2016-09-22 10 views
0

jQuery 북마크릿에 추가 로직을 추가 할 위치는 어디입니까?

위의 링크는 위의 초보자를위한 사전 질문입니다. 위 링크는 jQuery를로드하는 데 매우 효과적입니다. 그러나 다음과 같은 추가 jQuery 선택기 문을 추가하려면 :

$ ('# mruSelect'). hide(); 거기에 묻혀 경고 문이있다

javascript:(function(){var el=document.createElement("div"),b=document.getElementsByTagName("body")[0],otherlib=!1,msg="";el.style.position="fixed",el.style.height="32px",el.style.width="220px",el.style.marginLeft="-110px",el.style.top="0",el.style.left="50%25",el.style.padding="5px 10px",el.style.zIndex=1001,el.style.fontSize="12px",el.style.color="#222%22,el.style.backgroundColor=%22#f99%22;function%20showMsg(){var%20txt=document.createTextNode(msg);el.appendChild(txt),b.appendChild(el),window.setTimeout(function(){txt=null,typeof%20jQuery==%22undefined%22?b.removeChild(el):(jQuery(el).fadeOut(%22slow%22,function(){jQuery(this).remove()}),otherlib&&(window.$jq=jQuery.noConflict()))},2500)}if(typeof%20jQuery!=%22undefined%22)return%20msg=%22This%20page%20already%20using%20jQuery%20v%22+jQuery.fn.jquery,showMsg();alert('test');typeof%20$==%22function%22&&(otherlib=!0);function%20getScript(url,success){var%20script=document.createElement(%22script%22);script.src=url;var%20head=document.getElementsByTagName(%22head%22)[0],done=!1;script.onload=script.onreadystatechange=function(){!done&&(!this.readyState||this.readyState==%22loaded%22||this.readyState==%22complete%22)&&(done=!0,success(),script.onload=script.onreadystatechange=null,head.removeChild(script))},head.appendChild(script)}getScript(%22//code.jquery.com/jquery.min.js%22,function(){return%20typeof%20jQuery==%22undefined%22?msg=%22Sorry,%20but%20jQuery%20was%20not%20able%20to%20load%22:(msg=%22The%20Recent%20Items%20is%20now%20hidden%22,otherlib&&(msg+=%22%20and%20noConflict().%20Use%20$jq;,%20not%20$().%22)),showMsg()})})(); 

...

그러나이 타이밍 문제로보고 다음 코드에서 내가 안전하게 jQuery를로드 한 후이를 추가 할 수있는 확실하지 않다 추가 및 작동하지만 아직 사용할 수 없기 때문에 jQuery를 추가해도 작동하지 않습니다.

+0

다음 링크를 사용해 보셨습니까? 순수 JS 나 JQuery를위한 북마클릿 포맷에 매우 유용하다. http://mrcoles.com/bookmarklet/ –

답변

0

jQuery를로드했는지 여부를 보장 할 수 없다고 판단되었습니다. 그래서 showMsg() 다음에 다음을 추가하기로 결정했습니다. 함수 호출.

document.getElementById('mruSelect').style.display = 'none'; 
관련 문제