Forked from uptownhr/gist:888f27fcf4d636d0197dd5736514094a
Last active
July 5, 2024 04:49
-
-
Save A2R14N/3c2f4e3b2890f486780799e1b8c592c2 to your computer and use it in GitHub Desktop.
One Million Checkboxes - Checker; One Million Checkboxes - console script; One Million Checkboxes - Chrome console; One Million Checkboxes - Firefox console; Million Checkboxes - Console; One Million Checkboxes - working script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// to copy and paste in your browser console after successfully loading https://onemillioncheckboxes.com/ | |
let currentPosition; | |
function getRandomInt(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
function getUncheckedCheckbox() { | |
const uncheckedCheckboxes = document.querySelectorAll('input[type=checkbox]:not(:checked)'); | |
if (uncheckedCheckboxes.length === 0) return null; | |
const randomIndex = getRandomInt(0, uncheckedCheckboxes.length - 1); | |
return uncheckedCheckboxes[randomIndex]; | |
} | |
function moveToPosition(newPosition = null) { | |
const gridElement = document.querySelector('.grid'); | |
if (newPosition === null) { | |
newPosition = getRandomInt(0, gridElement.scrollHeight); | |
} | |
gridElement.scrollTop = newPosition; | |
currentPosition = newPosition; | |
document.querySelector('button[type=submit]').click(); | |
} | |
function executeWorkflow() { | |
const nextCheckbox = getUncheckedCheckbox(); | |
if (nextCheckbox) { | |
nextCheckbox.click(); | |
} else { | |
moveToPosition(currentPosition - 1000); | |
} | |
} | |
// Initialize the process by randomizing the initial position | |
moveToPosition(); | |
const interval = setInterval(executeWorkflow, 300); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// to copy and paste in your browser console after successfully loading https://onemillioncheckboxes.com/ | |
let currentPosition; | |
/** | |
* Generates a random integer between min (inclusive) and max (inclusive). | |
* @param {number} min - The minimum value (inclusive). | |
* @param {number} max - The maximum value (inclusive). | |
* @return {number} A random integer between min and max. | |
*/ | |
function getRandomInt(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
/** | |
* Selects a random unchecked checkbox from the list of unchecked checkboxes on the page. | |
* @return {HTMLElement|null} A randomly selected unchecked checkbox, or null if all checkboxes are checked. | |
*/ | |
function getUncheckedCheckbox() { | |
const uncheckedCheckboxes = document.querySelectorAll('input[type=checkbox]:not(:checked)'); | |
if (uncheckedCheckboxes.length === 0) return null; | |
const randomIndex = getRandomInt(0, uncheckedCheckboxes.length - 1); | |
return uncheckedCheckboxes[randomIndex]; | |
} | |
/** | |
* Moves the grid container to a specified position. If no position is specified, a random position is chosen. | |
* @param {number|null} newPosition - The position to scroll to. If null, a random position is chosen. | |
*/ | |
function moveToPosition(newPosition = null) { | |
const gridElement = document.querySelector('.grid'); | |
if (newPosition === null) { | |
newPosition = getRandomInt(0, gridElement.scrollHeight); | |
} | |
gridElement.scrollTop = newPosition; | |
currentPosition = newPosition; | |
document.querySelector('button[type=submit]').click(); | |
} | |
/** | |
* Executes the main workflow: checks a random unchecked checkbox if available, | |
* otherwise scrolls the grid container up by 1000 pixels. | |
*/ | |
function executeWorkflow() { | |
const nextCheckbox = getUncheckedCheckbox(); | |
if (nextCheckbox) { | |
nextCheckbox.click(); | |
} else { | |
moveToPosition(currentPosition - 1000); | |
} | |
} | |
// Initialize the process by randomizing the initial position | |
moveToPosition(); | |
const interval = setInterval(executeWorkflow, 300); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment