Need help to debug a script (screenshot inside)

75 views
Skip to first unread message

Mikhoul

unread,
Jul 7, 2016, 11:11:27 PM7/7/16
to greasemonkey-users

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: http://stackoverflow.com/questions/11200509/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 ????



janekptacijarabaci

unread,
Jul 9, 2016, 10:04:53 AM7/9/16
to greasemonkey-users
Ad:
addJS_Node (scriptSrc);

= this creates an infinite loop...
window.addEventListener ('beforescriptexecute', checkForBadJavascripts, true);

addJS_Node (scriptSrc); <=> the onbeforescriptexecute event occurs

Mikhoul

unread,
Jul 9, 2016, 11:46:05 PM7/9/16
to greasemonkey-users
Thanks a lot  ! :)
Reply all
Reply to author
Forward
0 new messages