Last active
December 2, 2023 17:51
-
-
Save alastorid/38dea14c267775432d843cda4ff915fc to your computer and use it in GitHub Desktop.
sayGoodbyeToTrash: AdBlocker Blocker Blocker
This file contains hidden or 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
function calcEntropy(str) { | |
const uniqChars = [...new Set(str)]; | |
const totalCount = str.length; | |
let entropy = 0; | |
for (const char of uniqChars) { | |
const charCount = str.split(char).length - 1; | |
const probability = charCount / totalCount; | |
entropy -= probability * Math.log2(probability); | |
} | |
return entropy; | |
} | |
function sayGoodbyeToTrash() { | |
document.querySelectorAll('*').forEach((element) => { | |
if (element.id) { | |
const entropy = calcEntropy(element.id); | |
if (entropy > 4) { | |
element.remove(); | |
} | |
} | |
}); | |
} | |
sayGoodbyeToTrash(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment