NiTwit - From Twitter to Nitter and back

Show a button on the top right to quickly toggle between Twitter and Nitter.net (or any other instance).

  1. // ==UserScript==
  2. // @name NiTwit - From Twitter to Nitter and back
  3. // @namespace https://github.com/appel/userscripts
  4. // @version 0.1.15
  5. // @description Show a button on the top right to quickly toggle between Twitter and Nitter.net (or any other instance).
  6. // @author Ap
  7. // @match *://*.twitter.com/*
  8. // @match *://*.x.com/*
  9. // @match *://*.nitter.net/*
  10. // @match *://nitter.poast.org/*
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. ("use strict");
  17.  
  18. if (window.self !== window.top) {
  19. return; // Return if inside an iframe
  20. }
  21.  
  22. let alternateDomain = "https://nitter.poast.org";
  23.  
  24. let observer = new MutationObserver(function () {
  25. if (document.querySelector(".nitter-switch")) {
  26. return;
  27. }
  28.  
  29. const url = window.location.href;
  30. let btnColor, btnText, btnTitle;
  31.  
  32. if (url.includes("twitter.com") || url.includes("x.com")) {
  33. btnColor = "#ff6c60";
  34. btnText = "N";
  35. btnTitle = "Switch to Nitter";
  36. } else if (url.includes(alternateDomain)) {
  37. btnColor = "#1d9bf0";
  38. btnText = "T";
  39. btnTitle = "Switch to Twitter";
  40. }
  41.  
  42. let btn = document.createElement("button");
  43. btn.classList.add("nitter-switch");
  44. btn.textContent = btnText;
  45. btn.title = btnTitle;
  46. btn.style.position = "fixed";
  47. btn.style.top = "10px";
  48. btn.style.right = "10px";
  49. btn.style.zIndex = "9999";
  50. btn.style.backgroundColor = btnColor;
  51. btn.style.color = "white";
  52. btn.style.borderRadius = "50%";
  53. btn.style.width = "24px";
  54. btn.style.height = "24px";
  55. btn.style.border = "none";
  56. btn.style.cursor = "pointer";
  57. btn.style.fontFamily = "-apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif";
  58. btn.style.fontSize = "14px";
  59. btn.style.fontWeight = "700";
  60. btn.style.textAlign = "center";
  61. btn.style.padding = "0";
  62. btn.style.lineHeight = "24px";
  63. btn.style.transition = "transform .15s ease";
  64.  
  65. document.body.appendChild(btn);
  66.  
  67. btn.addEventListener("click", function () {
  68. let url = window.location.href;
  69. let newUrl = "";
  70.  
  71. if (url.includes("x.com")) {
  72. newUrl = url.replace("https://x.com", alternateDomain);
  73. } else if (url.includes("twitter.com")) {
  74. newUrl = url.replace("https://twitter.com", alternateDomain);
  75. } else if (url.includes(alternateDomain)) {
  76. newUrl = url.replace(alternateDomain, "https://twitter.com");
  77. }
  78.  
  79. // Add "pop" animation
  80. this.style.transform = "scale(1.2)";
  81. setTimeout(() => (this.style.transform = "scale(1)"), 150);
  82.  
  83. window.location.href = newUrl;
  84. });
  85. });
  86.  
  87. observer.observe(document, { childList: true, subtree: true });
  88. })();

QingJ © 2025

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