0

I've tried all sorts of solutions to index a array and remove elements that match a regex. The solution I ended up with should work, as it doesn't skip loop iterations due to the array length changing, which is the problem I had before. However now it just seems to ignore my if statement.

   const iframes = Array.from(document.getElementsByTagName("iframe")).filter(frame => frame.getAttribute("src") == "/domain/to/iframe");
   const idoc = iframes.length === 1 ? iframes[0].contentWindow.document : document;
   const regex = /.*TextGoesHere*/sig;
   var msgs = idoc.getElementsByClassName("message");
   msgs = Array.from(msgs);
   while (msgs.length > 0) {
    removal = msgs.pop(msgs.length);
    if (regex.test(removal.innerHTML)) {
        removal.remove();
    } else {
        console.log(regex.test(removal.innerHTML));
    }
   }

Output:

false
false
true
true
false
false

0 Answers0