Revert X to Twitter Embed

Fixes Twitter/X embed by reverting X references back to original Twitter ones.

当前为 2023-12-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @license GNU GPLv3
  3. // @name Revert X to Twitter Embed
  4. // @namespace https://github.com/CatmanFan/Revert-X-to-Twitter-Embed/
  5. // @icon https://www.iconarchive.com/download/i76545/xenatt/minimalism/App-Twitter.256.png
  6. // @author Mr._Lechkar / CatmanFan
  7. // @description Fixes Twitter/X embed by reverting X references back to original Twitter ones.
  8. // @version 0.1
  9. // @match https://platform.twitter.com/embed/Tweet.html
  10. // @run-at document-start
  11. // @grant GM_addStyle
  12. // ==/UserScript==
  13.  
  14. // Original color (copied from Yakisova's X to Twitter userscript)
  15. GM_addStyle(`
  16. svg.r-18jsvk2 {
  17. color: rgb(29, 155, 240);
  18. }
  19. `);
  20.  
  21. // Original bird (copied from Yakisova's X to Twitter userscript)
  22. var birdPath = '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';
  23. var xPath = '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'
  24.  
  25. // Check for "X"/"post" string and return reverted, function
  26. function revertString(item) {
  27. var string = item;
  28.  
  29. if (string.includes("post")) { string = string.replace("post", "Tweet"); }
  30. if (string.includes(" X")) { string = string.replace(" X", " Twitter"); }
  31.  
  32. return string;
  33. }
  34.  
  35. function revertXLogo() {
  36. SVG = document.getElementsByClassName("r-18jsvk2 r-4qtqp9 r-yyyyoo r-6zzn7w r-19fsva8 r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-q1j0wu")[0].querySelector('g').querySelector('path');
  37.  
  38. if (SVG.getAttribute('d') == xPath) {
  39. SVG.setAttribute('d', birdPath);
  40. }
  41. }
  42.  
  43. function revertHover() {
  44. var Text = document.getElementById("layers").getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  45.  
  46. if (Text) { Text.innerHTML = revertString(Text.innerHTML); }
  47. }
  48.  
  49.  
  50. // Revert all strings
  51. function revertStrings() {
  52.  
  53. // "Share this post"
  54. var items = document.getElementsByClassName("css-901oao css-1hf3ou5 r-14j79pv r-1qd0xha r-1b43r93 r-b88u0q r-1cwl3u0 r-13hce6t r-bcqeeo r-qvutc0");
  55.  
  56. for (itemX of items) {
  57. item = itemX.getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  58. if (item) { item.innerHTML = revertString(item.innerHTML); }
  59. }
  60.  
  61. // "Read more on X"
  62. items = document.getElementsByClassName("css-901oao css-16my406 css-1hf3ou5 r-poiln3 r-1b43r93 r-1cwl3u0 r-bcqeeo r-qvutc0");
  63.  
  64. for (itemX of items) {
  65. item = itemX.getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  66. if (item) { item.innerHTML = revertString(item.innerHTML); }
  67. }
  68.  
  69. // Same for Accessibility Labels
  70. /* items = document.querySelectorAll('body *');
  71.  
  72. for (item of items) {
  73. if (item.getAttribute('aria-label').includes(" X") || item.getAttribute('aria-label').includes(" post"))
  74. {
  75. string = item.getAttribute('aria-label');
  76. window.alert(string);
  77. item.setAttribute('aria-label', revertString(string));
  78. }
  79. } */
  80. }
  81.  
  82. setInterval(revertXLogo, 1);
  83. setInterval(revertHover, 1);
  84. setInterval(revertStrings, 5);