-
-
Save simonwep/12bb870f1777a6cca9e7874637b93458 to your computer and use it in GitHub Desktop.
// ==UserScript== | |
// @name BlockAdblock Blocker | |
// @version 1.0 | |
// @namespace http://tampermonkey.net/ | |
// @description Blocks block-adblock | |
// @match *://**/* | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
(() => { | |
const originalEval = window.eval; | |
const keywords = ['advertising', 'ad', 'blocker', 'disabled', 'understand', 'site', 'income', 'okay', 'http://blockadblock.com', '']; | |
window.eval = str => { | |
// Check for keywords | |
const matches = keywords.filter(v => str.includes(v)); | |
if (matches.length / keywords.length > 0.85) { | |
console.log(`[ABBB] Probability of being ad-related: ${(matches.length / keywords.length) * 100}%`); | |
// Check if it contains the base64 charset in a variable | |
if (str.match(/[A-Za-z]+='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'/)) { | |
console.log(` >> It contains the base64 charset`); | |
// Check if it will clear the body element | |
if (str.includes(`document.body.innerHTML=''`)) { | |
console.log(` >> It'll clear your dom. Blocked.`); | |
return; | |
} | |
} | |
} | |
return originalEval(str); | |
}; | |
})(); |
@rohitsharmaj7 Sorry, I'm against ads in general and if I would be on the side of ads I probably wouldn't have published this script to block existing adblocker-blocker 😅 Spending time developing such things is wasted time, use it to improve the quality of the product itself or develop systems where users get extras by actually paying money. Ads are terrible and that won't change.
People will find a way to circumvent any kind of mechanism which would make them to watch ads, you can't win this game. Either bet on the 70% without any kind of adblocker or find another way to raise money.
And last but not least, you can't block an adblocker - ads are shown client-side and a user can do whatever he wants with what you give him which is the reason why things like PiHole or YouTube Vanced got invented (check both out, they're great).
If you really want to force your users into viewing ads you'll have to use methods which will make user leave your platform.
👍 Nice answer! I always laugh at people that think they have control over what is shown over the client-side. As I'm personally against any type of ads whatsoever, I find this amusing!
doesnt work
@charlie-moomoo it's over a year old... did you expect this to work after a single month without any updates? 😅
Works like a charm thank you. I don't mind ads but some websites push their limits... ever gone onto an anime-related webpage? Either overly sexual anime mobile game ads will pop up or straight up p**n
I ain't having none of that. Thanks a bunch for the script!
Oh, to some of you who are having issues try changing:
// @match ://**/
to
// @match :///*
Take care and support your favorite devs when you can.
its not working properly on ravelry eg https://www.ravelry.com/patterns/library/illume click on 'add to library' it. don't allow popup, its not an ad, its there to download, with script on prevents me from downloads
it doesn't block from https://blockadblock.com/
The provided script is already quite robust, but here are a few suggestions for further improvements:
- The script does not account for minified code, which can make the keyword matching less accurate. You can use a JavaScript beautifier like js-beautify to prettify the code before performing the keyword matching.
- The script only checks for a single type of obfuscation (base64 encoding). You may want to add checks for other types of obfuscation, such as string manipulation or code splitting.
- The script logs information to the console, but it may be more helpful to alert the user with a popup message instead.
- The script does not prevent BlockAdBlock from blocking the page, it only logs a message. You may want to modify the script to actually prevent BlockAdBlock from working.
Here is an updated version of the script that includes these improvements:
// ==UserScript==
// @name BlockAdblock Blocker
// @version 1.1
// @namespace http://tampermonkey.net/
// @description Blocks block-adblock
// @match *://**/*
// @grant none
// @run-at document-start
// ==/UserScript==
(() => {
const originalEval = window.eval;
const keywords = ['advertising', 'ad', 'blocker', 'disabled', 'understand', 'site', 'income', 'okay', 'http://blockadblock.com', ''];
function beautifyCode(code) {
return window.js_beautify(code);
}
function isCodeSuspicious(code) {
// Check for keywords
const beautifiedCode = beautifyCode(code);
const matches = keywords.filter(v => beautifiedCode.includes(v));
if (matches.length / keywords.length > 0.85) {
console.log(`[ABBB] Probability of being ad-related: ${(matches.length / keywords.length) * 100}%`);
// Check if it contains base64-encoded characters in a variable
if (beautifiedCode.match(/[A-Za-z]+='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'/)) {
console.log(` >> It contains the base64 charset`);
// Check if it will clear the body element
if (beautifiedCode.includes(`document.body.innerHTML=''`)) {
console.log(` >> It'll clear your dom. Blocked.`);
return true;
}
}
}
return false;
}
window.eval = str => {
if (isCodeSuspicious(str)) {
alert('BlockAdBlock detected on this page and has been blocked.');
return;
}
return originalEval(str);
};
})();
This version includes the following improvements:
The beautifyCode()
function uses the js_beautify library to prettify the code before performing keyword matching, which should improve accuracy.
The isCodeSuspicious()
function checks for base64 encoding in a more robust way by using a regular expression. It also returns a Boolean value, which simplifies the eval function.
The eval
function displays a popup message instead of logging to the console.
The isCodeSuspicious()
function returns true
if the code is suspicious, which allows the eval
function to block the code from running.
Thanks @TylerHallTech ! I will give it a go and report back if I find something could be further improved.
Thanks @TylerHallTech ! I will give it a go and report back if I find something could be further improved.
Okay
@jefro108 - If I had to guess, they probably found this script and a working work-around - at least that's how it works right 😂