-1

I'm newbie to JS/Greasemonkey and have some difficulty debugging this script:

N.B.: The script parse the HTML of the site, find the SCRIPT tag and change the content of the script before it run.

// ==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]
] );

It throw me in the console: "too much recursion"

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

Then point to: https://greasyfork.org/scripts/12317-checkforbadjavascripts-js/code/checkForBadJavascriptsjs.js file

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

.

The last error "ReferenceError: initTinyMCE is not defined" seem to be caused because of the first 2 errors.

`

From here: How to alter this javascript with Greasemonkey? everything should work fine in the script.

I don't see why I have those 2 "too much recursion" errors ?

Community
  • 1
  • 1
Khado Mikhal
  • 602
  • 7
  • 14

1 Answers1

0

checkForBadJavascripts adds an event listener beforescriptexecute that reacts to any script element being added, including those you add with addJS_node while the check is running. That's why the recursion is infinite.

To solve this you need to ensure first that a script contains the offending text using indexOf, for example. Only in that case replace it and add the script with addJS_Node.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136