LimePaste888

seeInsideForTitle

May 17th, 2022 (edited)
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 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.
  2. // Also gives a list of the elements removed.
  3.  
  4. // Variable setup...
  5. indexToTest = loopRan = 0;
  6. whenTheListIsSus = []
  7.  
  8. // Inserts the output element. Change CSS as needed.
  9. 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');}
  10.  
  11. listToTest = document.getElementsByTagName('span') // Change this to the <tag></tag> name of the elements you want to check!
  12.  
  13. // Runs the check loop for every element with the tag name.
  14. while (loopRan < listToTest.length) {
  15.     thingToTest = listToTest[indexToTest]
  16.     if (thingToTest.outerHTML.indexOf('example string here') != -1) // Change this to the text you want to filter!
  17.         {thingToTest.remove();whenTheListIsSus.push(thingToTest.outerHTML.toString());}
  18.     else {indexToTest++;}
  19.     loopRan++;
  20. }
  21.  
  22. document.getElementById('output').innerHTML = whenTheListIsSus.length != 0 ? whenTheListIsSus.join('').replaceAll('<', '&lt;').replaceAll('>', '&gt;') : 'None removed.' // Puts the thing to the output element.
  23. console.log(whenTheListIsSus) // Logs.
Add Comment
Please, Sign In to add comment