2014-02-09 79 views
1

我的Greasemonkey腳本完全按照我希望的方式工作,但它以某種方式阻止網站本身的JavaScript。他們只是不工作了。Greasemonkey腳本阻止網站的其他腳本

我使用非常有用的waitForKeyElements()在加載某個容器後開始一些操作。

什麼令人不安其他腳本?

// @require  https://gist.github.com/raw/2625891/waitForKeyElements.js 
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js 
// @grant   none 
// ==/UserScript== 

var newText = 'changed'; 

// changes after loading .containerid 
waitForKeyElements (
    "#containerid", renameTop 
); 

function renameTop() { 
    var searchlinkTop = document.getElementById('containerid'); 
     searchlinkTop.innerHTML = newText; 
} 

// some normal changes 

function waitForKeyElements (
// ... the script's content 

回答

1

請參閱"jQuery in Greasemonkey 1.0 conflicts..."
問題是@grant none。這是一個非常 Greasemonkey糟糕的雖然「功能」,保證你會有衝突和錯誤。你真幸運這次它是如此明顯,直接。

@grant none更改爲@grant GM_addStyle。這將恢復沙箱並消除衝突。

+0

哇,謝謝!它適用於此腳本。 –

+0

哇,謝謝!它適用於我的小腳本。 但我還有另一個更大的腳本,幾個月來也遭受這個問題。當然,我也嘗試過你的建議,但它打破了整個劇本......?這種方法有沒有例外? 較大的腳本使用例如 // @require http://github.com/sizzlemctwizzle/GM_config/raw/master/gm_config.js GM_xmlhttpRequest({method:「GET」, url:'http://ajax.googleapis.com/ajax/ libs/jquery/1.3.2/jquery.min.js', onload:...;}}); GM_registerMenuCommand(...); window.addEventListener(「load」,Gm_main,false); $('div.twitter')。remove(); –

+0

第二個腳本使用了幾個'GM_'函數。您需要爲每個'GM_'函數添加'@ grant'指令。除此之外,請爲第二個腳本打開一個新問題(將此答案標記爲答案後)。 –