4

With Greasemonkey, I'm looking to block images and scripts from being downloaded.

From an existing post I learnt that it is possible to use the document-start directive to jump in before scripts execute.

Is it possible for me to use window.addEventListener on a specific event that allows me to find the src = xxx.js and xxx.jpg tags and either remove these src= tags before downloading, or to block the download?

Note: Here is a list of events that Mozilla supports.

AMENDED: I would like to replace the blocked downloads with my own scripts or images.

Community
  • 1
  • 1
codeaperature
  • 1,089
  • 2
  • 10
  • 25
  • 3
    Use the answer you linked to block the desired `xxx.js` files. You can use Mutation Observers to quickly kill image `src`s, but the file might start downloading in the background anyway (need to test this). ... The **smart** thing to do is to use [Adblock Plus](http://adblockplus.org/en/), and/or maybe [RequestPolicy](https://addons.mozilla.org/en-us/firefox/addon/requestpolicy/) to block select js or jpg files. Adblock plus will be faster as well. – Brock Adams Oct 28 '12 at 04:21
  • Thx ... I still need to investigate these two paths, but I should say that I would like to replace the blocked downloads with my own scripts or images. (Per AMENDED text.) – codeaperature Oct 28 '12 at 09:26
  • Can you run a Greasemonkey script before the page's html is executed? if so, maybe it's possible to remove the desired html elements – alfred Oct 28 '12 at 09:56
  • Yes - You can use the script at "document-start". This will allow you to add the event listeners (and do some other activities) before you get the page. At this time, a lot of the HTML is missing. My tests sow that only the elements are filled - I ain't got no for me. – codeaperature Oct 28 '12 at 18:48
  • Greasemonkey can't do this, because the page script may earlier than GM script execute. You remove the `src` attribute later doesn't help. I think what your want is modify the http response content. – muzuiget Apr 19 '13 at 18:29
  • Bad question, you should directly ask you want to replace the scripts and images. Greasemonkey can't do this, try to use https://addons.mozilla.org/en-us/firefox/addon/redirector/ – muzuiget Dec 28 '13 at 02:15
  • I'd recommend trying Ublock Origin instead. You can write your custom blocking rules for it. – Steve Horvath May 27 '18 at 23:25

0 Answers0