Twitter Tab Revert

Reverts the Twitter favicon and tab title

  1. // ==UserScript==
  2. // @name Twitter Tab Revert
  3. // @namespace aubymori.github.io
  4. // @version 2.0.2
  5. // @description Reverts the Twitter favicon and tab title
  6. // @author aubymori
  7. // @match https://twitter.com/*
  8. // @match https://x.com/*
  9. // @icon https://abs.twimg.com/favicons/twitter.2.ico
  10. // @license Unlicense
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. let faviconElOg = null;
  15. let faviconEl = document.createElement("link");
  16. faviconEl.setAttribute("rel", "shortcut icon");
  17. faviconEl.setAttribute("href", "https://abs.twimg.com/favicons/twitter.2.ico");
  18.  
  19. async function waitForElm(sel)
  20. {
  21. while (document.querySelector(sel) == null)
  22. {
  23. await new Promise(r => requestAnimationFrame(r));
  24. }
  25. return document.querySelector(sel);
  26. }
  27.  
  28. waitForElm("link[rel=\"shortcut icon\"]").then(() => {
  29. document.head.insertAdjacentElement("beforeend", faviconEl);
  30. });
  31.  
  32. function revertTab()
  33. {
  34. if (faviconElOg == null)
  35. {
  36. faviconElOg = document.querySelector("link[rel=\"shortcut icon\"]");
  37. if (faviconElOg == null)
  38. {
  39. return;
  40. }
  41. }
  42.  
  43. faviconEl.setAttribute(
  44. "href",
  45. faviconElOg.getAttribute("href").replace(/\.3\.ico$/, ".2.ico")
  46. );
  47.  
  48. if (document.title.endsWith("X"))
  49. {
  50. document.title = document.title.replace(/X$/, "Twitter");
  51. }
  52. }
  53.  
  54. setInterval(revertTab, 10);