First time user here!
So, somewhat recently I got a YouTube adblocker for my computer off of GitHub. It is a simple Chrome plug-in written in JavaScript and it used to work great, but then it partially stopped working. What I mean by that is, when the adblocker is enabled it only blocks advertisements that have valid urls (such as https://www.example.com/). All other urls (such as example.com) won't get blocked.
I would've tried contacting the programmer of the plug-in, but I can't find his or her GitHub page anymore. I am a complete newcomer to JavaScript programming, however I do know what the problem is, just not how to go about rewriting the code.
There is a portion of background.js that contains a function with the parameter (argument?) urls:, which contains an array that consists of "all_urls". To my knowledge, "all_urls" will match any url that begins with schemes such as https:// and http://.
Here is the code in question.
background.js
var numBlocked = 0;
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
// It is easier to ignore requests instead of modifying them - everything seems to work fine
// Note that get_midroll_info response contains playerAds describing all of the ads in the video
const ignore =
details.url.indexOf("/get_video_info") != -1 ||
details.url.indexOf("/api/stats/ads") != -1 ||
details.url.indexOf("/pagead/conversion") != -1 ||
details.url.indexOf("ad_companion") != -1 ||
details.url.indexOf("get_midroll_info") != -1;
if (ignore) {
numBlocked++; // keep track of blocked requests
chrome.browserAction.setBadgeBackgroundColor({color: "#FF0000"});
chrome.browserAction.setBadgeText({text: (numBlocked > 99) ? "99+" : `${numBlocked}`});
}
return {cancel: ignore};
},
{urls: ["<all_urls>"]},
["blocking"]
);
Thanks, and sorry in advance if I forgot something.