2016-07-08 76 views
-1

我的新手到JS/Greasemonkey的,並有一定的難度調試這個腳本:太多的遞歸錯誤使用checkForBadJavascripts()

注:腳本解析網站的HTML,找到SCRIPT標籤和更改腳本運行之前的內容。

// ==UserScript== 
// @name  JustPaste.it CheckForBadScript 
// @namespace Mkhoul 
// @description Test 01 
// @include  https://justpaste.it/* 
// @version  1 
// @require https://greasyfork.org/scripts/12317-checkforbadjavascripts-js/code/checkForBadJavascriptsjs.js?version=73234 
// @run-at document-start 
// @grant GM_addStyle 
// ==/UserScript== 


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

function replaceTargetJavascript (scriptNode) { 
    var scriptSrc = scriptNode.textContent; 
    scriptSrc  = scriptSrc.replace (
     "meta,script,object,applet,iframe,option,embed,span[size|face],pre,font[style|face],h2[style],h1[style],h3[style],h[style],input,textarea,submit", 

     "dummyoption" 
    ); 

    addJS_Node (scriptSrc); 
} 

checkForBadJavascripts ([ 
    [false, /invalid_elements/, replaceTargetJavascript] 
]); 

它把我扔在控制檯: 「太多遞歸」

http://i.imgur.com/x6rj73t.png

然後指向:https://greasyfork.org/scripts/12317-checkforbadjavascripts-js/code/checkForBadJavascriptsjs.js文件

http://i.imgur.com/F9agQMT.png

最後一個錯誤「ReferenceError:initTinyMCE未定義」似乎是由於前2個錯誤引起的。

`

從這裏:How to alter this javascript with Greasemonkey?一切都應該在腳本中很好地工作。

我不明白爲什麼我有那些2「太多的遞歸」錯誤?

回答

0

checkForBadJavascripts添加一個事件偵聽beforescriptexecute該反應的任何腳本元素被添加,包括那些你addJS_node 檢查正在運行補充。這就是爲什麼遞歸是無限的。

爲了解決這個問題,您需要首先確保腳本包含使用indexOf的違規文本。只有在這種情況下,將其替換並添加腳本addJS_Node