手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:greasemonkey

GreaseMonkey with jQuery

习惯了用jQuery,因此在使用greasemonkey的时候,也总是想着用jQuery,找了下,确实有这样的例子。。

JavaScript代码
  1. var $;  
  2.   
  3. // Add jQuery  
  4.     (function(){  
  5.         if (typeof unsafeWindow.jQuery == 'undefined') {  
  6.             var GM_Head = document.getElementsByTagName('head')[0] || document.documentElement,  
  7.                 GM_JQ = document.createElement('script');  
  8.       
  9.             GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';  
  10.             GM_JQ.type = 'text/javascript';  
  11.             GM_JQ.async = true;  
  12.       
  13.             GM_Head.insertBefore(GM_JQ, GM_Head.firstChild);  
  14.         }  
  15.         GM_wait();  
  16.     })();  
  17.   
  18. // Check if jQuery's loaded  
  19.     function GM_wait() {  
  20.         if (typeof unsafeWindow.jQuery == 'undefined') {  
  21.             window.setTimeout(GM_wait, 100);  
  22.         } else {  
  23.             $ = unsafeWindow.jQuery.noConflict(true);  
  24.             letsJQuery();  
  25.         }  
  26.     }  
  27.   
  28. // All your GM code must be inside this function  
  29.     function letsJQuery() {  
  30.         alert($); // check if the dollar (jquery) function works  
  31.         alert($().jquery); // check jQuery version  
  32.     }  

然后代码就得全部扔在letsJQuery()方法里了。
由于是async,所以,尽量选择快一点地址,比如本地的localhost之类的,HOHO,不过,这就得本地WEB服务常开了。

原文来自:http://joanpiedra.com/jquery/greasemonkey/

Tags: greasemonkey, jquery