Rehike for YouTube (Userscript)

Modify YouTube's UI to look like older versions, similar to Rehike

Fra 04.04.2025. Se den seneste versjonen.

// ==UserScript==
// @name         Rehike for YouTube (Userscript)
// @namespace    https://greasyfork.org/en/users/your-username
// @version      1.0
// @description  Modify YouTube's UI to look like older versions, similar to Rehike
// @author       Your Name
// @match        *://www.youtube.com/*
// @icon         https://www.youtube.com/favicon.ico
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    console.log("[Rehike Userscript] Loaded.");

    // Apply basic UI modifications
    function modifyYouTubeUI() {
        GM_addStyle(`
            #masthead-container { background-color: #222 !important; }
            ytd-searchbox { background-color: #333 !important; }
            ytd-app { background-color: #181818 !important; }
            /* Hide YouTube Shorts */
            ytd-rich-section-renderer { display: none !important; }
        `);
    }

    // Intercept API Calls to modify JSON data
    function interceptAPI() {
        const open = window.XMLHttpRequest.prototype.open;
        window.XMLHttpRequest.prototype.open = function(method, url) {
            if (url.includes("browse") || url.includes("next")) {
                this.addEventListener("readystatechange", function() {
                    if (this.readyState === 4 && this.responseText) {
                        try {
                            let response = JSON.parse(this.responseText);

                            // Modify response to remove Shorts (example)
                            if (response.contents) {
                                response.contents = response.contents.filter(
                                    content => !content.id.includes("shorts")
                                );
                            }

                            Object.defineProperty(this, "responseText", { get: () => JSON.stringify(response) });
                        } catch (e) {
                            console.error("[Rehike Userscript] API Intercept Error:", e);
                        }
                    }
                });
            }
            return open.apply(this, arguments);
        };
    }

    // Run modifications
    function init() {
        modifyYouTubeUI();
        interceptAPI();
    }

    // Check when YouTube loads and run script
    let observer = new MutationObserver((mutations, obs) => {
        if (document.querySelector("ytd-app")) {
            obs.disconnect();
            init();
        }
    });

    observer.observe(document, { childList: true, subtree: true });
})();