Clean YouTube Links

Cleans YouTube Links

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();