Discord notification count remover

Removes the notification count indicator from the title

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Discord notification count remover
// @namespace    https://rant.li/boson
// @version      1.1
// @description  Removes the notification count indicator from the title
// @author       Boson
// @match        *://discord.com/*
// @grant        none
// @license      GNU AGPLv3
// ==/UserScript==


(function() {
  'use strict';
    var notificationCountRegex = new RegExp('^\\(\\d+\\)+');

    function removeTitleNotification() {
      if(notificationCountRegex.test(document.head.querySelector("title").innerText))
          document.head.querySelector("title").innerText = document.head.querySelector("title").innerText.split(')')[1];
         }
    removeTitleNotification();
    var observeDOM = (function() {
      var MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
            eventListenerSupported = window.addEventListener;

        return function(obj, callback) {
            if(MutationObserver) {
                var obs = new MutationObserver(function(mutations, observer){
                    if(mutations[0].addedNodes.length || mutations[0].removedNodes.length )
                        callback();
                });
                obs.observe(obj, {childList: true, subtree: true});
            }
            else if(eventListenerSupported ) {
                obj.addEventListener('DOMNodeInserted', callback, false);
                obj.addEventListener('DOMNodeRemoved', callback, false);
            }
        };
    })();

    var favicon_link_html = document.createElement('link');
    favicon_link_html.rel = 'icon';
    favicon_link_html.href = 'https://static-00.iconduck.com/assets.00/discord-icon-512x512-xtx725no.png';
    favicon_link_html.type = 'image/png';
    try {
      document.getElementsByTagName('head')[0].appendChild( favicon_link_html );
    }
    catch(e) { }
    observeDOM(document.head.querySelector("title"), function() {
        removeTitleNotification();
    });
})();