Twitter Favicon Revert

Reverts the Twitter favicon from the X

当前为 2023-07-24 提交的版本,查看 最新版本

// ==UserScript==
// @name         Twitter Favicon Revert
// @namespace    aubymori.github.io
// @version      1.0
// @description  Reverts the Twitter favicon from the X
// @author       aubymori
// @match        https://twitter.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 revertFavicon()
{
    if (faviconElOg == null)
    {
        faviconElOg = document.querySelector("link[rel=\"shortcut icon\"]");
        if (faviconElOg == null)
        {
            alert("Failed to get favicon element");
            return;
        }
    }

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

setInterval(revertFavicon, 10);