Is there a way to trigger custom JavaScript on ad detection?

Everything about using Adblock Plus on Google Chrome
Post Reply
AcidShout
Posts: 2
Joined: Tue Jul 22, 2014 10:00 pm

Is there a way to trigger custom JavaScript on ad detection?

Post by AcidShout »

Hi there!

I found a web page which adds an event listener to the ad <div>, and if it's removed / hidden / etc, it simply creates another one. If it's hidden with display: none;, then the entire page disappears.

So I thought I could remove it with a bit of JavaScript, and came up with this:

Code: Select all

var x;
while(x = document.getElementById('ad17')){
    x.removeEventListener('DOMNodeRemoved');
    x.parentNode.removeChild(x);
}
That effectively solves the problem if I run it, but I don't want to run that each time I browse to a new page.
Is there any way to make AdBlock for Chrome to execute my custom JavaScript when it detects #ad17?

Thanks!
User avatar
mapx
Posts: 21940
Joined: Thu Jan 06, 2011 2:01 pm

Re: Is there a way to trigger custom JavaScript on ad detection?

Post by mapx »

no, you can't do what you want using ABP
but which is that page/site ?
AcidShout
Posts: 2
Joined: Tue Jul 22, 2014 10:00 pm

Re: Is there a way to trigger custom JavaScript on ad detection?

Post by AcidShout »

It's private, and requires a paid registration.

Anyway I can give some research about the styling if you want
lewisje
Posts: 2743
Joined: Mon Jun 14, 2010 12:07 pm

Re: Is there a way to trigger custom JavaScript on ad detection?

Post by lewisje »

I didn't notice this thread when it was first posted, but I'll just say that .removeEventListener requires both the event name and the same function that had been added as the event listener (and also the same value of the third argument, the "useCapture" parameter, that had been used to add the event); unfortunately, there's no way in vanilla DOM/JS to say "remove all listeners on this element for this event" without having references to all event listeners already (and no way to enumerate all event listeners): https://developer.mozilla.org/en-US/doc ... ntListener
There's a buzzin' in my brain I really can't explain; I think about it before they make me go to bed.
Post Reply