top | item 40803526

(no title)

MechanicalFish | 1 year ago

// ==UserScript== // @name Check All Unchecked Checkboxes // @namespace http://tampermonkey.net/ // @version 1.0 // @description Check all unchecked checkboxes on the page // @author MechanicalFish // @match https://onemillioncheckboxes.com/* // @grant none // ==/UserScript==

(function() { 'use strict';

    function checkAllCheckboxes() {
        var checkboxes = document.querySelectorAll('input[type="checkbox"]');

        checkboxes.forEach(function(checkbox) {
            if (!checkbox.checked) {
                checkbox.checked = true;
            }
        });
    }

    const observer = new MutationObserver((mutations) => {
        checkAllCheckboxes();
    });

    observer.observe(document.body, { childList: true, subtree: true });

    checkAllCheckboxes();
})();

discuss

order

some_random|1 year ago

This really feels like it defeats the purpose of the site ngl

Vampiero|1 year ago

Well maybe next time OP will actually do their analysis and figure out that the project is DOA before even writing one line of code.

Mystery-Machine|1 year ago

This ain't gonna work for 1,000,000 checkboxes. You could try using requestAnimationFrame or querying only non-checked checkboxes querySelectorAll('input[type="checkbox"]:not(:checked)') or not calling checkAllCheckboxes for all mutations.

Edit: or just call querySelector('input[type="checkbox"]:not(:checked)') and do them one by one in some kinda while(true) loop

sillysaurusx|1 year ago

Just write data to the underlying API. No need to interact with the browser UI at all.