Block a single embedded script

Ask for help about NoScript, no registration needed to post
Nighthawk

Block a single embedded script

Post by Nighthawk »

Hi I've been testing something on my own webspace.

To prevent any other manipulating of the page content on the client side I could stop events from bubbling up using the stopPropagation function, by embedding this piece of javascript in the page:

Code: Select all

if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", function(ev) {ev.stopPropagation();}, false);
}else if(document.attachEvent){
document.attachEvent("DOMContentLoaded", function(ev) {ev.stopPropagation();});
}else{
document.DOMContentLoaded = function(ev){ev.stopPropagation();};
}
This would stop extentions like greasemonkey for example too as they only get fired after the DOM was loaded but at that point stopPropagation prevents it from running.

My question is, can I reverse this and prevent this specific embedded script from running, using the surrogate replacement method?
Mozilla/5.0 (Windows; U; Windows NT 6.1; nl; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8
User avatar
Giorgio Maone
Site Admin
Posts: 9524
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: Block a single embedded script

Post by Giorgio Maone »

Nighthawk wrote: My question is, can I reverse this and prevent this specific embedded script from running, using the surrogate replacement method?
Yes you can:

Code: Select all

(function() {
var stopPropagation = Event.prototype.stopPropagation;
Event.prototype.stopPropagation = function() {
  if (this.type != "DOMContentLoaded") stopPropagation.apply(this);
}
})();
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
Nighthawk

Re: Block a single embedded script

Post by Nighthawk »

Thanks a lot, this feature is a real nice addition, props!
Mozilla/5.0 (Windows; U; Windows NT 6.1; nl; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8
Post Reply