Skip to content

Instantly share code, notes, and snippets.

@alastorid
Last active December 2, 2023 17:51
Show Gist options
  • Save alastorid/38dea14c267775432d843cda4ff915fc to your computer and use it in GitHub Desktop.
Save alastorid/38dea14c267775432d843cda4ff915fc to your computer and use it in GitHub Desktop.
sayGoodbyeToTrash: AdBlocker Blocker Blocker
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