Ruud14 / Page-Manipulator

Browser Extension that can automatically inject custom HTML, CSS or JavaScript into any web-page. This way you can customize any web-page to fit your needs. Currently available on Google Chrome and Microsoft Edge.
https://chrome.google.com/webstore/detail/page-manipulator/mdhellggnoabbnnchkeniomkpghbekko?hl=nl
90 stars 31 forks source link

Updated script tag to point to an external js on the main page but has no effect #14

Closed SmokeFrog981 closed 2 years ago

SmokeFrog981 commented 2 years ago

Here is the code

class MyTest { constructor() { var scripts = document.getElementsByTagName("script");

    for (var i = 0; i < scripts.length; i++) {
        if (scripts[i].src) {
            console.log(i, scripts[i].src);

            if (i==7)
                scripts[i].src = "https://www.test.com/2.5569d62b.chunk.js";

            if (i==8)
                scripts[i].src = "https://www.test.com/main.8b5a7a6b.chunk.js"
        }
    }

  for (var i = 0; i < scripts.length; i++) {
    if (scripts[i].src) {
          console.log(i, scripts[i].src);
    }
  }
}

mlg()
{
    setInterval(function()
    { 
    }.bind(this), 100);
}

}

setTimeout(function() { let yeet = new MyTest(); yeet.mlg(); }, 3000);

The scripts in the external site were not used once the page is loaded. Any ideas?

Ruud14 commented 2 years ago

Instead of changing the source of existing scripts, try adding new script tags with the desired sources, then the custom external scripts will be used.

That's how to add your own custom external scripts, but removing the existing scripts isn't that easy. You could of course remove their tags but the code in them will have already executed by that time. If those existing scripts perform a one-time action, then you could maybe revert that action (e.g. If those scripts inject an image, you could programmatically remove that image.). And if those scripts are constantly running somekind of loop, then you could maybe break the loop somehow.

Another way to stop those original scripts from executing (which doesn't involve injecting code using this extension) is completely blocking communication with their source. (e.g. with firewall rules).

Hope this helps :)