Search code examples
javascriptjqueryuserscriptstampermonkey

Userscript - Replace another Javascript before it executes?


I want to create my own Userscript for Tampermonkey for a specific site I often use and I want to add some features and I want to improve some things.

Since it loads some .js files, that do some stuff I don't want to happen, I want to replace these .js files and reimplement the things I need within my Userscript.

I don't want to replace functions, I want to completely remove specific .js files from the DOM before they get executed and reimplement them in my Userscript to my preferences.

I tried to use this method: http://userscripts-mirror.org/scripts/show/125936 But it didn't work at all, no errormessages or similar, it just doesn't execute the Eventlistener, I use Chrome, could it be that this has to be implemented in another way for Chrome?


Solution

  • beforescriptexecute event referenced in your question isn't implemented in Chrome and probably never will be.

    There is no way for a userscript in Chrome to prevent some webpage script that is referenced in the page html <script> tag from loading.

    The only solution is to use an extension that blocks urls via webRequest API.

    • If you don't mind making your userscript dependent on another extension then use HTTP Request Blocker, Requestly and others.
    • For a complete solution without dependencies you'll have to make your own extension, not a userscript.