onemillioncheckboxes

HAHHAHAHA

Versione datata 28/06/2024. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         onemillioncheckboxes
// @namespace    none
// @version      0.1
// @description  HAHHAHAHA
// @author       YOU (idc tbh)
// @license      MIT
// @match        https://onemillioncheckboxes.com/
// @grant        none
// ==/UserScript==
(function() {
    'use strict';
    let isSelecting = false;
    let startX, startY, endX, endY;
    let selectionBox;
    let totalChecked = 0;
    let startTime;
    function isElementInViewport(el) {
        const rect = el.getBoundingClientRect();
        return (
            rect.top >= 0 &&
            rect.left >= 0 &&
            rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
            rect.right <= (window.innerWidth || document.documentElement.clientWidth)
        );
    }
    function clickCheckbox(checkbox) {
        if (!checkbox.checked) { // Check if checkbox is not already checked
            checkbox.click();
            totalChecked++;
        }
    }
    function selectCheckboxesInArea(startX, startY, endX, endY) {
        const allCheckboxes = document.querySelectorAll('input[type="checkbox"]');
        let nearestUnchecked = null;
        let minDistance = Number.MAX_SAFE_INTEGER;
        let checkedCount = 0;
        startTime = performance.now();
        for (let checkbox of allCheckboxes) {
            if (!checkbox.checked && isElementInViewport(checkbox)) {
                const checkboxRect = checkbox.getBoundingClientRect();
                const checkboxX = checkboxRect.left + window.scrollX;
                const checkboxY = checkboxRect.top + window.scrollY;
                if (checkboxX >= startX && checkboxX <= endX && checkboxY >= startY && checkboxY <= endY) {
                    const centerX = (startX + endX) / 2;
                    const centerY = (startY + endY) / 2;
                    const distance = Math.sqrt(Math.pow(checkboxX - centerX, 2) + Math.pow(checkboxY - centerY, 2));
                    if (distance < minDistance) {
                        nearestUnchecked = checkbox;
                        minDistance = distance;
                    }
                    let currentTime = performance.now();
                    let elapsedTime = currentTime - startTime;
                    let delay = Math.max(0, (checkedCount * 1000) / 5 - elapsedTime);
                    setTimeout(() => {
                        clickCheckbox(checkbox);
                    }, delay);
                    checkedCount++;
                }
            }
        }
        if (nearestUnchecked) {
            clickCheckbox(nearestUnchecked);
        }
    }
    function startSelection() {
        isSelecting = true;
        document.body.style.cursor = 'crosshair';
        selectionBox = document.createElement('div');
        selectionBox.style.position = 'absolute';
        selectionBox.style.border = '2px solid red';
        selectionBox.style.pointerEvents = 'none';
        document.body.appendChild(selectionBox);
        document.addEventListener('mousedown', handleMouseDown);
        document.addEventListener('mousemove', handleMouseMove);
        document.addEventListener('mouseup', handleMouseUp);
    }
    function handleMouseDown(event) {
        if (isSelecting) {
            startX = event.pageX;
            startY = event.pageY;
            selectionBox.style.left = startX + 'px';
            selectionBox.style.top = startY + 'px';
            selectionBox.style.width = '0';
            selectionBox.style.height = '0';
            selectionBox.style.display = 'block';
        }
    }
    function handleMouseMove(event) {
        if (isSelecting) {
            endX = event.pageX;
            endY = event.pageY;
            let boxWidth = Math.abs(endX - startX);
            let boxHeight = Math.abs(endY - startY);
            selectionBox.style.width = boxWidth + 'px';
            selectionBox.style.height = boxHeight + 'px';
            selectionBox.style.left = Math.min(endX, startX) + 'px';
            selectionBox.style.top = Math.min(endY, startY) + 'px';
        }
    }
    function handleMouseUp() {
        if (isSelecting) {
            isSelecting = false;
            document.body.style.cursor = 'default';
            selectionBox.style.display = 'none';
            selectCheckboxesInArea(Math.min(startX, endX), Math.min(startY, endY), Math.max(startX, endX), Math.max(startY, endY));
            document.removeEventListener('mousedown', handleMouseDown);
            document.removeEventListener('mousemove', handleMouseMove);
            document.removeEventListener('mouseup', handleMouseUp);
        }
    }
    document.addEventListener('keydown', function(event) {
        if (event.altKey && event.key === 'x') {
            startSelection();
        }
    });
})();