Created
December 3, 2024 21:24
-
-
Save awestmoreland/e928ee75554db02c7aa87fd2b9bc0192 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
(async () => { | |
// Wait for the grid to load | |
const waitForSelector = (selector) => { | |
return new Promise((resolve) => { | |
const interval = setInterval(() => { | |
if (document.querySelector(selector)) { | |
clearInterval(interval); | |
resolve(); | |
} | |
}, 100); | |
}); | |
}; | |
await waitForSelector('#contents .ytd-rich-grid-renderer #button'); | |
// Get all buttons in the grid | |
const buttons = document.querySelectorAll('#contents .ytd-rich-grid-renderer #button'); | |
for (const button of buttons) { | |
// Click the button | |
button.click(); | |
// Wait for the popup to appear | |
await waitForSelector('.ytd-popup-container .ytd-menu-service-item-renderer'); | |
// Find the "Not interested" option and click it | |
const notInterested = Array.from(document.querySelectorAll('.ytd-popup-container .ytd-menu-service-item-renderer')) | |
.find(el => el.textContent.trim() === 'Not interested'); | |
if (notInterested) { | |
notInterested.click(); | |
} | |
// Wait a bit before moving to the next button | |
await new Promise(resolve => setTimeout(resolve, 1000)); | |
} | |
})(); | |
// Limit number to 20 max so we don't loop forever | |
const maxButtons = 20; | |
const limitedButtons = Array.from(buttons).slice(0, maxButtons); | |
for (const button of limitedButtons) { | |
// Click the button | |
button.click(); | |
// Wait for the popup to appear | |
await waitForSelector('.ytd-popup-container .ytd-menu-service-item-renderer'); | |
// Find the "Not interested" option and click it | |
const notInterested = Array.from(document.querySelectorAll('.ytd-popup-container .ytd-menu-service-item-renderer')) | |
.find(el => el.textContent.trim() === 'Not interested'); | |
if (notInterested) { | |
notInterested.click(); | |
} | |
// Wait a bit before moving to the next button | |
await new Promise(resolve => setTimeout(resolve, 1000)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment