Clean Catbox

Be able to use Catbox in public without the people next to you thinking you are a gooner.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Clean Catbox
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Be able to use Catbox in public without the people next to you thinking you are a gooner.
// @author       maxlikespizza
// @match        *://*.catbox.moe/*
// @match        *://catbox.moe/*
// @icon         https://catbox.moe/favicon.ico
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    "use strict";

    // --- Knock out the javascript that initially chooses the pic ---
    const originalCreateElement = document.createElement.bind(document);

    document.createElement = function(tag) {
        const el = originalCreateElement(tag);

        if (tag.toLowerCase() === "script") {
            const realSetAttribute = el.setAttribute.bind(el);
            el.setAttribute = function(name, value) {
                if (name === "src" && value.includes("resources/pic.js")) {
                    console.warn("Gooner shit destroyed (script)");
                    return;
                }
                return realSetAttribute(name, value);
            };
        }

        return el;
    };

    //remove existing <script src="resources/pic.js"> added before this script loaded
    new MutationObserver((mut) => {
        for (const m of mut) {
            for (const node of m.addedNodes) {
                if (node.tagName === "SCRIPT" && node.src && node.src.includes("resources/pic.js")) {
                    console.warn("Gooner shit destroyed (pre-existing content");
                    node.remove();
                }

                //kill the containing image block
                if (node.nodeType === 1) {
                    if (node.matches("div.image")) {
                        console.warn("Gooner shit destroyed (img)");
                        node.remove();
                    }
                    const bad = node.querySelector("div.image");
                    if (bad) bad.remove();
                }
            }
        }
    }).observe(document.documentElement, { childList: true, subtree: true });

})();