Greasemonkey Jquery interference? [duplicate]

戏子无情 提交于 2019-12-01 11:29:34
Brock Adams

Greasemonkey 1.0, radically changed the way the sandbox works, busting thousands of scripts. See also, jQuery in Greasemonkey 1.0 conflicts with websites using jQuery.

This is a huge problem, and the lead developer of Greasemonkey has expressed a complete unwillingness to resolve it in a sensible way.

To work around it, restore the sandbox to your script, and resolve the $ conflict, by editing your Metadata Block to end with the following lines:

// @grant       GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a major design change introduced in GM 1.0,
    It restores the sandbox.
*/


Specifying a @grant value (other than none) reactivates the sandbox.


You might also consider switching to Scriptish, which has offered superior features and performance in the past, and does not suffer from this new sandbox behavior.

Scriptish, so far, hasn't posted updates that destroy a large portion of its install base, either.

You need to include jQuery only if it isn't already included. So you need to make the first line check. If it is included run the script if it isn't included add like line to include it and then loop the checking function. Something like this:

var wrote = false,
    runScript = function(){
    if(typeof(jQuery) === 'undefined'){
        if(!wrote){
            wrote = true;
            document.write('<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>');
        }
        setTimeout(runScript, 50);
    }else{
        //your script goes here
    }
};

runScript();

Only problem would be is if google's jquery isn't up.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!