有没有一种方法可以将一个元素标记为广告,这样adblock就会隐藏它?我有一个用户感到不安,因为他认为一个广告没有被他的广告拦截器阻止。
发布于 2020-07-08 00:46:48
因此,adblock的工作原理是在加载之前搜索脚本,并删除任何与已知广告列表匹配的内容。
从技术上讲,你所要做的就是搜索这个元素,并添加一个类,这个类将被普通的广告拦截器拾取。
//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] );}
)};
https://stackoverflow.com/questions/62779110
复制相似问题