Get Twitter Icons Back

Restore the old icon on Twitter

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

  1. // ==UserScript==
  2. // @name Get Twitter Icons Back
  3. // @namespace Pionxzh
  4. // @version 1.0.0
  5. // @author Pionxzh
  6. // @description Restore the old icon on Twitter
  7. // @license MIT
  8. // @icon https://abs.twimg.com/favicons/twitter.2.ico
  9. // @match https://twitter.com/*
  10. // @match https://x.com/*
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
  17. function getDefaultExportFromCjs(x) {
  18. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
  19. }
  20. var sentinel_umd = { exports: {} };
  21. (function(module, exports) {
  22. (function(root, factory) {
  23. {
  24. module.exports = factory();
  25. }
  26. })(commonjsGlobal, function() {
  27. var isArray = Array.isArray, selectorToAnimationMap = {}, animationCallbacks = {}, styleEl, styleSheet, cssRules;
  28. return {
  29. /**
  30. * Add watcher.
  31. * @param {array} cssSelectors - List of CSS selector strings
  32. * @param {Function} callback - The callback function
  33. */
  34. on: function(cssSelectors, callback) {
  35. if (!callback)
  36. return;
  37. if (!styleEl) {
  38. var doc = document, head = doc.head;
  39. doc.addEventListener("animationstart", function(ev, callbacks, l, i) {
  40. callbacks = animationCallbacks[ev.animationName];
  41. if (!callbacks)
  42. return;
  43. ev.stopImmediatePropagation();
  44. l = callbacks.length;
  45. for (i = 0; i < l; i++)
  46. callbacks[i](ev.target);
  47. }, true);
  48. styleEl = doc.createElement("style");
  49. head.append(styleEl);
  50. styleSheet = styleEl.sheet;
  51. cssRules = styleSheet.cssRules;
  52. }
  53. (isArray(cssSelectors) ? cssSelectors : [cssSelectors]).map(function(selector, animId, isCustomName) {
  54. animId = selectorToAnimationMap[selector];
  55. if (!animId) {
  56. isCustomName = selector[0] == "!";
  57. selectorToAnimationMap[selector] = animId = isCustomName ? selector.slice(1) : "sentinel-" + Math.random().toString(16).slice(2);
  58. cssRules[styleSheet.insertRule(
  59. "@keyframes " + animId + "{from{transform:none;}to{transform:none;}}",
  60. cssRules.length
  61. )]._id = selector;
  62. if (!isCustomName) {
  63. cssRules[styleSheet.insertRule(
  64. selector + "{animation-duration:0.0001s;animation-name:" + animId + ";}",
  65. cssRules.length
  66. )]._id = selector;
  67. }
  68. selectorToAnimationMap[selector] = animId;
  69. }
  70. (animationCallbacks[animId] = animationCallbacks[animId] || []).push(callback);
  71. });
  72. },
  73. /**
  74. * Remove watcher.
  75. * @param {array} cssSelectors - List of CSS selector strings
  76. * @param {Function} callback - The callback function (optional)
  77. */
  78. off: function(cssSelectors, callback) {
  79. (isArray(cssSelectors) ? cssSelectors : [cssSelectors]).map(function(selector, animId, callbackList, i) {
  80. if (!(animId = selectorToAnimationMap[selector]))
  81. return;
  82. callbackList = animationCallbacks[animId];
  83. if (callback) {
  84. i = callbackList.length;
  85. while (i--) {
  86. if (callbackList[i] === callback)
  87. callbackList.splice(i, 1);
  88. }
  89. } else {
  90. callbackList = [];
  91. }
  92. if (callbackList.length)
  93. return;
  94. i = cssRules.length;
  95. while (i--) {
  96. if (cssRules[i]._id == selector)
  97. styleSheet.deleteRule(i);
  98. }
  99. delete selectorToAnimationMap[selector];
  100. delete animationCallbacks[animId];
  101. });
  102. },
  103. /**
  104. * Reset watchers and cache
  105. */
  106. reset: function() {
  107. selectorToAnimationMap = {};
  108. animationCallbacks = {};
  109. if (styleEl)
  110. styleEl.parentNode.removeChild(styleEl);
  111. styleEl = 0;
  112. }
  113. };
  114. });
  115. })(sentinel_umd);
  116. var sentinel_umdExports = sentinel_umd.exports;
  117. const sentinel = /* @__PURE__ */ getDefaultExportFromCjs(sentinel_umdExports);
  118. function onloadSafe(fn) {
  119. if (document.readyState === "complete") {
  120. fn();
  121. } else {
  122. window.addEventListener("load", fn);
  123. }
  124. }
  125. main();
  126. const twitterIconSvg = '<svg viewBox="0 0 24 24" aria-hidden="true" class="r-k200y r-1cvl2hr r-4qtqp9 r-yyyyoo r-eu3ka r-dnmrzs r-bnwqim r-1plcrui r-lrvibr"><g><path d="M23.643 4.937c-.835.37-1.732.62-2.675.733.962-.576 1.7-1.49 2.048-2.578-.9.534-1.897.922-2.958 1.13-.85-.904-2.06-1.47-3.4-1.47-2.572 0-4.658 2.086-4.658 4.66 0 .364.042.718.12 1.06-3.873-.195-7.304-2.05-9.602-4.868-.4.69-.63 1.49-.63 2.342 0 1.616.823 3.043 2.072 3.878-.764-.025-1.482-.234-2.11-.583v.06c0 2.257 1.605 4.14 3.737 4.568-.392.106-.803.162-1.227.162-.3 0-.593-.028-.877-.082.593 1.85 2.313 3.198 4.352 3.234-1.595 1.25-3.604 1.995-5.786 1.995-.376 0-.747-.022-1.112-.065 2.062 1.323 4.51 2.093 7.14 2.093 8.57 0 13.255-7.098 13.255-13.254 0-.2-.005-.402-.014-.602.91-.658 1.7-1.477 2.323-2.41z"></path></g></svg>';
  127. function main() {
  128. onloadSafe(() => {
  129. const placeHolderIconSelector = "#placeholder > svg";
  130. sentinel.on(placeHolderIconSelector, (svg) => {
  131. console.log("place", svg);
  132. svg.innerHTML = twitterIconSvg;
  133. sentinel.off(placeHolderIconSelector);
  134. });
  135. const selector = "h1 a[href='/home'] svg";
  136. sentinel.on(selector, (svg) => {
  137. console.log("svg", svg);
  138. svg.innerHTML = twitterIconSvg;
  139. sentinel.off(selector);
  140. });
  141. });
  142. }
  143.  
  144. })();