Revert X Embed back to Twitter Embed

Replaces X references in the Twitter/X embed with the original Twitter ones.

  1. // ==UserScript==
  2. // @license GNU GPLv3
  3. // @name Revert X Embed back to Twitter Embed
  4. // @name:fr Nom et logo originaux de Twitter sur les embeds (contenus externes embarqués)
  5. // @name:es Revertir X a Twitter en los Tweets insertados
  6. // @namespace https://github.com/CatmanFan/Revert-X-to-Twitter-Embed/
  7. // @icon https://www.iconarchive.com/download/i76545/xenatt/minimalism/App-Twitter.256.png
  8. // @author Mr._Lechkar / CatmanFan
  9. // @description Replaces X references in the Twitter/X embed with the original Twitter ones.
  10. // @description:fr Modifier les embeds (contenus externes embarqués) de Twitter/X en replaçant les références à X par les originales de Twitter (par exemple, « Poster sur X » devient désormais « Tweeter sur Twitter »).
  11. // @description:es Reemplazar el logotipo de X y sus otras referencias en los Tweets insertados (embeds) por las originales de Twitter.
  12. // @version 0.35
  13. // @match https://platform.twitter.com/embed/Tweet.html
  14. // @match https://platform.twitter.com/embed/Tweet.html*
  15. // @match https://platform.x.com/embed/Tweet.html
  16. // @match https://platform.x.com/embed/Tweet.html*
  17. // @match https://platform.twitter.com/embed/index.html
  18. // @match https://platform.twitter.com/embed/index.html*
  19. // @match https://platform.x.com/embed/index.html
  20. // @match https://platform.x.com/embed/index.html*
  21. // @match https://syndication.twitter.com/*
  22. // @match https://syndication.x.com/*
  23. // @run-at document-start
  24. // @grant GM_addStyle
  25. // ==/UserScript==
  26.  
  27.  
  28. // Original color (copied from Yakisova's X to Twitter userscript)
  29. GM_addStyle(`
  30. svg.r-18jsvk2 {
  31. color: rgb(29, 155, 240);
  32. }
  33. `);
  34.  
  35. // Original bird (copied from Yakisova's X to Twitter userscript)
  36. 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';
  37. const 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'
  38.  
  39. // Check for "X"/"post" string and return reverted, function
  40. function revertString(item) {
  41. var string = item;
  42.  
  43. // Other languages
  44. switch (document.getElementsByTagName('html')[0].getAttribute('lang'))
  45. {
  46. case "ru":
  47. if (string.includes(" пост")) { string = string.replace(" пост", " твит"); }
  48. break;
  49. case "uk":
  50. if (string.includes(" пост")) { string = string.replace(" пост", " твіт"); }
  51. break;
  52. case "de":
  53. if (string.includes("Post")) { string = string.replace("Post", "Tweet"); }
  54. break;
  55. case "pl":
  56. if (string.includes("wpis")) { string = string.replace("wpis", "Tweet"); }
  57. break;
  58. case "ro":
  59. string = string.replace("această postare", "acest Tweet");
  60. string = string.replace("postare", "Tweet");
  61. break;
  62. case "fi":
  63. string = string.replace("julkaisusta", "twiitistä");
  64. string = string.replace("julkaisuun", "twiittiin");
  65. string = string.replace("julkaisu", "twiitti");
  66. break;
  67. case "tr":
  68. string = string.replace("Gönderinin", "Tweet'in");
  69. string = string.replace("gönderiyi", "Tweet'i");
  70. if (string.includes("gönderi")) { string = string.replace("gönderi", "Tweet"); }
  71. if (string.includes("Gönderi")) { string = string.replace("Gönderi", "Tweet"); }
  72. break;
  73. case "ar": // Broken currently, so it is unimplemented
  74. // string = string.replace(" X", " تويتر");
  75. // string = string.replace("هذا المنشور", "هذه التغريدة");
  76. // if (string.includes("المنشور")) { window.alert(string); string = string.replace("منشور", "تغريدة"); }
  77. break;
  78. case "ko":
  79. string = string.replace("게시물", "트윗에");
  80. string = string.replace("게시", "트윗");
  81. break;
  82. case "ja":
  83. string = string.replace("ポスト", "ツイート");
  84. break;
  85. }
  86.  
  87. // Copy link
  88. if (string == "Copy link") { string = "Copy link to post"; }
  89. if (string == "Copy link to post") { string = "Copy link to Tweet"; }
  90.  
  91. if (string.includes("post")) { string = string.replace("post", "Tweet"); }
  92. if (string.includes("Post")) { string = string.replace("Post", "Tweet"); }
  93. if (string.includes(" X")) { string = string.replace(" X", " Twitter"); }
  94. if (string.includes(" X")) { string = string.replace(" X", " Twitter"); }
  95.  
  96. return string;
  97. }
  98.  
  99. function revertXLogo() {
  100. SVG = document.getElementsByClassName("r-18jsvk2 r-4qtqp9 r-yyyyoo r-dnmrzs r-bnwqim r-1plcrui r-lrvibr")[0].querySelector('g').querySelector('path');
  101. SVG.setAttribute('d', birdPath);
  102.  
  103. SVG = document.getElementsByClassName("r-jwli3a r-4qtqp9 r-yyyyoo r-1yevf0r r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-meisx5")[2].querySelector('g').querySelector('path');
  104. SVG.setAttribute('d', birdPath);
  105.  
  106. SVG = document.getElementsByClassName("css-901oao r-1awozwy r-jwli3a r-6koalj r-18u37iz r-16y2uox r-1qd0xha r-1b43r93 r-b88u0q r-1777fci r-hjklzo r-bcqeeo r-q4m81j r-qvutc0")[0];
  107. SVG.getElementsByClassName("r-jwli3a r-4qtqp9 r-yyyyoo r-1yevf0r r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-meisx5")[0].querySelector('g').querySelector('path').setAttribute('d', birdPath);
  108. }
  109.  
  110. function revertXLogoEmbed() {
  111. SVG1 = document.getElementsByClassName("r-jwli3a r-4qtqp9 r-yyyyoo r-z80fyv r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-19wmn03")[2].querySelector('g').querySelector('path');
  112. SVG1.setAttribute('d', birdPath);
  113. }
  114.  
  115. function checkValidity(item) {
  116. var valid = false;
  117. if (item) { valid = true; }
  118. if (item.parentNode && item.parentNode.getAttribute('data-testid') == "tweetText") { return false; }
  119. return valid;
  120. }
  121.  
  122. function revertHover() {
  123. var item = document.getElementById("layers").getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  124.  
  125. if (checkValidity(item) == true) { item.innerHTML = revertString(item.innerHTML); }
  126. }
  127.  
  128. // Revert all strings
  129. function revertStrings() {
  130.  
  131. // "Share this post"
  132. var items = document.getElementsByClassName("css-901oao css-1hf3ou5 r-14j79pv r-1qd0xha r-1b43r93 r-b88u0q r-1cwl3u0 r-13hce6t r-bcqeeo r-qvutc0");
  133.  
  134. for (itemX of items) {
  135. item = itemX.getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  136. if (checkValidity(item) == true) { item.innerHTML = revertString(item.innerHTML); }
  137. }
  138.  
  139. // "Copy link" / "Copy link to post"
  140. items = document.getElementsByClassName("css-901oao css-1hf3ou5 r-14j79pv r-1qd0xha r-1b43r93 r-b88u0q r-1cwl3u0 r-13hce6t r-bcqeeo r-qvutc0");
  141.  
  142. for (itemX of items) {
  143. item = itemX.getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  144. if (checkValidity(item) == true) { item.innerHTML = revertString(item.innerHTML); }
  145. }
  146.  
  147. // "Read more on X"
  148. items = document.getElementsByClassName("css-901oao css-16my406 css-1hf3ou5 r-poiln3 r-1b43r93 r-1cwl3u0 r-bcqeeo r-qvutc0");
  149.  
  150. for (itemX of items) {
  151. item = itemX.getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  152. if (checkValidity(item) == true) { item.innerHTML = revertString(item.innerHTML); }
  153. }
  154.  
  155. // "View on X"
  156. items = document.getElementsByClassName("css-901oao r-jwli3a r-1qd0xha r-1gkfh8e r-16dba41 r-56xrmm r-146iojx r-bcqeeo r-s1qlax r-1vvnge1 r-qvutc0");
  157.  
  158. for (itemX of items) {
  159. item = itemX.getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  160. if (checkValidity(item) == true) { item.innerHTML = revertString(item.innerHTML); }
  161. }
  162.  
  163. // "Watch on X" / "Continue watching on X"
  164. items = document.getElementsByClassName("css-901oao css-16my406 css-1hf3ou5 r-poiln3 r-n6v787 r-fxxt2n r-bcqeeo r-qvutc0");
  165.  
  166. for (itemX of items) {
  167. item = itemX.getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  168. if (checkValidity(item) == true) { item.innerHTML = revertString(item.innerHTML); }
  169. }
  170.  
  171. // "Context is written by people who use X, and appears when rated helpful by others."
  172. items = document.getElementsByClassName("css-901oao r-14j79pv r-1qd0xha r-1enofrn r-16dba41 r-fxxt2n r-bcqeeo r-kmv1fd r-qvutc0");
  173.  
  174. for (itemX of items) {
  175. item = itemX.getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  176. if (checkValidity(item) == true) { item.innerHTML = revertString(item.innerHTML); }
  177.  
  178. var items1 = itemX.getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0");
  179. for (itemX1 of items1) {
  180. item = itemX.getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  181. if (checkValidity(item) == true) { item.innerHTML = revertString(item.innerHTML); }
  182. }
  183. }
  184.  
  185. // "Some or all of the content shared in this Post is disputed and might be misleading about an election or other civic process."
  186. items = document.getElementsByClassName("css-901oao r-1qd0xha r-a023e6 r-16dba41 r-rjixqe r-bcqeeo r-qvutc0");
  187.  
  188. for (itemX of items) {
  189. item = itemX.getElementsByClassName("css-901oao css-16my406 r-poiln3 r-bcqeeo r-qvutc0")[0];
  190. if (checkValidity(item) == true) { item.innerHTML = revertString(item.innerHTML); }
  191. }
  192.  
  193.  
  194. // Same for Accessibility Labels
  195. // NOTE: Not fully working at the present moment
  196. /* items = document.querySelectorAll('body *');
  197.  
  198. for (item of items) {
  199. if (item.getAttribute('aria-label').includes(" X") || item.getAttribute('aria-label').includes(" post"))
  200. {
  201. string = item.getAttribute('aria-label');
  202. window.alert(string);
  203. item.setAttribute('aria-label', revertString(string));
  204. }
  205. } */
  206. }
  207.  
  208. // Delete "Not found" error, which was not present before Musk takeover iirc
  209. function deleteNotFound()
  210. {
  211. const txt = document.documentElement.innerHTML;
  212.  
  213. if (txt.includes("M12 20.25c4.56 0 8.25-3.69 8.25-8.25S16.56 3.75 12 3.75 3.75 7.44 3.75 12s3.69 8.25 8.25 8.25zM22.25 12c0 5.66-4.59 10.25-10.25 10.25S1.75 17.66 1.75 12 6.34 1.75 12 1.75 22.25 6.34 22.25 12zM10.5 15.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5S12.83 17 12 17s-1.5-.67-1.5-1.5zm.5-2.8L10.75 7h2.5L13 12.7s-.5-.2-1-.2-1 .2-1 .2z") && txt.includes(">Not found</span>"))
  214. {
  215. document.documentElement.innerHTML = "";
  216. }
  217. }
  218.  
  219. setInterval(revertXLogo, 1);
  220. setInterval(revertXLogoEmbed, 1);
  221. setInterval(revertHover, 1);
  222. setInterval(revertStrings, 1);
  223. setInterval(deleteNotFound, 1);