Clean YouTube Links

Cleans YouTube Links

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Clean YouTube Links
// @version      0
// @namespace    cleanytsi
// @description  Cleans YouTube Links
// @author       (me)
// @match       *://8chan.moe/*/res/*
// @match       *://8chan.se/*/res/*
// @match       *://8chan.cc/*/res/*
// @run-at       document-idle
// @grant        none
// ==/UserScript==

(function() {
    "use strict";
    const target = document.getElementById("threadList");
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            document.querySelectorAll('.divMessage a:not(.quoteLink)').forEach((link) => {
                if(link.href.includes("youtu") && link.href.includes("si=")) {
                    let stringindex = link.href.indexOf("si=")
                    let sanitized = link.href.split(link.href.substring(stringindex, stringindex+19)).join("")

                    if(sanitized.substring(sanitized.length-1) == "?") {
                        sanitized = sanitized.slice(0, sanitized.length-1)
                    }

                    if(sanitized.includes("?&")) {
                        sanitized = sanitized.split("?&").join("?")
                    }

                    link.textContent = sanitized
                    link.href = sanitized
                }
            });
        });
    });

    const config = {
        subtree: true,
        childList: true
    };

    observer.observe(target, config);
})();