Fix X button

Fixes the faulty new X button

  1. // ==UserScript==
  2. // @name Fix X button
  3. // @namespace https://twitter.com/
  4. // @version 1.1
  5. // @description Fixes the faulty new X button
  6. // @author You
  7. // @match https://twitter.com/
  8. // @match https://*.twitter.com/
  9. // @match https://twitter.com/*
  10. // @match https://*.twitter.com/*
  11. // @match https://x.com/
  12. // @match https://*.x.com/
  13. // @match https://x.com/*
  14. // @match https://*.x.com/*
  15. // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com
  16. // @grant window.close
  17. // @license JSON
  18. // ==/UserScript==
  19.  
  20. (function() {
  21. 'use strict';
  22.  
  23. const closeTab = () => {
  24. // in case window.close doesn't work, we need to have a fallback
  25. document.head.innerHTML = "<style>body { color: orange; background: black }</style>"
  26. document.body.innerHTML = "It's now safe to turn off your computer."
  27.  
  28. // close the tab
  29. window.close()
  30. }
  31.  
  32. const fixSvgElement = (v) => {
  33. if(v.innerHTML.includes("M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z")) { // filter to the X button
  34. v.style.cursor = "pointer";
  35. v.onclick = closeTab
  36. }
  37. }
  38. const observer = new MutationObserver(mutations => {
  39. Array.from(document.getElementsByTagName("svg")).forEach(fixSvgElement);
  40. });
  41.  
  42. observer.observe(document, {
  43. childList: true,
  44. subtree: true
  45. });
  46.  
  47. Array.from(document.getElementsByTagName("svg")).forEach(fixSvgElement);
  48. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址