Skip to content

Instantly share code, notes, and snippets.

@awestmoreland
Created December 3, 2024 21:24
Show Gist options
  • Save awestmoreland/e928ee75554db02c7aa87fd2b9bc0192 to your computer and use it in GitHub Desktop.
Save awestmoreland/e928ee75554db02c7aa87fd2b9bc0192 to your computer and use it in GitHub Desktop.
(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