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.

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

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

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