Last active
September 30, 2023 14:32
-
-
Save simonwep/12bb870f1777a6cca9e7874637b93458 to your computer and use it in GitHub Desktop.
Blocks BlockAdBlock scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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); | |
}; | |
})(); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The provided script is already quite robust, but here are a few suggestions for further improvements:
Here is an updated version of the script that includes these improvements:
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 returnstrue
if the code is suspicious, which allows theeval
function to block the code from running.