Clean YouTube Links

Cleans YouTube Links

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
})();