這兩天讀了一些jQuery的使用方法,跟我去年認識的jQuery有點出入,不過它確實是很好用,如同它宣稱的:「write less, do more.」
我除了使用Javascript Shell來練習外,也想讓Greasemonkey可以直接套用自訂的jQuery script,於是找到了這個東西:
在Greasemonkey裡面加入jQuery的方法Greasemonkey程式碼:
// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
// Check if jQuery's loaded
function GM_wait() {
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();
// All your GM code must be inside this function
function letsJQuery() {
alert($); // check if the dollar (jquery) function works
}
安裝下載點:
Download as a userscript. (需要安裝 greasemonkey )
因為作者允許MIT License,所以我就直接複製貼上了XD
ps. 如果不想要每次載入都出現那個alert(),就自己//掉需要的地方吧XD ;
沒有留言:
張貼留言