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

后端 未结 11 1314

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:11

    If the page already has jQuery, then just follow this template:

    // ==UserScript==
    // @name          My Script
    // @namespace     my-script
    // @description   Blah
    // @version       1.0
    // @include       http://site.com/*
    // @author        Me
    // ==/UserScript==
    
    var main = function () {
    
        // use $ or jQuery here, however the page is using it
    
    };
    
    // Inject our main script
    var script = document.createElement('script');
    script.type = "text/javascript";
    script.textContent = '(' + main.toString() + ')();';
    document.body.appendChild(script);
    

提交回复
热议问题