Greasemonkey @require jQuery not working “Component not available”

前端 未结 8 2113
温柔的废话
温柔的废话 2020-12-16 19:41

I\'ve seen the other question on here about loading jQuery in a Greasemonkey. Having tried that method, with this require statement inside my ==UserScript== tag

相关标签:
8条回答
  • 2020-12-16 20:13

    I found a non-ideal way to use it with jQuery 1.4.1 -- this seems to fix it. It's the new browser sniffing that seems to "break" it.

    jquery-1.4.1.min.js:

      [old]  36: var o=r.createElement("div");n="on"+n;var m=n in o;
      [new]  36: var o=r.createElement("div");n="on"+n;var m=true;
    

    jquery-1.4.1.js

      [old] 934: var isSupported = (eventName in el);
      [new] 934: var isSupported = true;
    
    0 讨论(0)
  • 2020-12-16 20:14

    Not entirely true, it seems like jQuery 1.4 tries to detect something using a call that just doesn't work in the greasemonkey environment. @require does normally work as it should.

    So reverting to 1.3.2 does do the trick, but I'd rather find a solution that lets me use 1.4.

    btw, I use this, slightly different:

    // @require http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js
    
    0 讨论(0)
  • 2020-12-16 20:20

    Patch for jquery-1.4.3.min.js

    [old] line 41 u.createElement("div");s="on"+s;var B=s in v;
    [new] line 41 u.createElement("div");s="on"+s;var B=true;

    0 讨论(0)
  • 2020-12-16 20:22

    Ok, so i looked into this a bit more deeper. I used your script exactly, but used our JQuery version, making it look like this:

    // ==UserScript==
    // @name           My Script
    // @namespace      http://www.google.com
    // @description    My test script
    // @include        http://www.google.se/*
    // @include        http://www.dn.se/*
    // @require        http://myserver/jquery-1.3.2.js
    // ==/UserScript==
    
    GM_log("Hello");
    

    This works just fine for me, my guess, the JQuery up on the google api is missing some functions. Because this code above, works just fine. Also note the /* at the end of each url, please include that.

    Try another JQuery and change the urls and it should world properly.

    0 讨论(0)
  • 2020-12-16 20:26

    The @require attribute doesn't work correctly in Greasemonkey and jQuery...this same error can occur in FireBug as well.

    An alternative is to include jQuery in the page via Greasemonkey by creating the script tag. Here's how to do that.

    0 讨论(0)
  • 2020-12-16 20:32

    Here's a minified version of jQuery 1.4.4 for Greasemonkey:

    http://userscripts.org/scripts/show/92329

    Hope it helps, yah

    0 讨论(0)
提交回复
热议问题