Twitter Enhancement

Remove promoted tweets and ads from Twitter feed

  1. // ==UserScript==
  2. // @name Twitter Enhancement
  3. // @description Remove promoted tweets and ads from Twitter feed
  4. // @name:ar تحسين تويتر
  5. // @description:ar إزالة التغريدات المروجة والإعلانات من تغذية تويتر
  6. // @name:bg Подобрение за Туитър
  7. // @description:bg Премахване на промотирани туитове и реклами от емисията на Туитър
  8. // @name:cs Vylepšení Twitteru
  9. // @description:cs Odstranění propagovaných tweetů a reklam z feedu Twitteru
  10. // @name:da Twitter Forbedring
  11. // @description:da Fjern promoverede tweets og annoncer fra Twitter-feedet
  12. // @name:de Twitter Verbesserung
  13. // @description:de Entfernt beworbene Tweets und Werbung aus dem Twitter-Feed
  14. // @name:el Βελτίωση Twitter
  15. // @description:el Αφαίρεση προωθούμενων tweets και διαφημίσεων από τη ροή του Twitter
  16. // @name:en Twitter Enhancement
  17. // @description:en Remove promoted tweets and ads from Twitter feed
  18. // @name:eo Twitter Plibonigo
  19. // @description:eo Forigi promociitajn tvitajn kaj reklamojn el la Twitter-fluo
  20. // @name:es Mejora de Twitter
  21. // @description:es Elimina tweets promocionados y anuncios del feed de Twitter
  22. // @name:fi Twitterin Parannus
  23. // @description:fi Poista mainostetut twiitit ja mainokset Twitter-syötteestä
  24. // @name:fr Amélioration de Twitter
  25. // @description:fr Supprime les tweets sponsorisés et les publicités du fil Twitter
  26. // @name:fr-CA Amélioration de Twitter
  27. // @description:fr-CA Supprime les tweets commandités et les annonces du fil Twitter
  28. // @name:he שיפור טוויטר
  29. // @description:he הסרת ציוצים מקודמים ופרסומות מהפיד של טוויטר
  30. // @name:hr Poboljšanje Twittera
  31. // @description:hr Uklanjanje promoviranih tvitova i oglasa iz Twitter feeda
  32. // @name:hu Twitter Fejlesztés
  33. // @description:hu Eltávolítja a promótált tweeteket és hirdetéseket a Twitter hírfolyamból
  34. // @name:id Peningkatan Twitter
  35. // @description:id Hapus tweet yang dipromosikan dan iklan dari umpan Twitter
  36. // @name:it Miglioramento Twitter
  37. // @description:it Rimuove i tweet promossi e gli annunci dal feed di Twitter
  38. // @name:ja Twitter強化
  39. // @description:ja Twitterフィードからプロモーションツイートと広告を削除
  40. // @name:ka Twitter-ის გაუმჯობესება
  41. // @description:ka წაშლის პრომოუშენ თვითებსა და რეკლამებს Twitter-ის ნაკადიდან
  42. // @name:ko 트위터 개선
  43. // @description:ko 트위터 피드에서 홍보 트윗과 광고 제거
  44. // @name:nb Twitter Forbedring
  45. // @description:nb Fjern promoverte tweets og annonser fra Twitter-feeden
  46. // @name:nl Twitter Verbetering
  47. // @description:nl Verwijder gepromote tweets en advertenties uit de Twitter-feed
  48. // @name:pl Ulepszenie Twittera
  49. // @description:pl Usuwa promowane tweety i reklamy z feedu Twittera
  50. // @name:pt-BR Melhoria no Twitter
  51. // @description:pt-BR Remove tweets promovidos e anúncios do feed do Twitter
  52. // @name:ro Îmbunătățire Twitter
  53. // @description:ro Elimină tweet-urile promovate și reclamele din fluxul Twitter
  54. // @name:ru Улучшение Twitter
  55. // @description:ru Удаляет продвигаемые твиты и рекламу из ленты Twitter
  56. // @name:sk Vylepšenie Twitteru
  57. // @description:sk Odstráni propagované tweety a reklamy z feedu Twitteru
  58. // @name:sr Побољшање Твитера
  59. // @description:sr Уклања промовисане твитове и огласе из Твитер фида
  60. // @name:sv Twitter Förbättring
  61. // @description:sv Ta bort sponsrade tweets och annonser från Twitter-flödet
  62. // @name:th การปรับปรุง Twitter
  63. // @description:th ลบโพสต์ที่ได้รับการโปรโมทและโฆษณาออกจากฟีด Twitter
  64. // @name:tr Twitter Geliştirme
  65. // @description:tr Twitter akışından tanıtılan tweetleri ve reklamları kaldır
  66. // @name:ug Twitter ياخشىلاش
  67. // @description:ug Twitter ئېقىمىدىن تەشۋىق قىلىنغان تىۋىتلار ۋە ئېلانلارنى چىقىرىۋېتىش
  68. // @name:uk Покращення Twitter
  69. // @description:uk Видаляє просувані твіти та рекламу зі стрічки Twitter
  70. // @name:vi Cải tiến Twitter
  71. // @description:vi Xóa các tweet được quảng bá và quảng cáo khỏi nguồn cấp dữ liệu Twitter
  72. // @name:zh Twitter增强
  73. // @description:zh 从Twitter feed中移除推广推文和广告
  74. // @name:zh-CN Twitter增强
  75. // @description:zh-CN 从Twitter feed中移除推广推文和广告
  76. // @name:zh-HK Twitter增強
  77. // @description:zh-HK 從Twitter feed中移除推廣貼文同廣告
  78. // @name:zh-SG Twitter增强
  79. // @description:zh-SG 从Twitter feed中移除推广推文和广告
  80. // @name:zh-TW Twitter增強
  81. // @description:zh-TW 從Twitter動態消息中移除推廣貼文與廣告
  82. // @namespace http://tampermonkey.net/
  83. // @version 1.1.3
  84. // @author aspen138
  85. // @match *://twitter.com/*
  86. // @match *://x.com/*
  87. // @grant none
  88. // @license MIT
  89. // @grant GM_addStyle
  90. // @icon https://about.twitter.com/etc/designs/about2-twitter/public/img/favicon-32x32.png
  91. // ==/UserScript==
  92.  
  93.  
  94. // Twitter Ad Remover
  95. (function() {
  96. function hideAd(node) {
  97. if (
  98. !node ||
  99. node.nodeName !== "DIV" ||
  100. node.getAttribute("data-testid") !== "cellInnerDiv"
  101. ) {
  102. return;
  103. }
  104.  
  105. const adArticle = node.querySelector("div[data-testid='placementTracking'] > article");
  106. if (!adArticle) {
  107. return;
  108. }
  109.  
  110. node.style.cssText += "display: none;";
  111. }
  112.  
  113. // Observe for newly added nodes and hide ads in them
  114. new MutationObserver(function(mutations) {
  115. mutations.forEach(function(mutation) {
  116. mutation.addedNodes.forEach(hideAd);
  117. });
  118.  
  119. // Hide the sidebar ad
  120. const sidebarAd = document.querySelector("#react-root > div > div > div.css-175oi2r.r-1f2l425.r-13qz1uu.r-417010.r-18u37iz > main > div > div > div > div.css-175oi2r.r-aqfbo4.r-10f7w94.r-1hycxz > div > div.css-175oi2r.r-1hycxz.r-gtdqiz > div > div > div > div:nth-child(3) > div > aside");
  121. if (sidebarAd) {
  122. sidebarAd.style.display = 'none';
  123. }
  124. }).observe(document.body, {
  125. childList: true,
  126. subtree: true
  127. });
  128.  
  129. // Initial pass to hide existing ads
  130. document.querySelectorAll("div[data-testid='cellInnerDiv']").forEach(hideAd);
  131.  
  132. function removePromotedTweets(node) {
  133. node = node || document.body;
  134. const tweets = node.querySelectorAll('article[data-testid="tweet"]');
  135.  
  136. tweets.forEach((tweet) => {
  137. const adLabel = tweet.querySelector('div[dir="ltr"] > span');
  138. if (adLabel && (adLabel.textContent === 'Promoted' || adLabel.textContent === 'Ad')) {
  139. tweet.remove();
  140. }
  141. });
  142. }
  143.  
  144. // Initial removal of promoted tweets
  145. removePromotedTweets();
  146.  
  147. // Observe the DOM for changes and remove newly added promoted tweets
  148. new MutationObserver(function(mutations) {
  149. mutations.forEach(function(mutation) {
  150. mutation.addedNodes.forEach(function(node) {
  151. if (node.nodeType === Node.ELEMENT_NODE) {
  152. removePromotedTweets(node);
  153. }
  154. });
  155. });
  156. }).observe(document.body, {
  157. childList: true,
  158. subtree: true
  159. });
  160. })();
  161.  
  162.  
  163.  
  164. // I can understand summarizing a user's profile. But what's the point of summarizing a tweet that's not even very long????
  165. // hide Grok xAI "explain this post"
  166. (function() {
  167. 'use strict';
  168.  
  169. // Inject a <style> tag with display: none !important for the specific SVG elements
  170. const style = document.createElement('style');
  171. style.innerHTML = 'button[aria-label="Grok actions"] { display: none !important; }';
  172. document.head.appendChild(style);
  173.  
  174. // Select all specific SVG elements based on their class names
  175. const svgElements = document.querySelectorAll('button[aria-label="Grok actions"]');
  176.  
  177. // Hide each matched SVG element
  178. svgElements.forEach(svg => {
  179. svg.style.display = 'none';
  180. });
  181. })();