How to alter this javascript with Greasemonkey?

Since all those scriptData values seem liable to change from page load to page load, what you’d want to do is intercept that <script> node on the fly, clone it and only change 'auto' to true, using RegEx.

On Firefox Greasemonkey, you can do that with the stupefyingly brilliant (^_^) checkForBadJavascripts utility. Like so:

// ==UserScript==
// @name     _Modify JS as it's loaded
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @require  https://gist.github.com/raw/2620135/checkForBadJavascripts.js
// @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.
*/

function replaceTargetJavascript (scriptNode) {
    var scriptSrc   = scriptNode.textContent;
    scriptSrc       = scriptSrc.replace (
        /'auto'\s+\:\s+false/,
        "'auto'      : true"
    );

    addJS_Node (scriptSrc);
}

checkForBadJavascripts ( [
    [false, /'auto'\s+\:\s+false/, replaceTargetJavascript]
] );

Leave a Comment