Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Allows you to remove any element with a tag name if it contains a certain string. Useful for clearing image spam in your chat thing.
- // Also gives a list of the elements removed.
- // Variable setup...
- indexToTest = loopRan = 0;
- whenTheListIsSus = []
- // Inserts the output element. Change CSS as needed.
- if (document.getElementById('output') == null) {document.body.innerHTML += '<span id="output" style="max-width:200px;max-height:300px;overflow-y:scroll;background:#0004;border-radius:2px;padding:2px;position:fixed;bottom:10px;right:10px;z-index:42069;">output</span>';outputElement = document.getElementById('output');}
- listToTest = document.getElementsByTagName('span') // Change this to the <tag></tag> name of the elements you want to check!
- // Runs the check loop for every element with the tag name.
- while (loopRan < listToTest.length) {
- thingToTest = listToTest[indexToTest]
- if (thingToTest.outerHTML.indexOf('example string here') != -1) // Change this to the text you want to filter!
- {thingToTest.remove();whenTheListIsSus.push(thingToTest.outerHTML.toString());}
- else {indexToTest++;}
- loopRan++;
- }
- document.getElementById('output').innerHTML = whenTheListIsSus.length != 0 ? whenTheListIsSus.join('').replaceAll('<', '<').replaceAll('>', '>') : 'None removed.' // Puts the thing to the output element.
- console.log(whenTheListIsSus) // Logs.
Add Comment
Please, Sign In to add comment