Skip to content
← Back to Community
Chrome Extensoin js adblock
Profile icon
makxspa

I made a chrome extension similar to adblock. 1 time per second I get an error: "document.getElementByClassName is not a function".
This is my code (I didn't give all the code because I don't want anyone to copy the code):
manifest.json

{ "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

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);
Voters
Profile icon
FiredHacker
Profile icon
makxspa
Comments
hotnewtop
Profile icon
FiredHacker

Can you send a link to download it?

Profile icon
makxspa

@FiredHacker At the moment I do not develop my adblock (I have too little time) and I use the well-known "Adblock" program myself. If you want to download my adblocker go to:https://drive.google.com/drive/folders/1HZdExh6YuPf05MncJwln0qhTtDqOg2OF?usp=sharing

Profile icon
makxspa

@FiredHacker I can't give you access to the file because your email seems to be from some organization (work, school, etc.) and I get the message: "The domain administrator educ.dpcdsb.org has blocked the possibility of receiving documents from outside the organization. you are trying to share documents, they should contact their organisation's administrator directly. "

Profile icon
JustCoding123

Its called document.getElementsByClassName with an s.

Profile icon
makxspa

@JustCoding123 Could you please explain to me because I don't understand anything from your message.

Profile icon
JustCoding123

@makxspa You typed document.getElement(No s here)ByClassName wich doesn't exist. The function is called document.getElementsByClassName.

Profile icon
makxspa

@JustCoding123 I corrected the code but I have an error "Uncaught TypeError: document.getElementByClassNames is not a function"
script.js

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