Twitter Tab Revert

Reverts the Twitter favicon and tab title

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Twitter Tab Revert
// @namespace    aubymori.github.io
// @version      2.0.2
// @description  Reverts the Twitter favicon and tab title
// @author       aubymori
// @match        https://twitter.com/*
// @match        https://x.com/*
// @icon         https://abs.twimg.com/favicons/twitter.2.ico
// @license      Unlicense
// @grant        none
// ==/UserScript==

let faviconElOg = null;
let faviconEl = document.createElement("link");
faviconEl.setAttribute("rel", "shortcut icon");
faviconEl.setAttribute("href", "https://abs.twimg.com/favicons/twitter.2.ico");

async function waitForElm(sel)
{
    while (document.querySelector(sel) == null)
    {
        await new Promise(r => requestAnimationFrame(r));
    }
    return document.querySelector(sel);
}

waitForElm("link[rel=\"shortcut icon\"]").then(() => {
    document.head.insertAdjacentElement("beforeend", faviconEl);
});

function revertTab()
{
    if (faviconElOg == null)
    {
        faviconElOg = document.querySelector("link[rel=\"shortcut icon\"]");
        if (faviconElOg == null)
        {
            return;
        }
    }

    faviconEl.setAttribute(
        "href",
        faviconElOg.getAttribute("href").replace(/\.3\.ico$/, ".2.ico")
    );

    if (document.title.endsWith("X"))
    {
        document.title = document.title.replace(/X$/, "Twitter");
    }
}

setInterval(revertTab, 10);