🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

YouTube + Vorapis – Toggle Video, Comments & Sidebar

Allows toggling the visibility of YouTube videos, comments, and recommended sidebar videos

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         YouTube + Vorapis – Toggle Video, Comments & Sidebar
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Allows toggling the visibility of YouTube videos, comments, and recommended sidebar videos
// @author       Sefa AVAN
// @license      MIT
// @match        https://www.youtube.com/watch*
// @run-at       document-start
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function() {
    'use strict';

    let videoVisible = true;
    let commentsVisible = false;
    let sidebarVisible = false;

    /*************** CSS to hide comments and sidebar ***************/
    const style = document.createElement('style');
    style.textContent = `
        ytd-comments,
        #comments,
        ytd-item-section-renderer#comments,
        [node-type="comments"],
        [class*="comments"],
        [id*="comments"],
        #secondary,
        #secondary-inner,
        #related,
        ytd-watch-next-secondary-results-renderer,
        [node-type="related"],
        [class*="secondary"],
        [id*="secondary"],
        [class*="related"],
        ytd-compact-video-renderer {
            display: none !important;
        }
        ytd-watch-flexy {
            flex-direction: column !important;
        }
    `;
    document.head.appendChild(style);

    /*************** Functions ***************/
    function toggleVideo() {
        const video = document.querySelector('video');
        if (!video) return;
        videoVisible = !videoVisible;
        video.style.display = videoVisible ? 'block' : 'none';
    }

    function toggleComments() {
        const selectors = [
            "ytd-comments",
            "#comments",
            "ytd-item-section-renderer#comments",
            '[node-type="comments"]',
            '[class*="comments"]',
            '[id*="comments"]'
        ];
        commentsVisible = !commentsVisible;
        selectors.forEach(sel => {
            document.querySelectorAll(sel).forEach(el => {
                el.style.display = commentsVisible ? 'block' : 'none';
            });
        });
    }

    function toggleSidebar() {
        const selectors = [
            "#secondary",
            "#secondary-inner",
            "#related",
            "ytd-watch-next-secondary-results-renderer",
            '[node-type="related"]',
            '[class*="secondary"]',
            '[id*="secondary"]',
            '[class*="related"]',
            "ytd-compact-video-renderer"
        ];
        sidebarVisible = !sidebarVisible;
        selectors.forEach(sel => {
            document.querySelectorAll(sel).forEach(el => {
                el.style.display = sidebarVisible ? 'block' : 'none';
            });
        });
    }

    /*************** Tampermonkey Menu ***************/
    GM_registerMenuCommand("Toggle Video Visibility", toggleVideo);
    GM_registerMenuCommand("Toggle Comments Visibility", toggleComments);
    GM_registerMenuCommand("Toggle Sidebar Visibility", toggleSidebar);

    /*************** MutationObserver ***************/
    const observer = new MutationObserver(() => {
        toggleVideo();
        toggleComments();
        toggleSidebar();
    });
    observer.observe(document.documentElement, { childList: true, subtree: true });

})();