简体   繁体   English

Chrome 扩展程序

[英]Chrome Extension

I recently started making an extension for Google Chrome.我最近开始为谷歌浏览器做一个扩展。 A few days ago everything was working but the "Uncaught ReferenceError: click is not defined" errors started popping up.几天前一切正常,但“未捕获的引用错误:点击未定义”错误开始弹出。 Do you know where the error is and why it is happening.你知道错误在哪里以及为什么会发生。 I am sending all the code so that there are no problems.我正在发送所有代码,以便没有问题。

manifest.js 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
}

background.js背景.js


chrome.webRequest.onBeforeRequest.addListener(
  
function(details) { return {cancel: true}; },
  {urls: 
    ["*://*.doubleclick.net/*",
    "*://*.googleadservices.com/*",
    "*://*.googlesyndication.com/*",
    "*://*.adskeeper.com/*",
    "*://*.eternalfury.com/*",
    "*://*.g.cda.pl/*",
    "*://*.ocdn.eu/lps/*",
    "*://*.adskeeper.co.uk/*",
    "*://*.trafficstars.com/*",
    "*://*.tsyndicate.com/*",
    "*://*.greatdexchange.com/*",
    "*://*.panel.zenbox.pl/file-pp/012021/336x280.png*",
    "*://*.mgid.com/*",
    "*://*.mrex.exs.pl/*",
    "*://*.toglooman.com/*",
    "*://*.www3.smartadserver.com/*",
    "*://*.fwcdn.pl/prt/a1/hbo/*",
    "*://*.r2---sn-f5f7kn7z.c.2mdn.net/*",
    "*://*.ssl.cdne.cpmstar.com/*",
    "*://*.cat.nl.eu.criteo.com/*",
    "*://*.affilixxl.de/*",
    "*://*.s1.adform.net/*",
    "*://*.taboola.com/*",
    "*://*.content.foreshop.net/*",
    "*://*.tri-table.com/*",
    "*://*.a.spolecznosci.net/*",
    "*://*.mult-film.net.ru/*",
    "*://*.ocs-pl.oktawave.com/*",
    "*://*.moat.com/*"]
  },
  ["blocking"]
);

script.js脚本.js

setInterval(function(){

    var skipButton = document.getElementsByClassName("ytp-ad-skip-button");
    if(skipButton != undefined && skipButton.length > 0) {
            console.log("Ad detected");
            skipButton[0].click();
    }

}, 3000)





setInterval(() => {
  click("ytp-ad-overlay-close-button");
}, 300);
console.log("Ads closed");

setInterval(() => {
  click("avnts-close-btn-con");
}, 300);
console.log("Ads closed");

I have also image :我也有图像:

在此处输入图片说明

I guess the problem has to do with the way you click ytp-ad-overlay-close-button and avnts-close-btn-con .我想问题与您单击ytp-ad-overlay-close-buttonavnts-close-btn-con Why don't you use it the same way as with ytp-ad-skip-button ?为什么不像ytp-ad-skip-button那样使用它?

setInterval(() => {
    var closeButton = document.getElementByClassName('ytp-ad-overlay-close-button');
    if (closeButton != undefined && closeButton.length > 0) {
        closeButton[0].click();
        console.log('Ads closed');
    }
}, 300);

setInterval(() => {
    var closeBtn = document.getElementByClassName('avnts-close-btn-con');
    if (closeBtn != undefined && closeBtn.length > 0) {
        closeBtn[0].click();
        console.log('Ads closed');
    }
}, 300);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM