Created
April 15, 2024 06:39
-
-
Save williamli/4394f5ef7c1de00e5d68843a0b547981 to your computer and use it in GitHub Desktop.
rmrf_weibo_feed
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
// Usage: | |
// 1. login to weibo and visit your weibo post list (https://weibo.com/u/_your_id_) | |
// 2. copy and paste the following functions to console | |
// 3. start the process with checkAndPerformClicks(1500, 1200); // Runs the function with a 1500ms delay between checks and a 1200ms delay between clicks | |
// Helper function to create a delay | |
function delay(duration) { | |
return new Promise(resolve => setTimeout(resolve, duration)); | |
} | |
/** | |
* Asynchronously performs a series of clicks with specified delays between each action. | |
* @param {number} clickDelay - The delay in milliseconds between each click action. | |
*/ | |
async function performClicks(clickDelay = 1000) { // Default delay is 1000ms if not specified | |
await delay(clickDelay); | |
document.querySelectorAll('article.woo-panel-main .woo-box-flex.woo-box-alignCenter i')[0].click(); | |
await delay(clickDelay); | |
document.querySelectorAll('article.woo-panel-main .woo-pop-wrap-main > div')[6].click(); | |
await delay(clickDelay); | |
document.querySelectorAll('.woo-dialog-main .woo-dialog-ctrl button')[1].click(); | |
} | |
/** | |
* Checks for the presence of elements and performs clicks if they exist, waits for a defined delay, and repeats. | |
* Uses recursive calls instead of a while loop for safety and clarity. | |
* @param {number} repeatDelay - The delay in milliseconds between recursive checks and after clicks. | |
* @param {number} clickDelay - The delay in milliseconds between each click action within performClicks. | |
*/ | |
async function checkAndPerformClicks(repeatDelay = 1000, clickDelay = 1000) { | |
const elements = document.querySelectorAll('article.woo-panel-main .woo-box-flex.woo-box-alignCenter i'); | |
if (elements.length !== 0) { | |
await performClicks(clickDelay); | |
await delay(repeatDelay); // Use the repeatDelay parameter | |
checkAndPerformClicks(repeatDelay, clickDelay); // Pass both delays to the recursive call | |
} else { | |
console.log('No elements found, stopping execution.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment