How can I use jQuery in Greasemonkey scripts in Google Chrome?

后端 未结 11 1300

As some of you may know, Google Chrome has put some severe limitation on Greasemonkey scripts.

Chromium does not support @require,

11条回答
  •  自闭症患者
    2020-11-22 10:06

    I wonder if you couldn't rely on document.defaultView.jQuery in your GM script ala:

    if (document.defaultView.jQuery) {
      jQueryLoaded(document.defaultView.jQuery);
    } else {
      var jq = document.createElement('script');
      jq.src = 'http://jquery.com/src/jquery-latest.js';
      jq.type = 'text/javascript';
      document.getElementsByTagName('head')[0].appendChild(jq);
      (function() { 
        if (document.defaultView.jQuery) jQueryLoaded(document.defaultView.jQuery);
        else setTimeout(arguments.callee, 100);
      })();
    }
    
    function jQueryLoaded($) {
      console.dir($);
    }
    

提交回复
热议问题