YouTube Title Fixer

Fixes a severely broken UI flaw in YouTube by removing the annoying and unnecessary "(X)" from page titles. Seriously, I have 15 tabs in a row showing "(1) ...", obscuring the actual page titles. This is just stupid.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube Title Fixer
// @description  Fixes a severely broken UI flaw in YouTube by removing the annoying and unnecessary "(X)" from page titles. Seriously, I have 15 tabs in a row showing "(1) ...", obscuring the actual page titles. This is just stupid.
// @author       Braden Best
// @namespace    bradenscode.nogit
// @version      1.0.3
// @match        *://*.youtube.com/*
// ==/UserScript==

/*
 * A debugging and testing interface is provided by a constant named
 * `youtube_title_fixer`. The interface can be seen near the end of the
 * code, in the frozen object.
 *
 * By default, this interface is inaccessible. The interface can be made
 * visible to the global scope by enabling `expose_interface`.
 *
 * If you plan to use the interface for anything other than testing,
 * then you may be missing the point.
 */

(function(){
    const expose_interface = false;

    const youtube_title_fixer = (function(){
        const pattern = /\(\d+\)\s+/;

        let loop;
        let delay = 1000;

        function fixit(){
            if(document.title.match(pattern) !== null)
                document.title = document.title.replace(pattern, "");
        }

        function kill(){
            clearInterval(loop);
        }

        function init(){
            loop = setInterval(fixit, delay);
        }

        function set_delay(new_delay){
            delay = new_delay;
        }

        return Object.freeze({
            fixit,
            kill,
            init,
            set_delay
        });
    }());

    youtube_title_fixer.init();

    if(expose_interface)
        window.youtube_title_fixer = youtube_title_fixer;
}());