Remove videos containing certain words

Customizes YouTube based on user preferences. Remove videos from main pages (recommendations & subscriptions) that contains certain words + notifies you.

// ==UserScript==
// @name         Remove videos containing certain words
// @version      5.0
// @description  Customizes YouTube based on user preferences. Remove videos from main pages (recommendations & subscriptions) that contains certain words + notifies you.
// @icon         https://i.imgur.com/oUCcSbW.png
// @author       Misspent & OpenAI
// @namespace    https://chat.openai.com & https://chat.openai.com
// @match        https://www.youtube.com
// @exclude      https://www.youtube.com/watch
// @license      MIT
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';

    const wordsToRemove = ["Suits", "Add More Here"]; // Add more words to remove here

    function removeVideosWithSpecificWords() {
        const videoElements = document.querySelectorAll(".style-scope.ytd-rich-grid-row");
        const removedVideos = [];

        videoElements.forEach((video) => {
            const titleElement = video.querySelector("#video-title");
            if (!titleElement) return;

            const title = titleElement.innerText;
            const containsWords = wordsToRemove.some((word) => title.includes(word));

            if (containsWords) {
                video.remove();
                removedVideos.push("Removed: " + title); // Add "Removed: " at the start
            }
        });

        if (removedVideos.length > 0) {
            showRemovedVideos(removedVideos);
        }
    }

    function showRemovedVideos(removedVideos) {
        const existingPopup = document.querySelector("#removed-videos-popup");
        if (existingPopup) {
            existingPopup.remove();
        }

        const popup = document.createElement("div");
        popup.id = "removed-videos-popup";
        popup.style.position = "fixed";
        popup.style.bottom = "10px";
        popup.style.left = '50%';
        popup.style.transform = 'translate(-50%, 0)';
        popup.style.background = "#8B0000";
        popup.style.color = "#ccc";
        popup.style.padding = "8px";
        popup.style.fontSize = '14px';
        popup.style.fontWeight = 'bold';
        popup.style.maxHeight = "300px";
        popup.style.overflowY = "auto";
        popup.style.zIndex = "1006";

        removedVideos.slice(0, 10).forEach((video) => {
            const videoElement = document.createElement("div");
            let videoTitle = video;
            wordsToRemove.forEach((word) => {
                if (videoTitle.includes(word)) {
                    // Highlight the keyword in gold color
                    const goldSpan = document.createElement("span");
                    goldSpan.textContent = word;
                    goldSpan.style.color = "gold";
                    videoTitle = videoTitle.replace(word, goldSpan.outerHTML);
                }
            });
            videoElement.innerHTML = videoTitle;
            popup.appendChild(videoElement);
        });

        document.body.appendChild(popup);

        // Remove the popup after 3 seconds
        setTimeout(() => {
            popup.remove();
        }, 3000);
    }

    // Run the removal function initially
    removeVideosWithSpecificWords();

    // Run the removal function every 1 seconds (adjust the interval as needed)
    setInterval(removeVideosWithSpecificWords, 1000);

})();












/* New one is something like this:

Write a YouTube TamperMonkey script that does the following
1. Make the @namespace https://chat.openai.com
2. Make the @author Misspent & OpenAI
3. Give each section/function a brief description of what it is like you normally do
4. Remove a class "ytd-rich-item-renderer" that contains the words "BattleBit Remastered" and make it so I can add more words to it very easily
6. Make it detect newly loaded ones and remove them too
7. Can you make it popup with what it removes at the bottom center of the screen? Make the background #8B0000 and text #ccc
8. Make it stack the removed ones up to 10 and move the newly created ones below the old(previous) ones.
+ more
*/


/* Old was Something like this:

Write a TamperMonkey YouTube script that does the following:
1. Make the @namespace https://chatbot.theb.ai
2. Make the @author Misspent & OpenAI
3. Give each section/function a brief short description of what it is like you normally do
4. Removes "[page-subtype="home"] ytd-rich-item-renderer" if it contains the text "Grim Dawn"
5. Make it works consistently
10. Give an output for Console, make the background black, text colour red, padding "0px 4px" and font bold.

Give me the name of the title you remove and show all the ones you remove in console log

*/