I'm doing an adblock extension and want to make a button to turn it on and off using poput.js and popup.html. Unfortunately I don't know how to add it to my code. Here is my code:
manifest.js
{
"icons": { "128": "icon128.png" },
"name": "ADSkip",
"version": "1.2",
"description": "Block and Skip Ads",
"permissions": ["webRequest", "webRequestBlocking", "<all_urls>","tabs","activeTab"],
"content_scripts": [{
"js": ["script.js"],
"run_at": "document_idle",
"matches": ["<all_urls>"]
}],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}
script.js
const skip_add = (clazz) =>
{
const buttons = document.getElementsByClassName(clazz);
for (const button of buttons)
{
button.click();
console.log("No More Ad");
}
}
setInterval(() =>
{
skip_add("ytp-ad-skip-button-text");
skip_add("ytp-ad-overlay-close-button");
skip_add("avnts-close-btn-con");
}, 1000);
background.js(only two lines because I don't want anyone to fully copy)
chrome.webRequest.onBeforeRequest.addListener(
function(details) { return {cancel: true}; },
{urls:
["*://*.doubleclick.net/*",
"*://*.moat.com/*"]
},
["blocking"]
);