Youtube 隱藏評價欄

隱藏 喜歡/不喜歡 的評價欄。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name                Youtube: Hide Rating Bar
// @name:zh-TW          Youtube 隱藏評價欄
// @name:zh-CN          Youtube 隐藏评分栏
// @name:ja             Youtube 評価バーを非表示
// @name:ko             Youtube 등급 표시 줄 숨기기
// @name:ru             Youtube Скрыть панель рейтинга
// @version             1.0.0
// @description         Hide the Like/Dislike bar.
// @description:zh-TW   隱藏 喜歡/不喜歡 的評價欄。
// @description:zh-CN   隐藏 喜欢/不喜欢 的评分栏。
// @description:ja      高評価/低評価 バーを非表示にします。
// @description:ko      좋아요 / 싫어요 표시 줄을 숨 깁니다.
// @description:ru      Скрыть панель «Мне нравится / не нравится».
// @author              Hayao-Gai
// @namespace           https://github.com/HayaoGai
// @icon                https://upload.wikimedia.org/wikipedia/commons/4/4c/YouTube_icon.png
// @match               https://www.youtube.com/*
// @grant               none
// ==/UserScript==

/* jshint esversion: 6 */

(function() {
    'use strict';

    const targets = [
        //"ytd-toggle-button-renderer", // button
        "yt-formatted-string.style-scope.ytd-toggle-button-renderer", // number
        //"paper-tooltip.style-scope.ytd-toggle-button-renderer", // tooltip
        "#sentiment" // bar
    ];

    let href = document.location.href;

    init(10);

    observation();

    function init(times) {
        for (let i = 0; i < times; i++) {
            for (const target of targets) {
                setTimeout(() => hideTarget(target), 500 * i);
            }
        }
    }

    function hideTarget(target) {
        document.querySelectorAll(target).forEach(t => t.remove());
    }

    function observation() {
        const observer = new MutationObserver(mutations => {
            mutations.forEach(() => {
                if (href != document.location.href) {
                    href = document.location.href;
                    init(10);
                }
            });
        });
        const target = document.querySelector("body");
        const config = { childList: true, subtree: true };
        observer.observe(target, config);
    }

})();