Created
July 18, 2024 12:38
-
-
Save andrewloux/e2cd42c2f10e9e1d5471eea2dd9ab572 to your computer and use it in GitHub Desktop.
batch clicker
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
// Function to find and click links in batches based on custom selectors | |
function batchClickLinks(options = {}) { | |
const { | |
linkSelector = 'a[href*="https://download.net/file"]', // Updated default selector | |
rowSelector = 'body', | |
batchSize = 5, | |
delay = 5000, | |
excludeNumbers = [] | |
} = options; | |
console.log('Starting batch link clicking process...'); | |
// Find all links based on the provided selectors | |
const links = document.querySelectorAll(linkSelector); | |
console.log(`Total links found: ${links.length}`); | |
// Filter links to exclude numbers if specified | |
const validLinks = Array.from(links).filter(link => { | |
if (excludeNumbers.length > 0) { | |
const numberMatch = link.textContent.match(/(\d+)/); | |
if (numberMatch) { | |
const number = parseInt(numberMatch[1]); | |
if (excludeNumbers.includes(number)) { | |
console.log(`Link skipped: Number ${number} is in exclude list`); | |
return false; | |
} | |
} | |
} | |
return true; | |
}); | |
console.log(`Found ${validLinks.length} valid links`); | |
// Function to process a single link | |
function processLink(link) { | |
console.log(`Clicking link: ${link.href}`); | |
try { | |
// Open in a new tab | |
window.open(link.href, '_blank'); | |
} catch (error) { | |
console.error(`Error clicking link ${link.href}: ${error}`); | |
} | |
} | |
// Function to process a batch of links | |
function processBatch(startIndex) { | |
console.log(`Processing batch starting at index ${startIndex}`); | |
const endIndex = Math.min(startIndex + batchSize, validLinks.length); | |
for (let i = startIndex; i < endIndex; i++) { | |
processLink(validLinks[i]); | |
} | |
// If there are more links to process, schedule the next batch | |
if (endIndex < validLinks.length) { | |
console.log(`Scheduling next batch starting at index ${endIndex}`); | |
setTimeout(() => processBatch(endIndex), delay); | |
} else { | |
console.log('Finished processing all links'); | |
} | |
} | |
// Start processing the first batch | |
processBatch(0); | |
} | |
// Example usage: | |
// batchClickLinks({ | |
// linkSelector: 'a[href*="https://download.net/file"]', | |
// batchSize: 5, | |
// delay: 5000, | |
// excludeNumbers: [] | |
// }); | |
console.log('Batch link clicking script loaded. Call batchClickLinks() with your desired options to start.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment