Youtube - mark all as "not interesing"

Whenever you open a video on YouTube, its algorithm will start to recommend you similar videos. Sometimes it's quite irritating. Last time I was checking the video card comparisons. Soon after YouTube decided I'm a big fan of graphics card comparisons and every 5th recommendation was the same card comparison. You get the point.

To mark a video as not interesting you need to click the menu button and click I'm not interested every single time. This becomes tedious very quickly, so I created a quick and dirty solution. Assuming you are currently viewing YouTube's main page, it iterates over all loaded videos and marks them as not interesting.

By default, the script assumes that 6th option in the menu is the I'm not interested option. Before copying/pasting make sure it's the same since in your region/language it can be located in a different position. If needed alter the notInterstedMenuItemIndex value.

If the script encounters only one option in the menu it assumes it's the YouTubeMix and clicks it.

const sleep = (ms) => {
    return new Promise(resolve => setTimeout(resolve, ms));
}

async function main() {
    const notInterstedMenuItemIndex = 4;
    const menuButtons = Array.from(document.querySelectorAll('#details button#button'));

    for (let i = 0; i < menuButtons.length; i++) {
        menuButtons[i].click();
        await sleep(50);

        const menuItems = document.querySelectorAll('#items ytd-menu-service-item-renderer');
        const menuItemIndex = menuItems.length === 1 ? 0 : notInterstedMenuItemIndex;
        menuItems[menuItemIndex].click();
        await sleep(50);
    }
}

main();