Rehike for YouTube (Userscript)

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

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

You will need to install an extension such as Tampermonkey to install this 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         Rehike for YouTube (Userscript)
// @namespace    https://greasyfork.org/en/users/your-username
// @version      1.1
// @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_addStyle
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

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

    // Apply 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 Shorts Section */
            ytd-rich-section-renderer { display: none !important; }
        `);
    }

    // Intercept API Calls via Fetch API
    function interceptFetch() {
        const originalFetch = window.fetch;
        window.fetch = async function(resource, init) {
            let response = await originalFetch(resource, init);

            if (typeof resource === "string" && resource.includes("browse")) {
                try {
                    let clone = response.clone();
                    let json = await clone.json();

                    // Remove Shorts from Homepage
                    if (json.contents?.twoColumnBrowseResultsRenderer) {
                        json.contents.twoColumnBrowseResultsRenderer.tabs =
                            json.contents.twoColumnBrowseResultsRenderer.tabs.filter(tab =>
                                !tab?.tabRenderer?.content?.sectionListRenderer?.contents?.some(
                                    sec => sec?.richSectionRenderer?.content?.shelfRenderer?.title?.simpleText === "Shorts"
                                )
                            );
                    }

                    let modifiedResponse = new Response(JSON.stringify(json), {
                        status: response.status,
                        statusText: response.statusText,
                        headers: response.headers
                    });

                    return modifiedResponse;
                } catch (e) {
                    console.error("[Rehike Userscript] Fetch Intercept Error:", e);
                }
            }

            return response;
        };
    }

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

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

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