Rehike for YouTube (Userscript)

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

目前為 2025-04-04 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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