Last active
December 15, 2018 20:51
-
-
Save nemanjan00/fe431daf45b905488050bd403038065d to your computer and use it in GitHub Desktop.
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
String.prototype.replaceAll = function(search, replacement) { | |
var target = this; | |
return target.replace(new RegExp(search, 'g'), replacement); | |
}; | |
normalizer = (pattern) => { | |
result = {}; | |
pattern.split("").forEach((character) => result[character] = true); | |
return result; | |
} | |
comparator = (pattern, toFind) => { | |
toFind = Object.keys(toFind); | |
found = []; | |
notFound = false; | |
toFind.forEach((element) => { | |
if(pattern[element] === undefined){ | |
notFound = true; | |
} | |
}); | |
if(!notFound && toFind.length == Object.keys(pattern).length){ | |
return true; | |
} else { | |
return false; | |
} | |
}; | |
toFind = normalizer("Sponsored"); | |
divs = Array.from(document.querySelectorAll("span")).map((element) => element.parentElement).map((element) => element); | |
innerText = divs.map((element) => element.innerText.replaceAll(" ", "")).map(text => normalizer(text)).map(normalized => comparator(normalized, toFind)); | |
divs.forEach((div, key) => { | |
if(innerText[key]){ | |
div.style.display = "none"; | |
} | |
}); | |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title></title> | |
</head> | |
<body> | |
<div> | |
<span>Sp</span> | |
<span>Sp</span> | |
<span>on</span> | |
<span>s</span> | |
<span>s</span> | |
<span>or</span> | |
<span>or</span> | |
<span>ed</span> | |
<span>or</span> | |
</div> | |
<div> | |
<span>Spa</span> | |
<span>on</span> | |
<span>s</span> | |
<span>or</span> | |
<span>ed</span> | |
</div> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment