Last active
September 3, 2025 04:04
-
-
Save LikeCarter/ec713324319043ab0caca8fedd7974cd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // This script automates clicking a checkbox and a download button, | |
| // using a click event to uncheck the previous checkbox. | |
| const checkboxes = document.querySelectorAll('.td-wb-checkbox__input'); | |
| const downloadButton = document.getElementById('td-wb-eservices-statements-download'); | |
| // Base delay of 500ms + a random variation | |
| const baseDelay = 500; | |
| let i = 0; | |
| function clickNext() { | |
| if (i < checkboxes.length) { | |
| const currentCheckbox = checkboxes[i]; | |
| // Dispatch a click event to uncheck the previous checkbox | |
| if (i > 0) { | |
| const previousCheckbox = checkboxes[i - 1]; | |
| const uncheckEvent = new MouseEvent('click', { | |
| bubbles: true, | |
| cancelable: true, | |
| view: window | |
| }); | |
| previousCheckbox.dispatchEvent(uncheckEvent); | |
| console.log(`Dispatched click event to uncheck previous checkbox: ${i}`); | |
| } | |
| // Use a small, random delay before the next action | |
| const randomDelay = Math.floor(Math.random() * 200) + 100; // 100-300ms | |
| setTimeout(() => { | |
| // Dispatch a click event on the current checkbox | |
| const clickEvent = new MouseEvent('click', { | |
| bubbles: true, | |
| cancelable: true, | |
| view: window | |
| }); | |
| currentCheckbox.dispatchEvent(clickEvent); | |
| console.log(`Dispatched click event on checkbox ${i + 1}`); | |
| if (downloadButton) { | |
| setTimeout(() => { | |
| downloadButton.dispatchEvent(clickEvent); | |
| console.log('Dispatched click event on download button'); | |
| i++; | |
| // Proceed to the next checkbox after the main delay | |
| setTimeout(clickNext, baseDelay + Math.random() * 100); | |
| }, 100); | |
| } else { | |
| console.error('Download button not found. Proceeding to the next checkbox.'); | |
| i++; | |
| setTimeout(clickNext, baseDelay + Math.random() * 100); | |
| } | |
| }, randomDelay); | |
| } else { | |
| // Final uncheck after the loop completes | |
| if (checkboxes.length > 0) { | |
| const lastCheckbox = checkboxes[checkboxes.length - 1]; | |
| const uncheckEvent = new MouseEvent('click', { | |
| bubbles: true, | |
| cancelable: true, | |
| view: window | |
| }); | |
| lastCheckbox.dispatchEvent(uncheckEvent); | |
| } | |
| console.log('Automation complete. All checkboxes processed.'); | |
| } | |
| } | |
| clickNext(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment