Is there a way I can mark a element as a ad so that adblock will hide it? I have a user upset because what he considers a ad isnt blocked by his ad blocker.
Asked
Active
Viewed 303 times
0
-
2Technical things aside but if it's *the users adblocker* and *the users objection* why is it your problem? – Filburt Jul 07 '20 at 15:57
-
1Maybe looking from the opposite direction like [How to deal with AdBlock blocking non-ad elements](https://stackoverflow.com/q/43998076/205233) offers a clue (blacklisted CSS selectors?) – Filburt Jul 07 '20 at 16:02
-
1I'd still say this is simply a matter of asking the user to right-click the offending element and choose to block this element ... unless this is objectively indecent content and this is far from a technical issue. – Filburt Jul 07 '20 at 16:08
1 Answers
2
So adblock works by searching through the scripts before load and removing anything that matches a list of known ads.
Technically all you would have to do is search for this element and add a class that would be picked up by the normal ad blocker.
//get the elements you're looking for, turn into NodeList
const makeAd = document.querySelectorAll(".the-element-youre-looking-for");
//function for adding a class called ".adContent"
const addAds = (currentNode) => {
currentNode.classlist.add('.adContent');
//iterating through each of the possible items in the NodeList
for(const i of makeAd) {
window.addEventListener('DOMContentLoaded', function() {addAds( makeAd[i] );}
)};

Michael Riccio
- 38
- 4