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.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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;
}());