Search code examples
javascriptangularjsgreasemonkey

How do I uncheck all "md-checkboxes" (NOT real checkboxes) on a HTML page from a Greasemonkey script?


After wasting countless sweaty hours, swearing and cursing the name of the only food store I can use and how they keep checking their user-hostile options every single pageload, no matter how many times I uncheck them, and no matter how many times I report this "bug" (it's deliberate), I am simply forced to ask you experts for help.

The webpage doesn't use real HTML checkboxes, but instead something they call "md-checkboxes". It's an "AngularJS" thing. The AngularJS manual doesn't explain anything whatsoever, and neither does any of the numerous webpages (including Stack Overflow questions) I've been plowing through. None of the seemingly relevant code snippets do anything but dump various errors in the console.

This is the overall structure I have:

function turn_the_damn_things_off()
{
    var checkboxes = document.getElementsByTagName('md-checkbox');

    for (var i = 0; i < checkboxes.length; i++)
    {
        // I have tried countless things here, but nothing works. The checkboxes are never unchecked. I am, however, certain that the code here executes.
    }
}

setInterval(turn_the_damn_things_off, 500);

The reason I do this in an interval is that they seem to be re-checked not right away but after about a second after the page has been loaded.


Solution

  • for (var i = 0; i < checkboxes.length; i++)
    {
      let x = checkboxes[i];
      if(x.getAttribute("aria-checked") === "true")
        x.classList.toggle("md-checked");
    }