Control Panel for Twitter

Gives you more control over Twitter and adds missing features and UI improvements

当前为 2023-09-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Control Panel for Twitter
  3. // @description Gives you more control over Twitter and adds missing features and UI improvements
  4. // @icon https://raw.githubusercontent.com/insin/control-panel-for-twitter/master/icons/icon32.png
  5. // @namespace https://github.com/insin/control-panel-for-twitter/
  6. // @match https://twitter.com/*
  7. // @match https://mobile.twitter.com/*
  8. // @run-at document-start
  9. // @version 133
  10. // ==/UserScript==
  11. void function() {
  12.  
  13. let debug = false
  14.  
  15. /** @type {boolean} */
  16. let desktop
  17. /** @type {boolean} */
  18. let mobile
  19. let isSafari = navigator.userAgent.includes('Safari/') && !/Chrom(e|ium)\//.test(navigator.userAgent)
  20.  
  21. /** @type {HTMLHtmlElement} */
  22. let $html
  23. /** @type {HTMLBodyElement} */
  24. let $body
  25. /** @type {HTMLElement} */
  26. let $reactRoot
  27. /** @type {string} */
  28. let lang
  29. /** @type {string} */
  30. let dir
  31. /** @type {boolean} */
  32. let ltr
  33.  
  34. //#region Default config
  35. /**
  36. * @type {import("./types").Config}
  37. */
  38. const config = {
  39. debug: false,
  40. // Shared
  41. addAddMutedWordMenuItem: true,
  42. alwaysUseLatestTweets: true,
  43. defaultToLatestSearch: false,
  44. disableHomeTimeline: false,
  45. disabledHomeTimelineRedirect: 'notifications',
  46. disableTweetTextFormatting: false,
  47. dontUseChirpFont: false,
  48. dropdownMenuFontWeight: true,
  49. fastBlock: true,
  50. followButtonStyle: 'monochrome',
  51. hideAnalyticsNav: true,
  52. hideBlueReplyFollowedBy: false,
  53. hideBlueReplyFollowing: false,
  54. hideBookmarkButton: false,
  55. hideBookmarkMetrics: true,
  56. hideBookmarksNav: false,
  57. hideCommunitiesNav: false,
  58. hideConnectNav: true,
  59. hideExplorePageContents: true,
  60. hideFollowingMetrics: true,
  61. hideForYouTimeline: true,
  62. hideHelpCenterNav: true,
  63. hideHomeHeading: true,
  64. hideKeyboardShortcutsNav: false,
  65. hideLikeMetrics: true,
  66. hideListsNav: false,
  67. hideMetrics: false,
  68. hideMonetizationNav: true,
  69. hideMoreTweets: true,
  70. hideProfileRetweets: false,
  71. hideQuoteTweetMetrics: true,
  72. hideReplyMetrics: true,
  73. hideRetweetMetrics: true,
  74. hideSeeNewTweets: false,
  75. hideShareTweetButton: false,
  76. hideSubscriptions: true,
  77. hideTotalTweetsMetrics: true,
  78. hideTweetAnalyticsLinks: false,
  79. hideTwitterAdsNav: true,
  80. hideTwitterBlueReplies: false,
  81. hideTwitterBlueUpsells: true,
  82. hideUnavailableQuoteTweets: true,
  83. hideVerifiedNotificationsTab: true,
  84. hideViews: true,
  85. hideWhoToFollowEtc: true,
  86. listRetweets: 'ignore',
  87. mutableQuoteTweets: true,
  88. mutedQuotes: [],
  89. quoteTweets: 'ignore',
  90. reducedInteractionMode: false,
  91. replaceLogo: true,
  92. retweets: 'separate',
  93. showBlueReplyFollowersCount: true,
  94. tweakQuoteTweetsPage: true,
  95. twitterBlueChecks: 'replace',
  96. uninvertFollowButtons: true,
  97. // Experiments
  98. // none currently
  99. // Desktop only
  100. fullWidthContent: false,
  101. fullWidthMedia: true,
  102. hideAccountSwitcher: false,
  103. hideExploreNav: true,
  104. hideExploreNavWithSidebar: true,
  105. hideMessagesDrawer: true,
  106. hideSidebarContent: true,
  107. navBaseFontSize: true,
  108. navDensity: 'default',
  109. showRelevantPeople: false,
  110. // Mobile only
  111. hideAppNags: true,
  112. hideMessagesBottomNavItem: false,
  113. }
  114. //#endregion
  115.  
  116. //#region Locales
  117. /**
  118. * @type {Record<string, import("./types").Locale>}
  119. */
  120. const locales = {
  121. 'ar-x-fm': {
  122. ADD_MUTED_WORD: 'اضافة كلمة مكتومة',
  123. HOME: 'الرئيسيّة',
  124. MUTE_THIS_CONVERSATION: 'كتم هذه المحادثه',
  125. POST_ALL: 'نشر الكل',
  126. QUOTE_TWEET: 'اقتباس التغريدة',
  127. QUOTE_TWEETS: 'تغريدات اقتباس',
  128. REPOST: 'إعادة النشر',
  129. REPOSTS: 'المنشورات المُعاد نشرها',
  130. RETWEET: 'إعادة التغريد',
  131. RETWEETED_BY: 'مُعاد تغريدها بواسطة',
  132. RETWEETS: 'إعادات التغريد',
  133. SHARED_TWEETS: 'التغريدات المشتركة',
  134. SHOW: 'إظهار',
  135. SHOW_MORE_REPLIES: 'عرض المزيد من الردود',
  136. TURN_OFF_RETWEETS: 'تعطيل إعادة التغريد',
  137. TURN_ON_RETWEETS: 'تفعيل إعادة التغريد',
  138. TWEET: 'غرّدي',
  139. TWEETS: 'التغريدات',
  140. TWEET_ALL: 'تغريد الكل',
  141. TWEET_YOUR_REPLY: 'التغريد بردك!',
  142. TWITTER: 'تويتر',
  143. },
  144. ar: {
  145. ADD_MUTED_WORD: 'اضافة كلمة مكتومة',
  146. HOME: 'الرئيسيّة',
  147. MUTE_THIS_CONVERSATION: 'كتم هذه المحادثه',
  148. POST_ALL: 'نشر الكل',
  149. QUOTE: 'اقتباس',
  150. QUOTE_TWEET: 'اقتباس التغريدة',
  151. QUOTE_TWEETS: 'تغريدات اقتباس',
  152. REPOST: 'إعادة النشر',
  153. REPOSTS: 'المنشورات المُعاد نشرها',
  154. RETWEET: 'إعادة التغريد',
  155. RETWEETED_BY: 'مُعاد تغريدها بواسطة',
  156. RETWEETS: 'إعادات التغريد',
  157. SHARED_TWEETS: 'التغريدات المشتركة',
  158. SHOW: 'إظهار',
  159. SHOW_MORE_REPLIES: 'عرض المزيد من الردود',
  160. TURN_OFF_RETWEETS: 'تعطيل إعادة التغريد',
  161. TURN_ON_RETWEETS: 'تفعيل إعادة التغريد',
  162. TWEET: 'تغريد',
  163. TWEETS: 'التغريدات',
  164. TWEET_ALL: 'تغريد الكل',
  165. TWEET_YOUR_REPLY: 'التغريد بردك!',
  166. },
  167. bg: {
  168. ADD_MUTED_WORD: 'Добавяне на заглушена дума',
  169. HOME: 'Начало',
  170. MUTE_THIS_CONVERSATION: 'Заглушаване на разговора',
  171. POST_ALL: 'Публикуване на всичко',
  172. QUOTE: 'Цитат',
  173. QUOTE_TWEET: 'Цитиране на туита',
  174. QUOTE_TWEETS: 'Туитове с цитат',
  175. REPOST: 'Препубликуване',
  176. REPOSTS: 'Препубликувания',
  177. RETWEET: 'Ретуитване',
  178. RETWEETED_BY: 'Ретуитнат от',
  179. RETWEETS: 'Ретуитове',
  180. SHARED_TWEETS: 'Споделени туитове',
  181. SHOW: 'Показване',
  182. SHOW_MORE_REPLIES: 'Показване на още отговори',
  183. TURN_OFF_RETWEETS: 'Изключване на ретуитовете',
  184. TURN_ON_RETWEETS: 'Включване на ретуитовете',
  185. TWEET: 'تغريد',
  186. TWEETS: 'Туитове',
  187. TWEET_ALL: 'تغريد الكل',
  188. TWEET_YOUR_REPLY: 'Отговори с туит!',
  189. },
  190. bn: {
  191. ADD_MUTED_WORD: 'নীরব করা শব্দ যোগ করুন',
  192. HOME: 'হোম',
  193. MUTE_THIS_CONVERSATION: 'এই কথা-বার্তা নীরব করুন',
  194. POST_ALL: 'সবকটি পোস্ট করুন',
  195. QUOTE: 'উদ্ধৃতি',
  196. QUOTE_TWEET: 'টুইট উদ্ধৃত করুন',
  197. QUOTE_TWEETS: 'টুইট উদ্ধৃতিগুলো',
  198. REPOST: 'রিপোস্ট',
  199. REPOSTS: 'রিপোস্ট',
  200. RETWEET: 'পুনঃটুইট',
  201. RETWEETED_BY: 'পুনঃ টুইট করেছেন',
  202. RETWEETS: 'পুনঃটুইটগুলো',
  203. SHARED_TWEETS: 'ভাগ করা টুইটগুলি',
  204. SHOW: 'দেখান',
  205. SHOW_MORE_REPLIES: 'আরও উত্তর দেখান',
  206. TURN_OFF_RETWEETS: 'পুনঃ টুইটগুলি বন্ধ করুন',
  207. TURN_ON_RETWEETS: 'পুনঃ টুইটগুলি চালু করুন',
  208. TWEET: 'টুইট',
  209. TWEETS: 'টুইটগুলি',
  210. TWEET_ALL: 'সব টুইট করুন',
  211. TWEET_YOUR_REPLY: 'আপনার উত্তর টুইট করুন!',
  212. TWITTER: 'টুইটার',
  213. },
  214. ca: {
  215. ADD_MUTED_WORD: 'Afegeix una paraula silenciada',
  216. HOME: 'Inici',
  217. MUTE_THIS_CONVERSATION: 'Silencia la conversa',
  218. POST_ALL: 'Publica-ho tot',
  219. QUOTE: 'Cita',
  220. QUOTE_TWEET: 'Cita el tuit',
  221. QUOTE_TWEETS: 'Tuits amb cita',
  222. REPOST: 'Republicació',
  223. REPOSTS: 'Republicacions',
  224. RETWEET: 'Retuit',
  225. RETWEETED_BY: 'Retuitat per',
  226. RETWEETS: 'Retuits',
  227. SHARED_TWEETS: 'Tuits compartits',
  228. SHOW: 'Mostra',
  229. SHOW_MORE_REPLIES: 'Mostra més respostes',
  230. TURN_OFF_RETWEETS: 'Desactiva els retuits',
  231. TURN_ON_RETWEETS: 'Activa els retuits',
  232. TWEET: 'Tuita',
  233. TWEETS: 'Tuits',
  234. TWEET_ALL: 'Tuita-ho tot',
  235. TWEET_YOUR_REPLY: 'Tuita la teva resposta',
  236. },
  237. cs: {
  238. ADD_MUTED_WORD: 'Přidat slovo na seznam skrytých slov',
  239. HOME: 'Hlavní stránka',
  240. MUTE_THIS_CONVERSATION: 'Skrýt tuto konverzaci',
  241. POST_ALL: 'Postovat vše',
  242. QUOTE: 'Citace',
  243. QUOTE_TWEET: 'Citovat Tweet',
  244. QUOTE_TWEETS: 'Tweety s citací',
  245. REPOSTS: 'Reposty',
  246. RETWEET: 'Retweetnout',
  247. RETWEETED_BY: 'Retweetnuto uživateli',
  248. RETWEETS: 'Retweety',
  249. SHARED_TWEETS: 'Sdílené tweety',
  250. SHOW: 'Zobrazit',
  251. SHOW_MORE_REPLIES: 'Zobrazit další odpovědi',
  252. TURN_OFF_RETWEETS: 'Vypnout retweety',
  253. TURN_ON_RETWEETS: 'Zapnout retweety',
  254. TWEET: 'Tweetovat',
  255. TWEETS: 'Tweety',
  256. TWEET_ALL: 'Tweetnout vše',
  257. TWEET_YOUR_REPLY: 'Tweetujte svou odpověď!',
  258. },
  259. da: {
  260. ADD_MUTED_WORD: 'Tilføj skjult ord',
  261. HOME: 'Forside',
  262. MUTE_THIS_CONVERSATION: 'Skjul denne samtale',
  263. POST_ALL: 'Post alle',
  264. QUOTE: 'Citat',
  265. QUOTE_TWEET: 'Citér Tweet',
  266. QUOTE_TWEETS: 'Citat-Tweets',
  267. RETWEETED_BY: 'Retweetet af',
  268. SHARED_TWEETS: 'Delte tweets',
  269. SHOW: 'Vis',
  270. SHOW_MORE_REPLIES: 'Vis flere svar',
  271. TURN_OFF_RETWEETS: 'Slå Retweets fra',
  272. TURN_ON_RETWEETS: 'Slå Retweets til',
  273. TWEET_ALL: 'Tweet alt',
  274. TWEET_YOUR_REPLY: 'Tweet dit svar!',
  275. },
  276. de: {
  277. ADD_MUTED_WORD: 'Stummgeschaltetes Wort hinzufügen',
  278. HOME: 'Startseite',
  279. MUTE_THIS_CONVERSATION: 'Diese Konversation stummschalten',
  280. POST_ALL: 'Alle posten',
  281. QUOTE: 'Zitat',
  282. QUOTE_TWEET: 'Tweet zitieren',
  283. QUOTE_TWEETS: 'Zitierte Tweets',
  284. REPOST: 'Reposten',
  285. RETWEET: 'Retweeten',
  286. RETWEETED_BY: 'Retweetet von',
  287. SHARED_TWEETS: 'Geteilte Tweets',
  288. SHOW: 'Anzeigen',
  289. SHOW_MORE_REPLIES: 'Mehr Antworten anzeigen',
  290. TURN_OFF_RETWEETS: 'Retweets ausschalten',
  291. TURN_ON_RETWEETS: 'Retweets einschalten',
  292. TWEET: 'Twittern',
  293. TWEET_ALL: 'Alle twittern',
  294. TWEET_YOUR_REPLY: 'Twittere deine Antwort!',
  295. },
  296. el: {
  297. ADD_MUTED_WORD: 'Προσθήκη λέξης σε σίγαση',
  298. HOME: 'Αρχική σελίδα',
  299. MUTE_THIS_CONVERSATION: 'Σίγαση αυτής της συζήτησης',
  300. POST_ALL: 'Δημοσίευση όλων',
  301. QUOTE: 'Παράθεση',
  302. QUOTE_TWEET: 'Παράθεση Tweet',
  303. QUOTE_TWEETS: 'Tweet με παράθεση',
  304. REPOST: 'Αναδημοσίευση',
  305. REPOSTS: 'Αναδημοσιεύσεις',
  306. RETWEETED_BY: 'Έγινε Retweet από',
  307. RETWEETS: 'Retweet',
  308. SHARED_TWEETS: 'Κοινόχρηστα Tweets',
  309. SHOW: 'Εμφάνιση',
  310. SHOW_MORE_REPLIES: 'Εμφάνιση περισσότερων απαντήσεων',
  311. TURN_OFF_RETWEETS: 'Απενεργοποίηση των Retweet',
  312. TURN_ON_RETWEETS: 'Ενεργοποίηση των Retweet',
  313. TWEETS: 'Tweet',
  314. TWEET_ALL: 'Δημοσίευση όλων ως Tweet',
  315. TWEET_YOUR_REPLY: 'Στείλτε την απάντησή σας!',
  316. },
  317. en: {
  318. ADD_MUTED_WORD: 'Add muted word',
  319. HOME: 'Home',
  320. MUTE_THIS_CONVERSATION: 'Mute this conversation',
  321. POST_ALL: 'Post all',
  322. QUOTE: 'Quote',
  323. QUOTE_TWEET: 'Quote Tweet',
  324. QUOTE_TWEETS: 'Quote Tweets',
  325. REPOST: 'Repost',
  326. REPOSTS: 'Reposts',
  327. RETWEET: 'Retweet',
  328. RETWEETED_BY: 'Retweeted by',
  329. RETWEETS: 'Retweets',
  330. SHARED_TWEETS: 'Shared Tweets',
  331. SHOW: 'Show',
  332. SHOW_MORE_REPLIES: 'Show more replies',
  333. TURN_OFF_RETWEETS: 'Turn off Retweets',
  334. TURN_ON_RETWEETS: 'Turn on Retweets',
  335. TWEET: 'Tweet',
  336. TWEETS: 'Tweets',
  337. TWEET_ALL: 'Tweet all',
  338. TWEET_YOUR_REPLY: 'Tweet your reply!',
  339. TWITTER: 'Twitter',
  340. },
  341. es: {
  342. ADD_MUTED_WORD: 'Añadir palabra silenciada',
  343. HOME: 'Inicio',
  344. MUTE_THIS_CONVERSATION: 'Silenciar esta conversación',
  345. POST_ALL: 'Postear todo',
  346. QUOTE: 'Cita',
  347. QUOTE_TWEET: 'Citar Tweet',
  348. QUOTE_TWEETS: 'Tweets citados',
  349. REPOST: 'Repostear',
  350. RETWEET: 'Retwittear',
  351. RETWEETED_BY: 'Retwitteado por',
  352. SHARED_TWEETS: 'Tweets compartidos',
  353. SHOW: 'Mostrar',
  354. SHOW_MORE_REPLIES: 'Mostrar más respuestas',
  355. TURN_OFF_RETWEETS: 'Desactivar Retweets',
  356. TURN_ON_RETWEETS: 'Activar Retweets',
  357. TWEET: 'Twittear',
  358. TWEET_ALL: 'Twittear todo',
  359. TWEET_YOUR_REPLY: '¡Twittea tu respuesta!',
  360. },
  361. eu: {
  362. ADD_MUTED_WORD: 'Gehitu isilarazitako hitza',
  363. HOME: 'Hasiera',
  364. MUTE_THIS_CONVERSATION: 'Isilarazi elkarrizketa hau',
  365. QUOTE: 'Aipamena',
  366. QUOTE_TWEET: 'Txioa apaitu',
  367. QUOTE_TWEETS: 'Aipatu txioak',
  368. RETWEET: 'Bertxiotu',
  369. RETWEETED_BY: 'Bertxiotua:',
  370. RETWEETS: 'Bertxioak',
  371. SHARED_TWEETS: 'Partekatutako',
  372. SHOW: 'Erakutsi',
  373. SHOW_MORE_REPLIES: 'Erakutsi erantzun gehiago',
  374. TURN_OFF_RETWEETS: 'Desaktibatu birtxioak',
  375. TURN_ON_RETWEETS: 'Aktibatu birtxioak',
  376. TWEET: 'Txio',
  377. TWEETS: 'Txioak',
  378. TWEET_ALL: 'Txiotu guztiak',
  379. TWEET_YOUR_REPLY: 'Tweet your reply!',
  380. },
  381. fa: {
  382. ADD_MUTED_WORD: 'افزودن واژه خموش‌سازی شده',
  383. HOME: 'خانه',
  384. MUTE_THIS_CONVERSATION: 'خموش‌سازی این گفتگو',
  385. POST_ALL: 'پست کردن همه',
  386. QUOTE: 'نقل‌قول',
  387. QUOTE_TWEET: 'نقل‌توییت',
  388. QUOTE_TWEETS: 'نقل‌توییت‌ها',
  389. REPOST: 'بازپست',
  390. REPOSTS: 'بازپست‌ها',
  391. RETWEET: 'بازتوییت',
  392. RETWEETED_BY: 'بازتوییت‌ شد توسط',
  393. RETWEETS: 'بازتوییت‌ها',
  394. SHARED_TWEETS: 'توییتهای مشترک',
  395. SHOW: 'نمایش',
  396. SHOW_MORE_REPLIES: 'نمایش پاسخ‌های بیشتر',
  397. TURN_OFF_RETWEETS: 'غیرفعال‌سازی بازتوییت‌ها',
  398. TURN_ON_RETWEETS: 'فعال سازی بازتوییت‌ها',
  399. TWEET: 'توییت',
  400. TWEETS: 'توييت‌ها',
  401. TWEET_ALL: 'توییت به همه',
  402. TWEET_YOUR_REPLY: 'پاسختان را توییت کنید!',
  403. TWITTER: 'توییتر',
  404. },
  405. fi: {
  406. ADD_MUTED_WORD: 'Lisää hiljennetty sana',
  407. HOME: 'Etusivu',
  408. MUTE_THIS_CONVERSATION: 'Hiljennä tämä keskustelu',
  409. POST_ALL: 'Julkaise kaikki',
  410. QUOTE: 'Lainaa',
  411. QUOTE_TWEET: 'Twiitin lainaus',
  412. QUOTE_TWEETS: 'Twiitin lainaukset',
  413. REPOST: 'Uudelleenjulkaise',
  414. REPOSTS: 'Uudelleenjulkaisut',
  415. RETWEET: 'Uudelleentwiittaa',
  416. RETWEETED_BY: 'Uudelleentwiitannut',
  417. RETWEETS: 'Uudelleentwiittaukset',
  418. SHARED_TWEETS: 'Jaetut twiitit',
  419. SHOW: 'Näytä',
  420. SHOW_MORE_REPLIES: 'Näytä lisää vastauksia',
  421. TURN_OFF_RETWEETS: 'Poista uudelleentwiittaukset käytöstä',
  422. TURN_ON_RETWEETS: 'Ota uudelleentwiittaukset käyttöön',
  423. TWEET: 'Twiittaa',
  424. TWEETS: 'Twiitit',
  425. TWEET_ALL: 'Twiittaa kaikki',
  426. TWEET_YOUR_REPLY: 'Twiittaa vastauksesi',
  427. },
  428. fil: {
  429. ADD_MUTED_WORD: 'Idagdag ang naka-mute na salita',
  430. MUTE_THIS_CONVERSATION: 'I-mute ang usapang ito',
  431. POST_ALL: 'I-post lahat',
  432. QUOTE_TWEET: 'Quote na Tweet',
  433. QUOTE_TWEETS: 'Mga Quote na Tweet',
  434. REPOST: 'I-repost',
  435. REPOSTS: '(na) Repost',
  436. RETWEET: 'I-retweet',
  437. RETWEETED_BY: 'Ni-retweet ni',
  438. RETWEETS: 'Mga Retweet',
  439. SHARED_TWEETS: 'Mga Ibinahaging Tweet',
  440. SHOW: 'Ipakita',
  441. SHOW_MORE_REPLIES: 'Magpakita pa ng mga sagot',
  442. TURN_OFF_RETWEETS: 'I-off ang Retweets',
  443. TURN_ON_RETWEETS: 'I-on ang Retweets',
  444. TWEET: 'Mag-tweet',
  445. TWEETS: 'Mga Tweet',
  446. TWEET_ALL: 'I-tweet lahat',
  447. TWEET_YOUR_REPLY: 'I-Tweet ang sagot mo!',
  448. },
  449. fr: {
  450. ADD_MUTED_WORD: 'Ajouter un mot masqué',
  451. HOME: 'Accueil',
  452. MUTE_THIS_CONVERSATION: 'Masquer cette conversation',
  453. POST_ALL: 'Tout poster',
  454. QUOTE: 'Citation',
  455. QUOTE_TWEET: 'Citer le Tweet',
  456. QUOTE_TWEETS: 'Tweets cités',
  457. RETWEET: 'Retweeter',
  458. RETWEETED_BY: 'Retweeté par',
  459. SHARED_TWEETS: 'Tweets partagés',
  460. SHOW: 'Afficher',
  461. SHOW_MORE_REPLIES: 'Voir plus de réponses',
  462. TURN_OFF_RETWEETS: 'Désactiver les Retweets',
  463. TURN_ON_RETWEETS: 'Activer les Retweets',
  464. TWEET: 'Tweeter',
  465. TWEET_ALL: 'Tout tweeter',
  466. TWEET_YOUR_REPLY: 'Tweetez votre réponse !',
  467. },
  468. ga: {
  469. ADD_MUTED_WORD: 'Cuir focal balbhaithe leis',
  470. HOME: 'Baile',
  471. MUTE_THIS_CONVERSATION: 'Balbhaigh an comhrá seo',
  472. QUOTE: 'Sliocht',
  473. QUOTE_TWEET: 'Cuir Ráiteas Leis',
  474. QUOTE_TWEETS: 'Luaigh Tvuíteanna',
  475. RETWEET: 'Atweetáil',
  476. RETWEETED_BY: 'Atweetáilte ag',
  477. RETWEETS: 'Atweetanna',
  478. SHARED_TWEETS: 'Tweetanna Roinnte',
  479. SHOW: 'Taispeáin',
  480. SHOW_MORE_REPLIES: 'Taispeáin tuilleadh freagraí',
  481. TURN_OFF_RETWEETS: 'Cas as Atweetanna',
  482. TURN_ON_RETWEETS: 'Cas Atweetanna air',
  483. TWEETS: 'Tweetanna',
  484. TWEET_ALL: 'Tweetáil gach rud',
  485. TWEET_YOUR_REPLY: 'Tweet your reply!',
  486. },
  487. gl: {
  488. ADD_MUTED_WORD: 'Engadir palabra silenciada',
  489. HOME: 'Inicio',
  490. MUTE_THIS_CONVERSATION: 'Silenciar esta conversa',
  491. QUOTE: 'Cita',
  492. QUOTE_TWEET: 'Citar chío',
  493. QUOTE_TWEETS: 'Chíos citados',
  494. RETWEET: 'Rechouchiar',
  495. RETWEETED_BY: 'Rechouchiado por',
  496. RETWEETS: 'Rechouchíos',
  497. SHARED_TWEETS: 'Chíos compartidos',
  498. SHOW: 'Amosar',
  499. SHOW_MORE_REPLIES: 'Amosar máis respostas',
  500. TURN_OFF_RETWEETS: 'Desactivar os rechouchíos',
  501. TURN_ON_RETWEETS: 'Activar os rechouchíos',
  502. TWEET: 'Chío',
  503. TWEETS: 'Chíos',
  504. TWEET_ALL: 'Chiar todo',
  505. TWEET_YOUR_REPLY: 'Tweet your reply!',
  506. },
  507. gu: {
  508. ADD_MUTED_WORD: 'જોડાણ અટકાવેલો શબ્દ ઉમેરો',
  509. HOME: 'હોમ',
  510. MUTE_THIS_CONVERSATION: 'આ વાર્તાલાપનું જોડાણ અટકાવો',
  511. POST_ALL: 'બધા પોસ્ટ કરો',
  512. QUOTE: 'અવતરણ',
  513. QUOTE_TWEET: 'અવતરણની સાથે ટ્વીટ કરો',
  514. QUOTE_TWEETS: 'અવતરણની સાથે ટ્વીટ્સ',
  515. REPOST: 'રીપોસ્ટ કરો',
  516. REPOSTS: 'ફરીથી કરવામાં આવેલી પોસ્ટ',
  517. RETWEET: 'પુનટ્વીટ',
  518. RETWEETED_BY: 'આમની દ્વારા પુનટ્વીટ કરવામાં આવી',
  519. RETWEETS: 'પુનટ્વીટ્સ',
  520. SHARED_TWEETS: 'શેર કરેલી ટ્વીટ્સ',
  521. SHOW: 'બતાવો',
  522. SHOW_MORE_REPLIES: 'વધુ પ્રત્યુતરો દર્શાવો',
  523. TURN_OFF_RETWEETS: 'પુનટ્વીટ્સ બંધ કરો',
  524. TURN_ON_RETWEETS: 'પુનટ્વીટ્સ ચાલુ કરો',
  525. TWEET: 'ટ્વીટ',
  526. TWEETS: 'ટ્વીટ્સ',
  527. TWEET_ALL: 'બધાને ટ્વીટ કરો',
  528. TWEET_YOUR_REPLY: 'તમારા પ્રત્યુત્તરને ટ્વીટ કરો!',
  529. },
  530. he: {
  531. ADD_MUTED_WORD: 'הוסף מילה מושתקת',
  532. HOME: 'דף הבית',
  533. MUTE_THIS_CONVERSATION: 'להשתיק את השיחה הזאת',
  534. POST_ALL: 'פרסום הכל',
  535. QUOTE: 'ציטוט',
  536. QUOTE_TWEET: 'ציטוט ציוץ',
  537. QUOTE_TWEETS: 'ציוצי ציטוט',
  538. REPOST: 'דוחות',
  539. REPOSTS: 'פרסומים מחדש',
  540. RETWEET: 'צייץ מחדש',
  541. RETWEETED_BY: 'צויץ מחדש על־ידי',
  542. RETWEETS: 'ציוצים מחדש',
  543. SHARED_TWEETS: 'ציוצים משותפים',
  544. SHOW: 'הצג',
  545. SHOW_MORE_REPLIES: 'הצג תשובות נוספות',
  546. TURN_OFF_RETWEETS: 'כבה ציוצים מחדש',
  547. TURN_ON_RETWEETS: 'הפעל ציוצים מחדש',
  548. TWEET: 'צייץ',
  549. TWEETS: 'ציוצים',
  550. TWEET_ALL: 'צייץ הכול',
  551. TWEET_YOUR_REPLY: 'צייץ את התשובה!',
  552. TWITTER: 'טוויטר',
  553. },
  554. hi: {
  555. ADD_MUTED_WORD: 'म्यूट किया गया शब्द जोड़ें',
  556. HOME: 'होम',
  557. MUTE_THIS_CONVERSATION: 'इस बातचीत को म्यूट करें',
  558. POST_ALL: 'सभी पोस्ट करें',
  559. QUOTE: 'कोट',
  560. QUOTE_TWEET: 'ट्वीट क्वोट करें',
  561. QUOTE_TWEETS: 'कोट ट्वीट्स',
  562. REPOST: 'रीपोस्ट',
  563. REPOSTS: 'रीपोस्ट्स',
  564. RETWEET: 'रीट्वीट करें',
  565. RETWEETED_BY: 'इनके द्वारा रीट्वीट किया गया',
  566. RETWEETS: 'रीट्वीट्स',
  567. SHARED_TWEETS: 'साझा किए गए ट्वीट',
  568. SHOW: 'दिखाएं',
  569. SHOW_MORE_REPLIES: 'और अधिक जवाब दिखाएँ',
  570. TURN_OFF_RETWEETS: 'रीट्वीट बंद करें',
  571. TURN_ON_RETWEETS: 'रीट्वीट चालू करें',
  572. TWEET: 'ट्वीट करें',
  573. TWEETS: 'ट्वीट',
  574. TWEET_ALL: 'सभी ट्वीट करें',
  575. TWEET_YOUR_REPLY: 'अपना जवाब ट्वीट करें!',
  576. },
  577. hr: {
  578. ADD_MUTED_WORD: 'Dodaj onemogućenu riječ',
  579. HOME: 'Naslovnica',
  580. MUTE_THIS_CONVERSATION: 'Isključi zvuk ovog razgovora',
  581. POST_ALL: 'Objavi sve',
  582. QUOTE: 'Citat',
  583. QUOTE_TWEET: 'Citiraj Tweet',
  584. QUOTE_TWEETS: 'Citirani tweetovi',
  585. REPOST: 'Proslijedi objavu',
  586. REPOSTS: 'Proslijeđene objave',
  587. RETWEET: 'Proslijedi tweet',
  588. RETWEETED_BY: 'Korisnici koji su proslijedili Tweet',
  589. RETWEETS: 'Proslijeđeni tweetovi',
  590. SHARED_TWEETS: 'Dijeljeni tweetovi',
  591. SHOW: 'Prikaži',
  592. SHOW_MORE_REPLIES: 'Prikaži još odgovora',
  593. TURN_OFF_RETWEETS: 'Isključi proslijeđene tweetove',
  594. TURN_ON_RETWEETS: 'Uključi proslijeđene tweetove',
  595. TWEETS: 'Tweetovi',
  596. TWEET_ALL: 'Tweetaj sve',
  597. TWEET_YOUR_REPLY: 'Pošaljite Tweet s odgovorom!',
  598. },
  599. hu: {
  600. ADD_MUTED_WORD: 'Elnémított szó hozzáadása',
  601. HOME: 'Kezdőlap',
  602. MUTE_THIS_CONVERSATION: 'Beszélgetés némítása',
  603. POST_ALL: 'Az összes közzététele',
  604. QUOTE: 'Idézés',
  605. QUOTE_TWEET: 'Tweet idézése',
  606. QUOTE_TWEETS: 'Tweet-idézések',
  607. REPOST: 'Újraposztolás',
  608. REPOSTS: 'Újraposztolások',
  609. RETWEETED_BY: 'Retweetelte',
  610. RETWEETS: 'Retweetek',
  611. SHARED_TWEETS: 'Megosztott tweetek',
  612. SHOW: 'Megjelenítés',
  613. SHOW_MORE_REPLIES: 'Több válasz megjelenítése',
  614. TURN_OFF_RETWEETS: 'Retweetek kikapcsolása',
  615. TURN_ON_RETWEETS: 'Retweetek bekapcsolása',
  616. TWEET: 'Tweetelj',
  617. TWEETS: 'Tweetek',
  618. TWEET_ALL: 'Tweet küldése mindenkinek',
  619. TWEET_YOUR_REPLY: 'Tweeteld válaszodat',
  620. },
  621. id: {
  622. ADD_MUTED_WORD: 'Tambahkan kata kunci yang dibisukan',
  623. HOME: 'Beranda',
  624. MUTE_THIS_CONVERSATION: 'Bisukan percakapan ini',
  625. POST_ALL: 'Posting semua',
  626. QUOTE: 'Kutipan',
  627. QUOTE_TWEET: 'Kutip Tweet',
  628. QUOTE_TWEETS: 'Tweet Kutipan',
  629. REPOST: 'Posting ulang',
  630. REPOSTS: 'Posting ulang',
  631. RETWEETED_BY: 'Di-retweet oleh',
  632. RETWEETS: 'Retweet',
  633. SHARED_TWEETS: 'Tweet yang Dibagikan',
  634. SHOW: 'Tampilkan',
  635. SHOW_MORE_REPLIES: 'Tampilkan balasan lainnya',
  636. TURN_OFF_RETWEETS: 'Matikan Retweet',
  637. TURN_ON_RETWEETS: 'Nyalakan Retweet',
  638. TWEETS: 'Tweet',
  639. TWEET_ALL: 'Tweet semua',
  640. TWEET_YOUR_REPLY: 'Tweet balasan Anda!',
  641. },
  642. it: {
  643. ADD_MUTED_WORD: 'Aggiungi parola o frase silenziata',
  644. MUTE_THIS_CONVERSATION: 'Silenzia questa conversazione',
  645. POST_ALL: 'Pubblica tutto',
  646. QUOTE: 'Citazione',
  647. QUOTE_TWEET: 'Cita Tweet',
  648. QUOTE_TWEETS: 'Tweet di citazione',
  649. REPOSTS: 'Repost',
  650. RETWEET: 'Ritwitta',
  651. RETWEETED_BY: 'Ritwittato da',
  652. RETWEETS: 'Retweet',
  653. SHARED_TWEETS: 'Tweet condivisi',
  654. SHOW: 'Mostra',
  655. SHOW_MORE_REPLIES: 'Mostra altre risposte',
  656. TURN_OFF_RETWEETS: 'Disattiva Retweet',
  657. TURN_ON_RETWEETS: 'Attiva Retweet',
  658. TWEET: 'Twitta',
  659. TWEETS: 'Tweet',
  660. TWEET_ALL: 'Twitta tutto',
  661. TWEET_YOUR_REPLY: 'Twitta la tua risposta.',
  662. },
  663. ja: {
  664. ADD_MUTED_WORD: 'ミュートするキーワードを追加',
  665. HOME: 'ホーム',
  666. MUTE_THIS_CONVERSATION: 'この会話をミュート',
  667. POST_ALL: 'すべてポスト',
  668. QUOTE: '引用',
  669. QUOTE_TWEET: '引用ツイート',
  670. QUOTE_TWEETS: '引用ツイート',
  671. REPOST: 'リポスト',
  672. REPOSTS: 'リポスト',
  673. RETWEET: 'リツイート',
  674. RETWEETED_BY: 'リツイートしたユーザー',
  675. RETWEETS: 'リツイート',
  676. SHARED_TWEETS: '共有ツイート',
  677. SHOW: '表示',
  678. SHOW_MORE_REPLIES: '返信をさらに表示',
  679. TURN_OFF_RETWEETS: 'リツイートをオフにする',
  680. TURN_ON_RETWEETS: 'リツイートをオンにする',
  681. TWEET: 'ツイートする',
  682. TWEETS: 'ツイート',
  683. TWEET_ALL: 'すべてツイート',
  684. TWEET_YOUR_REPLY: '返信をツイートしましょう。',
  685. },
  686. kn: {
  687. ADD_MUTED_WORD: 'ಸದ್ದಡಗಿಸಿದ ಪದವನ್ನು ಸೇರಿಸಿ',
  688. HOME: 'ಹೋಮ್',
  689. MUTE_THIS_CONVERSATION: 'ಈ ಸಂವಾದವನ್ನು ಸದ್ದಡಗಿಸಿ',
  690. POST_ALL: 'ಎಲ್ಲವನ್ನೂ ಪೋಸ್ಟ್ ಮಾಡಿ',
  691. QUOTE: 'ಕೋಟ್‌',
  692. QUOTE_TWEET: 'ಟ್ವೀಟ್ ಕೋಟ್ ಮಾಡಿ',
  693. QUOTE_TWEETS: 'ಕೋಟ್ ಟ್ವೀಟ್‌ಗಳು',
  694. REPOST: 'ಮರುಪೋಸ್ಟ್ ಮಾಡಿ',
  695. REPOSTS: 'ಮರುಪೋಸ್ಟ್‌ಗಳು',
  696. RETWEET: 'ಮರುಟ್ವೀಟಿಸಿ',
  697. RETWEETED_BY: 'ಮರುಟ್ವೀಟಿಸಿದವರು',
  698. RETWEETS: 'ಮರುಟ್ವೀಟ್‌ಗಳು',
  699. SHARED_TWEETS: 'ಹಂಚಿದ ಟ್ವೀಟ್‌ಗಳು',
  700. SHOW: 'ತೋರಿಸಿ',
  701. SHOW_MORE_REPLIES: 'ಇನ್ನಷ್ಟು ಪ್ರತಿಕ್ರಿಯೆಗಳನ್ನು ತೋರಿಸಿ',
  702. TURN_OFF_RETWEETS: 'ಮರುಟ್ವೀಟ್‌ಗಳನ್ನು ಆಫ್ ಮಾಡಿ',
  703. TURN_ON_RETWEETS: 'ಮರುಟ್ವೀಟ್‌ಗಳನ್ನು ಆನ್ ಮಾಡಿ',
  704. TWEET: 'ಟ್ವೀಟ್',
  705. TWEETS: 'ಟ್ವೀಟ್‌ಗಳು',
  706. TWEET_ALL: 'ಎಲ್ಲಾ ಟ್ವೀಟ್ ಮಾಡಿ',
  707. TWEET_YOUR_REPLY: 'ನಿಮ್ಮ ಪ್ರತಿಕ್ರಿಯೆಯನ್ನು ಟ್ವೀಟ್ ಮಾಡಿ!',
  708. },
  709. ko: {
  710. ADD_MUTED_WORD: '뮤트할 단어 추가하기',
  711. HOME: '홈',
  712. MUTE_THIS_CONVERSATION: '이 대화 뮤트하기',
  713. POST_ALL: '모두 게시하기',
  714. QUOTE: '인용',
  715. QUOTE_TWEET: '트윗 인용하기',
  716. QUOTE_TWEETS: '트윗 인용하기',
  717. REPOST: '재게시',
  718. REPOSTS: '재게시',
  719. RETWEET: '리트윗',
  720. RETWEETED_BY: '리트윗함',
  721. RETWEETS: '리트윗',
  722. SHARED_TWEETS: '공유 트윗',
  723. SHOW: '표시',
  724. SHOW_MORE_REPLIES: '더 많은 답글 보기',
  725. TURN_OFF_RETWEETS: '리트윗 끄기',
  726. TURN_ON_RETWEETS: '리트윗 켜기',
  727. TWEET: '트윗',
  728. TWEETS: '트윗',
  729. TWEET_ALL: '모두 트윗하기',
  730. TWEET_YOUR_REPLY: '내 답글을 트윗하세요',
  731. TWITTER: '트위터',
  732. },
  733. mr: {
  734. ADD_MUTED_WORD: 'म्यूट केलेले शब्द सामील करा',
  735. HOME: 'होम',
  736. MUTE_THIS_CONVERSATION: 'ही चर्चा म्यूट करा',
  737. POST_ALL: 'सर्व पोस्ट करा',
  738. QUOTE: 'भाष्य',
  739. QUOTE_TWEET: 'ट्विट वर भाष्य करा',
  740. QUOTE_TWEETS: 'भाष्य ट्विट्स',
  741. REPOST: 'पुन्हा पोस्ट करा',
  742. REPOSTS: 'रिपोस्ट',
  743. RETWEET: 'पुन्हा ट्विट',
  744. RETWEETED_BY: 'यांनी पुन्हा ट्विट केले',
  745. RETWEETS: 'पुनर्ट्विट्स',
  746. SHARED_TWEETS: 'सामायिक ट्विट',
  747. SHOW: 'दाखवा',
  748. SHOW_MORE_REPLIES: 'अधिक प्रत्युत्तरे दाखवा',
  749. TURN_OFF_RETWEETS: 'पुनर्ट्विट्स बंद करा',
  750. TURN_ON_RETWEETS: 'पुनर्ट्विट्स चालू करा',
  751. TWEET: 'ट्विट',
  752. TWEETS: 'ट्विट्स',
  753. TWEET_ALL: 'सर्व ट्विट करा',
  754. TWEET_YOUR_REPLY: 'आपल्या प्रत्युत्तरावर ट्विट करा!',
  755. },
  756. ms: {
  757. ADD_MUTED_WORD: 'Tambahkan perkataan yang disenyapkan',
  758. HOME: 'Laman Utama',
  759. MUTE_THIS_CONVERSATION: 'Senyapkan perbualan ini',
  760. POST_ALL: 'Siarkan semua',
  761. QUOTE: 'Petikan',
  762. QUOTE_TWEET: 'Petik Tweet',
  763. QUOTE_TWEETS: 'Tweet Petikan',
  764. REPOST: 'Siaran semula',
  765. REPOSTS: 'Siaran semula',
  766. RETWEET: 'Tweet semula',
  767. RETWEETED_BY: 'Ditweet semula oleh',
  768. RETWEETS: 'Tweet semula',
  769. SHARED_TWEETS: 'Tweet Berkongsi',
  770. SHOW: 'Tunjukkan',
  771. SHOW_MORE_REPLIES: 'Tunjukkan lagi balasan',
  772. TURN_OFF_RETWEETS: 'Matikan Tweet semula',
  773. TURN_ON_RETWEETS: 'Hidupkan Tweet semula',
  774. TWEETS: 'Tweet',
  775. TWEET_ALL: 'Tweet semua',
  776. TWEET_YOUR_REPLY: 'Tweet balasan anda!',
  777. },
  778. nb: {
  779. ADD_MUTED_WORD: 'Skjul nytt ord',
  780. HOME: 'Hjem',
  781. MUTE_THIS_CONVERSATION: 'Skjul denne samtalen',
  782. POST_ALL: 'Publiser alle',
  783. QUOTE: 'Sitat',
  784. QUOTE_TWEET: 'Sitat-Tweet',
  785. QUOTE_TWEETS: 'Sitat-Tweets',
  786. REPOST: 'Republiser',
  787. REPOSTS: 'Republiseringer',
  788. RETWEETED_BY: 'Retweetet av',
  789. SHARED_TWEETS: 'Delte tweets',
  790. SHOW: 'Vis',
  791. SHOW_MORE_REPLIES: 'Vis flere svar',
  792. TURN_OFF_RETWEETS: 'Slå av Retweets',
  793. TURN_ON_RETWEETS: 'Slå på Retweets',
  794. TWEET_ALL: 'Tweet alle',
  795. TWEET_YOUR_REPLY: 'Tweet svaret ditt!',
  796. },
  797. nl: {
  798. ADD_MUTED_WORD: 'Genegeerd woord toevoegen',
  799. HOME: 'Startpagina',
  800. MUTE_THIS_CONVERSATION: 'Dit gesprek negeren',
  801. POST_ALL: 'Alles plaatsen',
  802. QUOTE: 'Geciteerd',
  803. QUOTE_TWEET: 'Citeer Tweet',
  804. QUOTE_TWEETS: 'Geciteerde Tweets',
  805. RETWEET: 'Retweeten',
  806. RETWEETED_BY: 'Geretweet door',
  807. SHARED_TWEETS: 'Gedeelde Tweets',
  808. SHOW: 'Weergeven',
  809. SHOW_MORE_REPLIES: 'Meer antwoorden tonen',
  810. TURN_OFF_RETWEETS: 'Retweets uitschakelen',
  811. TURN_ON_RETWEETS: 'Retweets inschakelen',
  812. TWEET: 'Tweeten',
  813. TWEET_ALL: 'Alles tweeten',
  814. TWEET_YOUR_REPLY: 'Tweet je antwoord!',
  815. },
  816. pl: {
  817. ADD_MUTED_WORD: 'Dodaj wyciszone słowo',
  818. HOME: 'Główna',
  819. MUTE_THIS_CONVERSATION: 'Wycisz tę rozmowę',
  820. POST_ALL: 'Opublikuj wszystko',
  821. QUOTE: 'Cytuj',
  822. QUOTE_TWEET: 'Cytuj Tweeta',
  823. QUOTE_TWEETS: 'Cytaty z Tweeta',
  824. REPOST: 'Podaj dalej wpis',
  825. REPOSTS: 'Wpisy podane dalej',
  826. RETWEET: 'Podaj dalej',
  827. RETWEETED_BY: 'Podane dalej przez',
  828. RETWEETS: 'Tweety podane dalej',
  829. SHARED_TWEETS: 'Udostępnione Tweety',
  830. SHOW: 'Pokaż',
  831. SHOW_MORE_REPLIES: 'Pokaż więcej odpowiedzi',
  832. TURN_OFF_RETWEETS: 'Wyłącz Tweety podane dalej',
  833. TURN_ON_RETWEETS: 'Włącz Tweety podane dalej',
  834. TWEETS: 'Tweety',
  835. TWEET_ALL: 'Tweetnij wszystko',
  836. TWEET_YOUR_REPLY: 'Wyślij Tweeta z odpowiedzią!',
  837. },
  838. pt: {
  839. ADD_MUTED_WORD: 'Adicionar palavra silenciada',
  840. HOME: 'Página Inicial',
  841. MUTE_THIS_CONVERSATION: 'Silenciar esta conversa',
  842. POST_ALL: 'Postar tudo',
  843. QUOTE: 'Comentar',
  844. QUOTE_TWEET: 'Comentar o Tweet',
  845. QUOTE_TWEETS: 'Tweets com comentário',
  846. REPOST: 'Repostar',
  847. RETWEET: 'Retweetar',
  848. RETWEETED_BY: 'Retweetado por',
  849. SHARED_TWEETS: 'Tweets Compartilhados',
  850. SHOW: 'Mostrar',
  851. SHOW_MORE_REPLIES: 'Mostrar mais respostas',
  852. TURN_OFF_RETWEETS: 'Desativar Retweets',
  853. TURN_ON_RETWEETS: 'Ativar Retweets',
  854. TWEET: 'Tweetar',
  855. TWEET_ALL: 'Tweetar tudo',
  856. TWEET_YOUR_REPLY: 'Tweetar sua resposta!',
  857. },
  858. ro: {
  859. ADD_MUTED_WORD: 'Adaugă cuvântul ignorat',
  860. HOME: 'Pagina principală',
  861. MUTE_THIS_CONVERSATION: 'Ignoră această conversație',
  862. POST_ALL: 'Postează tot',
  863. QUOTE: 'Citat',
  864. QUOTE_TWEET: 'Citează Tweetul',
  865. QUOTE_TWEETS: 'Tweeturi cu citat',
  866. REPOST: 'Repostează',
  867. REPOSTS: 'Repostări',
  868. RETWEET: 'Redistribuie',
  869. RETWEETED_BY: 'Redistribuit de către',
  870. RETWEETS: 'Retweeturi',
  871. SHARED_TWEETS: 'Tweeturi partajate',
  872. SHOW: 'Afișează',
  873. SHOW_MORE_REPLIES: 'Afișează mai multe răspunsuri',
  874. TURN_OFF_RETWEETS: 'Dezactivează Retweeturile',
  875. TURN_ON_RETWEETS: 'Activează Retweeturile',
  876. TWEETS: 'Tweeturi',
  877. TWEET_ALL: 'Dă Tweeturi cu tot',
  878. TWEET_YOUR_REPLY: 'Dă Tweet cu răspunsul!',
  879. },
  880. ru: {
  881. ADD_MUTED_WORD: 'Добавить игнорируемое слово',
  882. HOME: 'Главная',
  883. MUTE_THIS_CONVERSATION: 'Игнорировать эту переписку',
  884. POST_ALL: 'Опубликовать все',
  885. QUOTE: 'Цитата',
  886. QUOTE_TWEET: 'Цитировать',
  887. QUOTE_TWEETS: 'Твиты с цитатами',
  888. REPOST: 'Сделать репост',
  889. REPOSTS: 'Репосты',
  890. RETWEET: 'Ретвитнуть',
  891. RETWEETED_BY: 'Ретвитнул(а)',
  892. RETWEETS: 'Ретвиты',
  893. SHARED_TWEETS: 'Общие твиты',
  894. SHOW: 'Показать',
  895. SHOW_MORE_REPLIES: 'Показать еще ответы',
  896. TURN_OFF_RETWEETS: 'Отключить ретвиты',
  897. TURN_ON_RETWEETS: 'Включить ретвиты',
  898. TWEET: 'Твитнуть',
  899. TWEETS: 'Твиты',
  900. TWEET_ALL: 'Твитнуть все',
  901. TWEET_YOUR_REPLY: 'Твитните свой ответ!',
  902. TWITTER: 'Твиттер',
  903. },
  904. sk: {
  905. ADD_MUTED_WORD: 'Pridať stíšené slovo',
  906. HOME: 'Domov',
  907. MUTE_THIS_CONVERSATION: 'Stíšiť túto konverzáciu',
  908. POST_ALL: 'Uverejniť všetko',
  909. QUOTE: 'Citát',
  910. QUOTE_TWEET: 'Tweet s citátom',
  911. QUOTE_TWEETS: 'Tweety s citátom',
  912. REPOST: 'Opätovné uverejnenie',
  913. REPOSTS: 'Opätovné uverejnenia',
  914. RETWEET: 'Retweetnuť',
  915. RETWEETED_BY: 'Retweetnuté používateľom',
  916. RETWEETS: 'Retweety',
  917. SHARED_TWEETS: 'Zdieľané Tweety',
  918. SHOW: 'Zobraziť',
  919. SHOW_MORE_REPLIES: 'Zobraziť viac odpovedí',
  920. TURN_OFF_RETWEETS: 'Vypnúť retweety',
  921. TURN_ON_RETWEETS: 'Zapnúť retweety',
  922. TWEET: 'Tweetnuť',
  923. TWEETS: 'Tweety',
  924. TWEET_ALL: 'Tweetnuť všetko',
  925. TWEET_YOUR_REPLY: 'Tweetnite odpoveď!',
  926. },
  927. sr: {
  928. ADD_MUTED_WORD: 'Додај игнорисану реч',
  929. HOME: 'Почетна',
  930. MUTE_THIS_CONVERSATION: 'Игнориши овај разговор',
  931. POST_ALL: 'Објави све',
  932. QUOTE: 'Цитат',
  933. QUOTE_TWEET: 'твит са цитатом',
  934. QUOTE_TWEETS: 'твит(ов)а са цитатом',
  935. REPOST: 'Поново објави',
  936. REPOSTS: 'Понвне објаве',
  937. RETWEET: 'Ретвитуј',
  938. RETWEETED_BY: 'Ретвитовано од стране',
  939. RETWEETS: 'Ретвитови',
  940. SHARED_TWEETS: 'Дељени твитови',
  941. SHOW: 'Прикажи',
  942. SHOW_MORE_REPLIES: 'Прикажи још одговора',
  943. TURN_OFF_RETWEETS: 'Искључи ретвитове',
  944. TURN_ON_RETWEETS: 'Укључи ретвитове',
  945. TWEET: 'Твитуј',
  946. TWEETS: 'Твитови',
  947. TWEET_ALL: 'Твитуј све',
  948. TWEET_YOUR_REPLY: 'Твитуј свој одговор!',
  949. TWITTER: 'Твитер',
  950. },
  951. sv: {
  952. ADD_MUTED_WORD: 'Lägg till ignorerat ord',
  953. HOME: 'Hem',
  954. MUTE_THIS_CONVERSATION: 'Ignorera den här konversationen',
  955. POST_ALL: 'Lägg upp allt',
  956. QUOTE: 'Citat',
  957. QUOTE_TWEET: 'Citera Tweet',
  958. QUOTE_TWEETS: 'Citat-tweets',
  959. REPOST: 'Återpublicera',
  960. REPOSTS: 'Återpubliceringar',
  961. RETWEET: 'Retweeta',
  962. RETWEETED_BY: 'Retweetad av',
  963. SHARED_TWEETS: 'Delade tweetsen',
  964. SHOW: 'Visa',
  965. SHOW_MORE_REPLIES: 'Visa fler svar',
  966. TURN_OFF_RETWEETS: 'Stäng av Retweets',
  967. TURN_ON_RETWEETS: 'Slå på Retweets',
  968. TWEET: 'Tweeta',
  969. TWEET_ALL: 'Tweeta allt',
  970. TWEET_YOUR_REPLY: 'Tweeta ditt svar!',
  971. },
  972. ta: {
  973. ADD_MUTED_WORD: 'செயல்மறைத்த வார்த்தையைச் சேர்',
  974. HOME: 'முகப்பு',
  975. MUTE_THIS_CONVERSATION: 'இந்த உரையாடலை செயல்மறை',
  976. POST_ALL: 'எல்லாம் இடுகையிடு',
  977. QUOTE: 'மேற்கோள்',
  978. QUOTE_TWEET: 'ட்விட்டை மேற்கோள் காட்டு',
  979. QUOTE_TWEETS: 'மேற்கோள் கீச்சுகள்',
  980. REPOST: 'மறுஇடுகை',
  981. REPOSTS: 'மறுஇடுகைகள்',
  982. RETWEET: 'மறுட்விட் செய்',
  983. RETWEETED_BY: 'இவரால் மறுட்விட் செய்யப்பட்டது',
  984. RETWEETS: 'மறுகீச்சுகள்',
  985. SHARED_TWEETS: 'பகிரப்பட்ட ட்வீட்டுகள்',
  986. SHOW: 'காண்பி',
  987. SHOW_MORE_REPLIES: 'மேலும் பதில்களைக் காண்பி',
  988. TURN_OFF_RETWEETS: 'மறுகீச்சுகளை அணை',
  989. TURN_ON_RETWEETS: 'மறுகீச்சுகளை இயக்கு',
  990. TWEET: 'ட்விட் செய்',
  991. TWEETS: 'கீச்சுகள்',
  992. TWEET_ALL: 'அனைத்தையும் ட்விட் செய்',
  993. TWEET_YOUR_REPLY: 'உங்கள் பதிலை ட்விட் செய்யவும்!',
  994. },
  995. th: {
  996. ADD_MUTED_WORD: 'เพิ่มคำที่ซ่อน',
  997. HOME: 'หน้าแรก',
  998. MUTE_THIS_CONVERSATION: 'ซ่อนบทสนทนานี้',
  999. POST_ALL: 'โพสต์ทั้งหมด',
  1000. QUOTE: 'การอ้างอิง',
  1001. QUOTE_TWEET: 'อ้างอิงทวีต',
  1002. QUOTE_TWEETS: 'ทวีตและคำพูด',
  1003. REPOST: 'รีโพสต์',
  1004. REPOSTS: 'รีโพสต์',
  1005. RETWEET: 'รีทวีต',
  1006. RETWEETED_BY: 'ถูกรีทวีตโดย',
  1007. RETWEETS: 'รีทวีต',
  1008. SHARED_TWEETS: 'ทวีตที่แชร์',
  1009. SHOW: 'แสดง',
  1010. SHOW_MORE_REPLIES: 'แสดงการตอบกลับเพิ่มเติม',
  1011. TURN_OFF_RETWEETS: 'ปิดรีทวีต',
  1012. TURN_ON_RETWEETS: 'เปิดรีทวีต',
  1013. TWEET: 'ทวีต',
  1014. TWEETS: 'ทวีต',
  1015. TWEET_ALL: 'ทวีตทั้งหมด',
  1016. TWEET_YOUR_REPLY: 'ทวีตการตอบกลับของคุณ',
  1017. TWITTER: 'ทวิตเตอร์',
  1018. },
  1019. tr: {
  1020. ADD_MUTED_WORD: 'Sessize alınacak kelime ekle',
  1021. HOME: 'Anasayfa',
  1022. MUTE_THIS_CONVERSATION: 'Bu sohbeti sessize al',
  1023. POST_ALL: 'Tümünü gönder',
  1024. QUOTE: 'Alıntı',
  1025. QUOTE_TWEET: 'Tweeti Alıntıla',
  1026. QUOTE_TWEETS: 'Alıntı Tweetler',
  1027. REPOST: 'Yeniden gönder',
  1028. REPOSTS: 'Yeniden gönderiler',
  1029. RETWEETED_BY: 'Retweetleyen(ler):',
  1030. RETWEETS: 'Retweetler',
  1031. SHARED_TWEETS: 'Paylaşılan Tweetler',
  1032. SHOW: 'Göster',
  1033. SHOW_MORE_REPLIES: 'Daha fazla yanıt göster',
  1034. TURN_OFF_RETWEETS: 'Retweetleri kapat',
  1035. TURN_ON_RETWEETS: 'Retweetleri aç',
  1036. TWEET: 'Tweetle',
  1037. TWEETS: 'Tweetler',
  1038. TWEET_ALL: 'Hepsini Tweetle',
  1039. TWEET_YOUR_REPLY: 'Yanıtını Tweetle.',
  1040. },
  1041. uk: {
  1042. ADD_MUTED_WORD: 'Додати слово до списку ігнорування',
  1043. HOME: 'Головна',
  1044. MUTE_THIS_CONVERSATION: 'Ігнорувати цю розмову',
  1045. POST_ALL: 'Опублікувати все',
  1046. QUOTE: 'Цитата',
  1047. QUOTE_TWEET: 'Цитувати твіт',
  1048. QUOTE_TWEETS: 'Цитовані твіти',
  1049. REPOST: 'Зробити репост',
  1050. REPOSTS: 'Репости',
  1051. RETWEET: 'Ретвітнути',
  1052. RETWEETED_BY: 'Ретвіти',
  1053. RETWEETS: 'Ретвіти',
  1054. SHARED_TWEETS: 'Спільні твіти',
  1055. SHOW: 'Показати',
  1056. SHOW_MORE_REPLIES: 'Показати більше відповідей',
  1057. TURN_OFF_RETWEETS: 'Вимкнути ретвіти',
  1058. TURN_ON_RETWEETS: 'Увімкнути ретвіти',
  1059. TWEET: 'Твіт',
  1060. TWEETS: 'Твіти',
  1061. TWEET_ALL: 'Твітнути все',
  1062. TWEET_YOUR_REPLY: 'Твітніть свою відповідь!',
  1063. TWITTER: 'Твіттер',
  1064. },
  1065. ur: {
  1066. ADD_MUTED_WORD: 'میوٹ شدہ لفظ شامل کریں',
  1067. HOME: 'ہوم',
  1068. MUTE_THIS_CONVERSATION: 'اس گفتگو کو میوٹ کریں',
  1069. QUOTE: 'نقل کریں',
  1070. QUOTE_TWEET: 'ٹویٹ کا حوالہ دیں',
  1071. QUOTE_TWEETS: 'ٹویٹ کو نقل کرو',
  1072. RETWEET: 'ریٹویٹ',
  1073. RETWEETED_BY: 'جنہوں نے ریٹویٹ کیا',
  1074. RETWEETS: 'ریٹویٹس',
  1075. SHARED_TWEETS: 'مشترکہ ٹویٹس',
  1076. SHOW: 'دکھائیں',
  1077. SHOW_MORE_REPLIES: 'مزید جوابات دکھائیں',
  1078. TURN_OFF_RETWEETS: 'ری ٹویٹس غیر فعال کریں',
  1079. TURN_ON_RETWEETS: 'ری ٹویٹس غیر فعال کریں',
  1080. TWEET: 'ٹویٹ',
  1081. TWEETS: 'ٹویٹس',
  1082. TWEET_ALL: 'سب کو ٹویٹ کریں',
  1083. TWITTER: 'ٹوئٹر',
  1084. },
  1085. vi: {
  1086. ADD_MUTED_WORD: 'Thêm từ tắt tiếng',
  1087. HOME: 'Trang chủ',
  1088. MUTE_THIS_CONVERSATION: 'Tắt tiếng cuộc trò chuyện này',
  1089. POST_ALL: 'Đăng tất cả',
  1090. QUOTE: 'Trích dẫn',
  1091. QUOTE_TWEET: 'Trích dẫn Tweet',
  1092. QUOTE_TWEETS: 'Tweet trích dẫn',
  1093. REPOST: 'Đăng lại',
  1094. REPOSTS: 'Bài đăng lại',
  1095. RETWEET: 'Tweet lại',
  1096. RETWEETED_BY: 'Được Tweet lại bởi',
  1097. RETWEETS: 'Các Tweet lại',
  1098. SHARED_TWEETS: 'Tweet được chia sẻ',
  1099. SHOW: 'Hiện',
  1100. SHOW_MORE_REPLIES: 'Hiển thị thêm trả lời',
  1101. TURN_OFF_RETWEETS: 'Tắt Tweet lại',
  1102. TURN_ON_RETWEETS: 'Bật Tweet lại',
  1103. TWEETS: 'Tweet',
  1104. TWEET_ALL: 'Đăng Tweet tất cả',
  1105. TWEET_YOUR_REPLY: 'Đăng Tweet câu trả lời của bạn!',
  1106. },
  1107. 'zh-Hant': {
  1108. ADD_MUTED_WORD: '加入靜音文字',
  1109. HOME: '首頁',
  1110. MUTE_THIS_CONVERSATION: '將此對話靜音',
  1111. POST_ALL: '全部發佈',
  1112. QUOTE: '引用',
  1113. QUOTE_TWEET: '引用推文',
  1114. QUOTE_TWEETS: '引用的推文',
  1115. REPOST: '轉發',
  1116. REPOSTS: '轉發',
  1117. RETWEET: '轉推',
  1118. RETWEETED_BY: '已被轉推',
  1119. RETWEETS: '轉推',
  1120. SHARED_TWEETS: '分享的推文',
  1121. SHOW: '顯示',
  1122. SHOW_MORE_REPLIES: '顯示更多回覆',
  1123. TURN_OFF_RETWEETS: '關閉轉推',
  1124. TURN_ON_RETWEETS: '開啟轉推',
  1125. TWEET: '推文',
  1126. TWEETS: '推文',
  1127. TWEET_ALL: '推全部內容',
  1128. TWEET_YOUR_REPLY: '推你的回覆!',
  1129. },
  1130. zh: {
  1131. ADD_MUTED_WORD: '添加要隐藏的字词',
  1132. HOME: '主页',
  1133. MUTE_THIS_CONVERSATION: '隐藏此对话',
  1134. POST_ALL: '全部发帖',
  1135. QUOTE: '引用',
  1136. QUOTE_TWEET: '引用推文',
  1137. QUOTE_TWEETS: '引用推文',
  1138. REPOST: '转帖',
  1139. REPOSTS: '转帖',
  1140. RETWEET: '转推',
  1141. RETWEETED_BY: '转推者',
  1142. RETWEETS: '转推',
  1143. SHARED_TWEETS: '分享的推文',
  1144. SHOW: '显示',
  1145. SHOW_MORE_REPLIES: '显示更多回复',
  1146. TURN_OFF_RETWEETS: '关闭转推',
  1147. TURN_ON_RETWEETS: '开启转推',
  1148. TWEET: '推文',
  1149. TWEETS: '推文',
  1150. TWEET_ALL: '全部发推',
  1151. TWEET_YOUR_REPLY: '发布你的回复!',
  1152. },
  1153. }
  1154.  
  1155. /**
  1156. * @param {import("./types").LocaleKey} code
  1157. * @returns {string}
  1158. */
  1159. function getString(code) {
  1160. return (locales[lang] || locales['en'])[code] || locales['en'][code];
  1161. }
  1162. //#endregion
  1163.  
  1164. //#region Constants
  1165. /** @enum {string} */
  1166. const PagePaths = {
  1167. ADD_MUTED_WORD: '/settings/add_muted_keyword',
  1168. BOOKMARKS: '/i/bookmarks',
  1169. COMPOSE_MESSAGE: '/messages/compose',
  1170. COMPOSE_TWEET: '/compose/tweet',
  1171. CONNECT: '/i/connect',
  1172. CUSTOMIZE_YOUR_VIEW: '/i/display',
  1173. HOME: '/home',
  1174. NOTIFICATION_TIMELINE: '/i/timeline',
  1175. PROFILE_SETTINGS: '/settings/profile',
  1176. SEARCH: '/search',
  1177. }
  1178.  
  1179. /** @enum {string} */
  1180. const Selectors = {
  1181. BLOCK_MENU_ITEM: '[data-testid="block"]',
  1182. DESKTOP_TIMELINE_HEADER: 'div[data-testid="primaryColumn"] > div > div:first-of-type',
  1183. DISPLAY_DONE_BUTTON_DESKTOP: '#layers div[role="button"]:not([aria-label])',
  1184. DISPLAY_DONE_BUTTON_MOBILE: 'main div[role="button"]:not([aria-label])',
  1185. MESSAGES_DRAWER: 'div[data-testid="DMDrawer"]',
  1186. MODAL_TIMELINE: 'section > h1 + div[aria-label] > div',
  1187. MOBILE_TIMELINE_HEADER: 'div[data-testid="TopNavBar"]',
  1188. NAV_HOME_LINK: 'a[data-testid="AppTabBar_Home_Link"]',
  1189. PRIMARY_COLUMN: 'div[data-testid="primaryColumn"]',
  1190. PRIMARY_NAV_DESKTOP: 'header nav',
  1191. PRIMARY_NAV_MOBILE: '#layers nav',
  1192. PROMOTED_TWEET_CONTAINER: '[data-testid="placementTracking"]',
  1193. SIDEBAR: 'div[data-testid="sidebarColumn"]',
  1194. SIDEBAR_WRAPPERS: 'div[data-testid="sidebarColumn"] > div > div > div > div > div',
  1195. TIMELINE: 'div[data-testid="primaryColumn"] section > h1 + div[aria-label] > div',
  1196. TIMELINE_HEADING: 'h2[role="heading"]',
  1197. TWEET: '[data-testid="tweet"]',
  1198. VERIFIED_TICK: 'svg[data-testid="icon-verified"]',
  1199. X_LOGO_PATH: 'svg path[d="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"]',
  1200. }
  1201.  
  1202. /** @enum {string} */
  1203. const Svgs = {
  1204. BLUE_LOGO_PATH: 'M16.5 3H2v18h15c3.038 0 5.5-2.46 5.5-5.5 0-1.4-.524-2.68-1.385-3.65-.08-.09-.089-.22-.023-.32.574-.87.908-1.91.908-3.03C22 5.46 19.538 3 16.5 3zm-.796 5.99c.457-.05.892-.17 1.296-.35-.302.45-.684.84-1.125 1.15.004.1.006.19.006.29 0 2.94-2.269 6.32-6.421 6.32-1.274 0-2.46-.37-3.459-1 .177.02.357.03.539.03 1.057 0 2.03-.35 2.803-.95-.988-.02-1.821-.66-2.109-1.54.138.03.28.04.425.04.206 0 .405-.03.595-.08-1.033-.2-1.811-1.1-1.811-2.18v-.03c.305.17.652.27 1.023.28-.606-.4-1.004-1.08-1.004-1.85 0-.4.111-.78.305-1.11 1.113 1.34 2.775 2.22 4.652 2.32-.038-.17-.058-.33-.058-.51 0-1.23 1.01-2.22 2.256-2.22.649 0 1.235.27 1.647.7.514-.1.997-.28 1.433-.54-.168.52-.526.96-.992 1.23z',
  1205. HOME: '<g><path d="M12 9c-2.209 0-4 1.791-4 4s1.791 4 4 4 4-1.791 4-4-1.791-4-4-4zm0 6c-1.105 0-2-.895-2-2s.895-2 2-2 2 .895 2 2-.895 2-2 2zm0-13.304L.622 8.807l1.06 1.696L3 9.679V19.5C3 20.881 4.119 22 5.5 22h13c1.381 0 2.5-1.119 2.5-2.5V9.679l1.318.824 1.06-1.696L12 1.696zM19 19.5c0 .276-.224.5-.5.5h-13c-.276 0-.5-.224-.5-.5V8.429l7-4.375 7 4.375V19.5z"></path></g>',
  1206. MUTE: '<g><path d="M18 6.59V1.2L8.71 7H5.5C4.12 7 3 8.12 3 9.5v5C3 15.88 4.12 17 5.5 17h2.09l-2.3 2.29 1.42 1.42 15.5-15.5-1.42-1.42L18 6.59zm-8 8V8.55l6-3.75v3.79l-6 6zM5 9.5c0-.28.22-.5.5-.5H8v6H5.5c-.28 0-.5-.22-.5-.5v-5zm6.5 9.24l1.45-1.45L16 19.2V14l2 .02v8.78l-6.5-4.06z"></path></g>',
  1207. RETWEET: '<g><path d="M4.5 3.88l4.432 4.14-1.364 1.46L5.5 7.55V16c0 1.1.896 2 2 2H13v2H7.5c-2.209 0-4-1.79-4-4V7.55L1.432 9.48.068 8.02 4.5 3.88zM16.5 6H11V4h5.5c2.209 0 4 1.79 4 4v8.45l2.068-1.93 1.364 1.46-4.432 4.14-4.432-4.14 1.364-1.46 2.068 1.93V8c0-1.1-.896-2-2-2z"></path></g>',
  1208. RETWEETS_OFF: '<g><path d="M3.707 21.707l18-18-1.414-1.414-2.088 2.088C17.688 4.137 17.11 4 16.5 4H11v2h5.5c.028 0 .056 0 .084.002l-10.88 10.88c-.131-.266-.204-.565-.204-.882V7.551l2.068 1.93 1.365-1.462L4.5 3.882.068 8.019l1.365 1.462 2.068-1.93V16c0 .871.278 1.677.751 2.334l-1.959 1.959 1.414 1.414zM18.5 9h2v7.449l2.068-1.93 1.365 1.462-4.433 4.137-4.432-4.137 1.365-1.462 2.067 1.93V9zm-8.964 9l-2 2H13v-2H9.536z"></path></g>',
  1209. TWITTER_LOGO_PATH: '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',
  1210. }
  1211.  
  1212. /** @enum {string} */
  1213. const Images = {
  1214. TWITTER_FAVICON: 'data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAA0pJREFUWAntVk1oE1EQnnlJbFK3KUq9VJPYWgQVD/5QD0qpfweL1YJQoZAULBRPggp6kB78PQn14kHx0jRB0UO9REVFb1YqVBEsbZW2SbVS0B6apEnbbMbZ6qbZdTempqCHPAjvzcw3P5mdmfcAiquYgX+cAVwu/+5AdDMQnSPCHUhQA0hf+Rxy2OjicIvzm+qnKhito0qpb2wvJhWeJgCPP7oPELeHvdJ1VSGf3eOPnSWga0S0Qo9HxEkEusDBuNjbEca8G291nlBxmgDc/ukuIvAJxI6wr+yKCsq1ewLxQ2lZfpQLo8oQ4ZXdCkfnACrGWpyDCl+oQmVn5xuVPU102e2P3qoJkFOhzVb9S7KSnL5jJs/mI+As01PJFPSlZeFSZZoAGBRXBZyq9lk5NrC+e7pJ5en30c+JWk59pZ5vRDOuhAD381c/H/FKz1SMNgCE16rg505r5TT0uLqme93d0fbq+1SeLSeU83Ke0RHYFPGVPcjQfNDUwIa7M665+dQAEEjZoMwZMcEF9RxIDAgBQ2mCcqJ0Z0b+h4MNbZ4RnyOSDbNmE2iRk5jCNgIIckFoZAs4IgfLGrlKGjkzS16iwj6pV9I4mUvCPf73JVytH9nRJj24QHrqU8NCIWrMaGqAC+Ut/3ZzAS63cx4v2K/x/IvQBOCwWzu5KmJGwEJ5PIgeG9nQBDDcXPpFoDjJ7ThvBC6EZxXWkJG+JgAFwGM4KBAOcibeGCn8FQ/hyajXPmSk+1sACogn4hYk7OdiHDFSWipPkPWSmY6mCzIghEEuxJvcEYUvxIdhX2mvmSHDDPBF9AJRnDZTyp+P40671JYLbxiAohDxSTfQIg4oNxgPzCWPHaWQBViOf2jGqVwBaEaxGbAqOFMrp+SefC8eNhoFIY5lXzpmtnMGUB2IbU3JdIqVW9m5zcxINn/hAYKiIexdaTh4srHKORMAP0b28PNgJyGt5gvHzQVYx91QpVcwpRFl/p63HSR1DLbid1OcTpAJQOG7u+KH+aI5Qwj13IsamU5vkUSIc8uGLDa8OtoivV8U5HcydFLtT7hlSDVy2nfxI2Ibg9awuVU8IeJAOMF5m2B6jFs1tM5R9rS3GRP5uSuiihn4DzPwA7z7GDH+43gqAAAAAElFTkSuQmCC',
  1215. TWITTER_PIP_FAVICON: 'data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAALASURBVHgB7VZNchJBFP5eM9FoRWV2WiZmbmBuIJ4g5ASBRWJlRXIC4ASQVUqxCo4QTwDegJzAiYlFXM1YZWmVQD9fQ6YyAwMMGBZW8i2G6e7He1+/3wHuOih4+fWieJhiKsirA0ZbE44fXZUaWDIGBH4/L+UUUB897DMfPf5ermKJUOaRIhTiDlNEBSwZlnkwY2vCuYOEWD/xMrCoKC41utISRlcc3Or2dfnqwHbDcj9X0fbztn9DAHxOoM0xrZILSIBXtR9F0VGKbJIhz7kVi3Lr770yAz4p2iYm188/awVi6lo4Ns4mETEDLz94uTHjIxDDRaWoohhOSjwi/9mKEFjtlKsayAuRM7M2HmFJwCRVIIqLSAAJjS822v0Vaip1E1oKC6XrXtrExjnxnJ6ldoVKFj0+ujywW3FKTTzJoibmAXP+Yt9uBEsrfLbWRelJzS/0B8z4WoKa6zW/1dd83Hlnn0Z0peAQkqNHvNPZi+qIELBWUNU97LLJ4hDESMZSlNmo+b5UTEvC85m0JCipTQREE+BhdzypIwSkLvyn4LKYrEzQkSZCloiyw+xJbnygfxX+VAJrPWnBoC9ixBXdDm4XflD7YajIinFq3L0E45J7fBa3HyEg7mhgeWjPJODu223J/iMsATzhcmp04+ueXTW1OsiD2zIuVfNNLockBAyIkdaaPxHGs3YR0JTQWnGbWkFCQZX5imwCmBoX++nGpONYD1zu2S0a9IN/g3jSNcNnqsy0ww2ZdPJzCKLXWAAy1N6ay2BRAgEcGZ+aqDnaoqdbjw6dhQgYwz1S2xKOQyQ0Phy7vDPr5iH5ITY+elmtpddLFyQzZBTP3xGl3FJ95NzQJ1hiAgMSw5jnJOZvMA/EMBNKSW89kUAAp+45+g+yojRjljL9NoP4GxdLYzk334vy3lYP0HBjhsw97vHf4C/b8RLHAOr+CQAAAABJRU5ErkJggg==',
  1216. }
  1217.  
  1218. const THEME_BLUE = 'rgb(29, 155, 240)'
  1219. const THEME_COLORS = new Set([
  1220. THEME_BLUE,
  1221. 'rgb(255, 212, 0)', // yellow
  1222. 'rgb(244, 33, 46)', // pink
  1223. 'rgb(120, 86, 255)', // purple
  1224. 'rgb(255, 122, 0)', // orange
  1225. 'rgb(0, 186, 124)', // green
  1226. ])
  1227. // <body> pseudo-selector for pages the full-width content feature works on
  1228. const FULL_WIDTH_BODY_PSEUDO = ':is(.Community, .List, .MainTimeline)'
  1229. // Matches any notification count at the start of the title
  1230. const TITLE_NOTIFICATION_RE = /^\(\d+\+?\) /
  1231. // The Communities nav item takes you to /yourusername/communities
  1232. const URL_COMMUNITIES_RE = /^\/[a-zA-Z\d_]{1,20}\/communities\/?$/
  1233. const URL_COMMUNITY_RE = /^\/i\/communities\/\d+(?:\/about)?\/?$/
  1234. const URL_COMMUNITY_MEMBERS_RE = /^\/i\/communities\/\d+\/(?:members|moderators)\/?$/
  1235. const URL_DISCOVER_COMMUNITIES_RE = /^\/i\/communities\/suggested\/?/
  1236. const URL_LIST_RE = /\/i\/lists\/\d+\/?$/
  1237. const URL_MEDIA_RE = /\/(?:photo|video)\/\d\/?$/
  1238. const URL_MEDIAVIEWER_RE = /^\/[a-zA-Z\d_]{1,20}\/status\/\d+\/mediaviewer$/i
  1239. // Matches URLs which show one of the tabs on a user profile page
  1240. const URL_PROFILE_RE = /^\/([a-zA-Z\d_]{1,20})(?:\/(?:with_replies|superfollows|highlights|media|likes))?\/?$/
  1241. // Matches URLs which show a user's Followers you know / Followers / Following tab
  1242. const URL_PROFILE_FOLLOWS_RE = /^\/[a-zA-Z\d_]{1,20}\/follow(?:ing|ers|ers_you_follow)\/?$/
  1243. const URL_TWEET_RE = /^\/([a-zA-Z\d_]{1,20})\/status\/(\d+)\/?$/
  1244. const URL_TWEET_LIKES_RETWEETS_RE = /^\/[a-zA-Z\d_]{1,20}\/status\/\d+\/(likes|retweets|reposts)\/?$/
  1245.  
  1246. // The Twitter Media Assist exension adds a new button at the end of the action
  1247. // bar (#346)
  1248. const TWITTER_MEDIA_ASSIST_BUTTON_SELECTOR = '.tva-download-icon, .tva-modal-download-icon'
  1249. //#endregion
  1250.  
  1251. //#region Variables
  1252. /**
  1253. * The quoted Tweet associated with a caret menu that's just been opened.
  1254. * @type {import("./types").QuotedTweet}
  1255. */
  1256. let quotedTweet = null
  1257.  
  1258. /** `true` when a 'Block @${user}' menu item was seen in the last popup. */
  1259. let blockMenuItemSeen = false
  1260.  
  1261. /** Notification count in the title (including trailing space), e.g. `'(1) '`. */
  1262. let currentNotificationCount = ''
  1263.  
  1264. /** Title of the current page, without the `' / Twitter'` suffix. */
  1265. let currentPage = ''
  1266.  
  1267. /** Current `location.pathname`. */
  1268. let currentPath = ''
  1269.  
  1270. /**
  1271. * CSS rule in the React Native stylesheet which defines the Chirp font-family
  1272. * and fallbacks for the whole app.
  1273. * @type {CSSStyleRule}
  1274. */
  1275. let fontFamilyRule = null
  1276.  
  1277. /** @type {string} */
  1278. let fontSize = null
  1279.  
  1280. /** Set to `true` when a Home/Following heading or Home nav link is used. */
  1281. let homeNavigationIsBeingUsed = false
  1282.  
  1283. /** Set to `true` when the media modal is open on desktop. */
  1284. let isDesktopMediaModalOpen = false
  1285.  
  1286. /** Set to `true` when the compose tweet modal is open on desktop. */
  1287. let isDesktopComposeTweetModalOpen = false
  1288.  
  1289. /** Set to `true` when a user list modal is open on desktop. */
  1290. let isDesktopUserListModalOpen = false
  1291.  
  1292. /**
  1293. * Cache for the last page title which was used for the main timeline.
  1294. * @type {string}
  1295. */
  1296. let lastMainTimelineTitle = null
  1297.  
  1298. /**
  1299. * MutationObservers active on the current modal.
  1300. * @type {import("./types").Disconnectable[]}
  1301. */
  1302. let modalObservers = []
  1303.  
  1304. /**
  1305. * `true` after the app has initialised.
  1306. * @type {boolean}
  1307. */
  1308. let observingPageChanges = false
  1309.  
  1310. /**
  1311. * MutationObservers active on the current page, or anything else we want to
  1312. * clean up when the user moves off the current page.
  1313. * @type {import("./types").NamedMutationObserver[]}
  1314. */
  1315. let pageObservers = []
  1316.  
  1317. /** `true` when a 'Pin to your profile' menu item was seen in the last popup. */
  1318. let pinMenuItemSeen = false
  1319.  
  1320. /** @type {number} */
  1321. let selectedHomeTabIndex = -1
  1322.  
  1323. /**
  1324. * Title for the fake timeline used to separate out retweets and quote tweets.
  1325. * @type {string}
  1326. */
  1327. let separatedTweetsTimelineTitle = null
  1328.  
  1329. /**
  1330. * The current "Color" setting, which can be changed in "Customize your view".
  1331. * @type {string}
  1332. */
  1333. let themeColor = localStorage.lastThemeColor
  1334.  
  1335. /**
  1336. * `true` when "For you" was the last tab selected on the main timeline.
  1337. */
  1338. let wasForYouTabSelected = false
  1339.  
  1340. function isOnBookmarksPage() {
  1341. return currentPath == PagePaths.BOOKMARKS
  1342. }
  1343.  
  1344. function isOnCommunitiesPage() {
  1345. return URL_COMMUNITIES_RE.test(currentPath)
  1346. }
  1347.  
  1348. function isOnCommunityPage() {
  1349. return URL_COMMUNITY_RE.test(currentPath)
  1350. }
  1351.  
  1352. function isOnCommunityMembersPage() {
  1353. return URL_COMMUNITY_MEMBERS_RE.test(currentPath)
  1354. }
  1355.  
  1356. function isOnDiscoverCommunitiesPage() {
  1357. return URL_DISCOVER_COMMUNITIES_RE.test(currentPath)
  1358. }
  1359.  
  1360. function isOnExplorePage() {
  1361. return currentPath.startsWith('/explore')
  1362. }
  1363.  
  1364. function isOnFollowListPage() {
  1365. return URL_PROFILE_FOLLOWS_RE.test(currentPath)
  1366. }
  1367.  
  1368. function isOnHomeTimeline() {
  1369. return currentPage == getString('HOME')
  1370. }
  1371.  
  1372. function isOnIndividualTweetPage() {
  1373. return URL_TWEET_RE.test(currentPath)
  1374. }
  1375.  
  1376. function isOnListPage() {
  1377. return URL_LIST_RE.test(currentPath)
  1378. }
  1379.  
  1380. function isOnMainTimelinePage() {
  1381. return currentPath == PagePaths.HOME || (
  1382. currentPath == PagePaths.CUSTOMIZE_YOUR_VIEW &&
  1383. isOnHomeTimeline() ||
  1384. isOnSeparatedTweetsTimeline()
  1385. )
  1386. }
  1387.  
  1388. function isOnMessagesPage() {
  1389. return currentPath.startsWith('/messages')
  1390. }
  1391.  
  1392. function isOnNotificationsPage() {
  1393. return currentPath.startsWith('/notifications')
  1394. }
  1395.  
  1396. function isOnProfilePage() {
  1397. let profilePathUsername = currentPath.match(URL_PROFILE_RE)?.[1]
  1398. if (!profilePathUsername) return false
  1399. // twitter.com/user and its sub-URLs put @user in the title
  1400. return currentPage.toLowerCase().includes(`${ltr ? '@' : ''}${profilePathUsername.toLowerCase()}${!ltr ? '@' : ''}`)
  1401. }
  1402.  
  1403. function isOnQuoteTweetsPage() {
  1404. return currentPath.endsWith('/retweets/with_comments')
  1405. }
  1406.  
  1407. function isOnSearchPage() {
  1408. return currentPath.startsWith('/search') || currentPath.startsWith('/hashtag/')
  1409. }
  1410.  
  1411. function isOnSeparatedTweetsTimeline() {
  1412. return currentPage == separatedTweetsTimelineTitle
  1413. }
  1414.  
  1415. function isOnSettingsPage() {
  1416. return currentPath.startsWith('/settings')
  1417. }
  1418.  
  1419. function shouldHideSidebar() {
  1420. return isOnExplorePage() || isOnDiscoverCommunitiesPage()
  1421. }
  1422.  
  1423. function shouldShowSeparatedTweetsTab() {
  1424. return config.retweets == 'separate' || config.quoteTweets == 'separate'
  1425. }
  1426. //#endregion
  1427.  
  1428. //#region Utility functions
  1429. /**
  1430. * @param {string} role
  1431. * @return {HTMLStyleElement}
  1432. */
  1433. function addStyle(role) {
  1434. let $style = document.createElement('style')
  1435. $style.dataset.insertedBy = 'control-panel-for-twitter'
  1436. $style.dataset.role = role
  1437. document.head.appendChild($style)
  1438. return $style
  1439. }
  1440.  
  1441. /**
  1442. * @param {Element} $svg
  1443. */
  1444. function blueCheck($svg) {
  1445. if (!$svg) {
  1446. warn('blueCheck was given', $svg)
  1447. return
  1448. }
  1449. $svg.classList.add('tnt_blue_check')
  1450. // Safari doesn't support using `d: path(…)` to replace paths in an SVG, so
  1451. // we have to manually patch the path in it.
  1452. if (isSafari && config.twitterBlueChecks == 'replace') {
  1453. $svg.firstElementChild.firstElementChild.setAttribute('d', Svgs.BLUE_LOGO_PATH)
  1454. }
  1455. }
  1456.  
  1457. /**
  1458. * @param {Element} $svgPath
  1459. */
  1460. function twitterLogo($svgPath) {
  1461. // Safari doesn't support using `d: path(…)` to replace paths in an SVG, so
  1462. // we have to manually patch the path in it.
  1463. $svgPath.setAttribute('d', Svgs.TWITTER_LOGO_PATH)
  1464. $svgPath.parentElement.classList.add('tnt_logo')
  1465. }
  1466.  
  1467. /**
  1468. * @param {string} str
  1469. * @return {string}
  1470. */
  1471. function dedent(str) {
  1472. str = str.replace(/^[ \t]*\r?\n/, '')
  1473. let indent = /^[ \t]+/m.exec(str)
  1474. if (indent) str = str.replace(new RegExp('^' + indent[0], 'gm'), '')
  1475. return str.replace(/(\r?\n)[ \t]+$/, '$1')
  1476. }
  1477.  
  1478. /**
  1479. * @param {string} name
  1480. * @param {import("./types").Disconnectable[]} observers
  1481. */
  1482. function disconnectObserver(name, observers) {
  1483. for (let i = observers.length -1; i >= 0; i--) {
  1484. let observer = observers[i]
  1485. if ('name' in observer && observer.name == name) {
  1486. observer.disconnect()
  1487. observers.splice(i, 1)
  1488. log(`disconnected ${name} ${observers === pageObservers ? 'page' : 'modal'} observer`)
  1489. }
  1490. }
  1491. }
  1492.  
  1493. function disconnectModalObserver(name) {
  1494. disconnectObserver(name, modalObservers)
  1495. }
  1496.  
  1497. function disconnectAllModalObservers() {
  1498. if (modalObservers.length > 0) {
  1499. log(
  1500. `disconnecting ${modalObservers.length} modal observer${s(modalObservers.length)}`,
  1501. modalObservers.map(observer => observer['name'])
  1502. )
  1503. modalObservers.forEach(observer => observer.disconnect())
  1504. modalObservers = []
  1505. }
  1506. }
  1507.  
  1508. function disconnectPageObserver(name) {
  1509. disconnectObserver(name, pageObservers)
  1510. }
  1511.  
  1512. /**
  1513. * @param {MutationRecord[]} mutations
  1514. * @param {($el: Node) => boolean | HTMLElement} fn - return `true` to use [$el]
  1515. * as the result, or return a different HTMLElement to use it as the result.
  1516. * @returns {Node | HTMLElement | null}
  1517. */
  1518. function findAddedNode(mutations, fn) {
  1519. for (let mutation of mutations) {
  1520. for (let el of mutation.addedNodes) {
  1521. let result = fn(el)
  1522. if (result) {
  1523. return result === true ? el : result
  1524. }
  1525. }
  1526. }
  1527. return null
  1528. }
  1529.  
  1530. /**
  1531. * @param {string} selector
  1532. * @param {{
  1533. * name?: string
  1534. * stopIf?: () => boolean
  1535. * timeout?: number
  1536. * context?: Document | HTMLElement
  1537. * }?} options
  1538. * @returns {Promise<HTMLElement | null>}
  1539. */
  1540. function getElement(selector, {
  1541. name = null,
  1542. stopIf = null,
  1543. timeout = Infinity,
  1544. context = document,
  1545. } = {}) {
  1546. return new Promise((resolve) => {
  1547. let startTime = Date.now()
  1548. let rafId
  1549. let timeoutId
  1550.  
  1551. function stop($element, reason) {
  1552. if ($element == null) {
  1553. warn(`stopped waiting for ${name || selector} after ${reason}`)
  1554. }
  1555. else if (Date.now() > startTime) {
  1556. log(`${name || selector} appeared after ${Date.now() - startTime}ms`)
  1557. }
  1558. if (rafId) {
  1559. cancelAnimationFrame(rafId)
  1560. }
  1561. if (timeoutId) {
  1562. clearTimeout(timeoutId)
  1563. }
  1564. resolve($element)
  1565. }
  1566.  
  1567. if (timeout !== Infinity) {
  1568. timeoutId = setTimeout(stop, timeout, null, `${timeout}ms timeout`)
  1569. }
  1570.  
  1571. function queryElement() {
  1572. let $element = context.querySelector(selector)
  1573. if ($element) {
  1574. stop($element)
  1575. }
  1576. else if (stopIf?.() === true) {
  1577. stop(null, 'stopIf condition met')
  1578. }
  1579. else {
  1580. rafId = requestAnimationFrame(queryElement)
  1581. }
  1582. }
  1583.  
  1584. queryElement()
  1585. })
  1586. }
  1587.  
  1588. /**
  1589. * Gets cached user info from React state.
  1590. * @returns {import("./types").UserInfoObject}
  1591. */
  1592. function getUserInfo() {
  1593. /** @type {import("./types").UserInfoObject} */
  1594. let userInfo = {}
  1595. let reactRootContainer = ($reactRoot?.wrappedJSObject ? $reactRoot.wrappedJSObject : $reactRoot)?._reactRootContainer
  1596. if (reactRootContainer) {
  1597. let userEntities = reactRootContainer?._internalRoot?.current?.memoizedState?.element?.props?.children?.props?.store?.getState()?.entities?.users?.entities
  1598. if (userEntities) {
  1599. for (let user of Object.values(userEntities)) {
  1600. userInfo[user.screen_name] = {
  1601. following: user.following,
  1602. followedBy: user.followed_by,
  1603. followersCount: user.followers_count,
  1604. shyBlue: false,
  1605. }
  1606. }
  1607. } else {
  1608. warn('user entities not found')
  1609. }
  1610. } else {
  1611. warn('React root container not found')
  1612. }
  1613. return userInfo
  1614. }
  1615.  
  1616. /**
  1617. * @param {import("./types").Disconnectable[]} observers
  1618. * @param {string} name
  1619. */
  1620. function isObserving(observers, name) {
  1621. return observers.some(observer => 'name' in observer && observer.name == name)
  1622. }
  1623.  
  1624. function log(...args) {
  1625. if (debug) {
  1626. console.log(`${currentPage ? `(${
  1627. currentPage.length < 70 ? currentPage : currentPage.slice(0, 70) + '…'
  1628. })` : ''}`, ...args)
  1629. }
  1630. }
  1631.  
  1632. function warn(...args) {
  1633. if (debug) {
  1634. console.log(`❗ ${currentPage ? `(${currentPage})` : ''}`, ...args)
  1635. }
  1636. }
  1637.  
  1638. function error(...args) {
  1639. console.log(`❌ ${currentPage ? `(${currentPage})` : ''}`, ...args)
  1640. }
  1641.  
  1642. /**
  1643. * @param {() => boolean} condition
  1644. * @returns {() => boolean}
  1645. */
  1646. function not(condition) {
  1647. return () => !condition()
  1648. }
  1649.  
  1650. /**
  1651. * Convenience wrapper for the MutationObserver API - the callback is called
  1652. * immediately to support using an observer and its options as a trigger for any
  1653. * change, without looking at MutationRecords.
  1654. * @param {Node} $element
  1655. * @param {MutationCallback} callback
  1656. * @param {string} name
  1657. * @param {MutationObserverInit} options
  1658. * @return {import("./types").NamedMutationObserver}
  1659. */
  1660. function observeElement($element, callback, name, options = {childList: true}) {
  1661. if (name) {
  1662. if (options.childList && callback.length > 0) {
  1663. log(`observing ${name}`, $element)
  1664. } else {
  1665. log (`observing ${name}`)
  1666. }
  1667. }
  1668.  
  1669. let observer = new MutationObserver(callback)
  1670. callback([], observer)
  1671. observer.observe($element, options)
  1672. observer['name'] = name
  1673. return observer
  1674. }
  1675.  
  1676. /**
  1677. * @param {string} page
  1678. * @returns {() => boolean}
  1679. */
  1680. function pageIsNot(page) {
  1681. return () => page != currentPage
  1682. }
  1683.  
  1684. /**
  1685. * @param {string} path
  1686. * @returns {() => boolean}
  1687. */
  1688. function pathIsNot(path) {
  1689. return () => path != currentPath
  1690. }
  1691.  
  1692. /**
  1693. * @param {number} n
  1694. * @returns {string}
  1695. */
  1696. function s(n) {
  1697. return n == 1 ? '' : 's'
  1698. }
  1699.  
  1700. /**
  1701. * @param {Element} $tweetButtonText
  1702. */
  1703. function setTweetButtonText($tweetButtonText) {
  1704. let currentText = $tweetButtonText.textContent
  1705. if (currentText == getString('TWEET') || currentText == getString('TWEET_ALL')) return
  1706. $tweetButtonText.textContent = currentText == getString('POST_ALL') ? getString('TWEET_ALL') : getString('TWEET')
  1707. }
  1708.  
  1709. function storeConfigChanges(changes) {
  1710. window.postMessage({type: 'tntConfigChange', changes})
  1711. }
  1712. //#endregion
  1713.  
  1714. //#region Global observers
  1715. const checkReactNativeStylesheet = (() => {
  1716. /** @type {number} */
  1717. let startTime
  1718.  
  1719. return function checkReactNativeStylesheet() {
  1720. if (startTime == null) {
  1721. startTime = Date.now()
  1722. }
  1723.  
  1724. let $style = /** @type {HTMLStyleElement} */ (document.querySelector('style#react-native-stylesheet'))
  1725. if (!$style) {
  1726. warn('React Native stylesheet not found')
  1727. return
  1728. }
  1729.  
  1730. for (let rule of $style.sheet.cssRules) {
  1731. if (!(rule instanceof CSSStyleRule)) continue
  1732.  
  1733. if (fontFamilyRule == null &&
  1734. rule.style.fontFamily &&
  1735. rule.style.fontFamily.includes('TwitterChirp')) {
  1736. fontFamilyRule = rule
  1737. log('found Chirp fontFamily CSS rule in React Native stylesheet')
  1738. configureFont()
  1739. }
  1740.  
  1741. if (themeColor == null &&
  1742. rule.style.backgroundColor &&
  1743. THEME_COLORS.has(rule.style.backgroundColor)) {
  1744. themeColor = rule.style.backgroundColor
  1745. localStorage.lastThemeColor = themeColor
  1746. log(`found initial theme color in React Native stylesheet: ${themeColor}`)
  1747. configureThemeCss()
  1748. }
  1749. }
  1750.  
  1751. let elapsedTime = Date.now() - startTime
  1752. if (fontFamilyRule == null || themeColor == null) {
  1753. if (elapsedTime < 3000) {
  1754. setTimeout(checkReactNativeStylesheet, 100)
  1755. } else {
  1756. warn(`stopped checking React Native stylesheet after ${elapsedTime}ms`)
  1757. }
  1758. } else {
  1759. log(`finished checking React Native stylesheet in ${elapsedTime}ms`)
  1760. }
  1761. }
  1762. })()
  1763.  
  1764. /**
  1765. * When the "Background" setting is changed in "Customize your view", <body>'s
  1766. * backgroundColor is changed and the app is re-rendered, so we need to
  1767. * re-process the current page.
  1768. */
  1769. function observeBodyBackgroundColor() {
  1770. let lastBackgroundColor = null
  1771.  
  1772. observeElement($body, () => {
  1773. let backgroundColor = $body.style.backgroundColor
  1774. if (backgroundColor == lastBackgroundColor) return
  1775.  
  1776. $body.classList.toggle('Default', backgroundColor == 'rgb(255, 255, 255)')
  1777. $body.classList.toggle('Dim', backgroundColor == 'rgb(21, 32, 43)')
  1778. $body.classList.toggle('LightsOut', backgroundColor == 'rgb(0, 0, 0)')
  1779.  
  1780. if (lastBackgroundColor != null) {
  1781. log('Background setting changed - re-processing current page')
  1782. observePopups()
  1783. observeSideNavTweetButton()
  1784. processCurrentPage()
  1785. }
  1786. lastBackgroundColor = backgroundColor
  1787. }, '<body> style attribute for background colour changes', {
  1788. attributes: true,
  1789. attributeFilter: ['style']
  1790. })
  1791. }
  1792.  
  1793. /**
  1794. * When the "Color" setting is changed in "Customize your view", the app
  1795. * re-renders from a certain point, so we need to re-process the current page.
  1796. */
  1797. async function observeColor() {
  1798. let $colorRerenderBoundary = await getElement('#react-root > div > div')
  1799.  
  1800. observeElement($colorRerenderBoundary, async () => {
  1801. if (location.pathname != PagePaths.CUSTOMIZE_YOUR_VIEW) return
  1802.  
  1803. let $doneButton = await getElement(desktop ? Selectors.DISPLAY_DONE_BUTTON_DESKTOP : Selectors.DISPLAY_DONE_BUTTON_MOBILE, {
  1804. name: 'Done button',
  1805. stopIf: not(() => location.pathname == PagePaths.CUSTOMIZE_YOUR_VIEW),
  1806. })
  1807. if (!$doneButton) return
  1808.  
  1809. let color = getComputedStyle($doneButton).backgroundColor
  1810. if (color == themeColor) return
  1811.  
  1812. log('Color setting changed - re-processing current page')
  1813. themeColor = color
  1814. localStorage.lastThemeColor = color
  1815. configureThemeCss()
  1816. observePopups()
  1817. observeSideNavTweetButton()
  1818. processCurrentPage()
  1819. }, 'Color change re-render boundary')
  1820. }
  1821.  
  1822. /**
  1823. * When the "Font size" setting is changed in "Customize your view" on desktop,
  1824. * `<html>`'s fontSize is changed and the app is re-rendered.
  1825. */
  1826. const observeHtmlFontSize = (() => {
  1827. /** @type {MutationObserver} */
  1828. let fontSizeObserver
  1829.  
  1830. return function observeHtmlFontSize() {
  1831. if (fontSizeObserver) {
  1832. fontSizeObserver.disconnect()
  1833. fontSizeObserver = null
  1834. }
  1835.  
  1836. if (mobile) return
  1837.  
  1838. let lastOverflow = ''
  1839.  
  1840. fontSizeObserver = observeElement($html, () => {
  1841. if (!$html.style.fontSize) return
  1842.  
  1843. let hasFontSizeChanged = fontSize != null && $html.style.fontSize != fontSize
  1844.  
  1845. if ($html.style.fontSize != fontSize) {
  1846. fontSize = $html.style.fontSize
  1847. log(`<html> fontSize has changed to ${fontSize}`)
  1848. configureNavFontSizeCss()
  1849. }
  1850.  
  1851. // Ignore overflow changes, which happen when a dialog is shown or hidden
  1852. let hasOverflowChanged = $html.style.overflow != lastOverflow
  1853. lastOverflow = $html.style.overflow
  1854. if (!hasFontSizeChanged && hasOverflowChanged) {
  1855. log('ignoring <html> style overflow change')
  1856. return
  1857. }
  1858.  
  1859. // When you switch between the smallest "Font size" options, <html>'s
  1860. // style is updated but the font size is kept the same - re-process just
  1861. // in case.
  1862. if (hasFontSizeChanged ||
  1863. location.pathname == PagePaths.CUSTOMIZE_YOUR_VIEW && fontSize == '14px') {
  1864. log('<html> style attribute changed, re-processing current page')
  1865. observePopups()
  1866. observeSideNavTweetButton()
  1867. processCurrentPage()
  1868. }
  1869. }, '<html> style attribute for font size changes', {
  1870. attributes: true,
  1871. attributeFilter: ['style']
  1872. })
  1873. }
  1874. })()
  1875.  
  1876. async function observeDesktopComposeTweetModal($popup) {
  1877. let $modalDialog = await getElement('div[role="dialog"][aria-labelledby]', {
  1878. context: $popup,
  1879. stopIf: () => !isDesktopComposeTweetModalOpen
  1880. })
  1881. if (!$modalDialog) return
  1882.  
  1883. /** @type {import("./types").Disconnectable} */
  1884. let tweetButtonObserver
  1885.  
  1886. function disconnectTweetButtonObserver() {
  1887. if (tweetButtonObserver) {
  1888. log('disconnecting tweet button dialog observer')
  1889. tweetButtonObserver.disconnect()
  1890. modalObservers.splice(modalObservers.indexOf(tweetButtonObserver), 1)
  1891. tweetButtonObserver = null
  1892. }
  1893. }
  1894.  
  1895. let waitingForTweetButton = false
  1896.  
  1897. modalObservers.push(
  1898. observeElement($modalDialog, async () => {
  1899. if (waitingForTweetButton) return
  1900.  
  1901. waitingForTweetButton = true
  1902. let $tweetButtonText = await getElement('div[data-testid="tweetButton"] span > span', {
  1903. context: $modalDialog,
  1904. name: 'tweet button',
  1905. timeout: 500,
  1906. })
  1907. waitingForTweetButton = false
  1908.  
  1909. if (!$tweetButtonText) {
  1910. disconnectTweetButtonObserver()
  1911. return
  1912. }
  1913.  
  1914. setTweetButtonText($tweetButtonText)
  1915.  
  1916. // The button will be moved around when multiple Tweets are being edited
  1917. tweetButtonObserver = observeElement($modalDialog, (mutations) => {
  1918. for (let mutation of mutations) {
  1919. for (let $addedNode of mutation.addedNodes) {
  1920. let $tweetButtonText = $addedNode.querySelector?.('div[data-testid="tweetButton"] span > span')
  1921. if ($tweetButtonText) {
  1922. setTweetButtonText($tweetButtonText)
  1923. }
  1924. }
  1925. }
  1926. }, 'tweet button dialog', {childList: true, subtree: true})
  1927. modalObservers.push(tweetButtonObserver)
  1928. }, 'compose tweet modal dialog')
  1929. )
  1930. }
  1931.  
  1932. /**
  1933. * @param {HTMLElement} $popup
  1934. */
  1935. async function observeDesktopModalTimeline($popup) {
  1936. // Media modals remember if they were previously collapsed, so we could be
  1937. // waiting for the initial timeline to be either rendered or expanded.
  1938. let $initialTimeline = await getElement(Selectors.MODAL_TIMELINE, {
  1939. context: $popup,
  1940. name: 'initial modal timeline',
  1941. stopIf: () => !isDesktopMediaModalOpen,
  1942. })
  1943.  
  1944. if ($initialTimeline == null) return
  1945.  
  1946. /**
  1947. * @param {HTMLElement} $timeline
  1948. */
  1949. function observeModalTimelineItems($timeline) {
  1950. disconnectModalObserver('modal timeline')
  1951. modalObservers.push(
  1952. observeElement($timeline, () => onIndividualTweetTimelineChange($timeline, {observers: modalObservers}), 'modal timeline')
  1953. )
  1954.  
  1955. // If other media in the modal is clicked, the timeline is replaced.
  1956. disconnectModalObserver('modal timeline parent')
  1957. modalObservers.push(
  1958. observeElement($timeline.parentElement, (mutations) => {
  1959. mutations.forEach((mutation) => {
  1960. mutation.addedNodes.forEach((/** @type {HTMLElement} */ $newTimeline) => {
  1961. log('modal timeline replaced')
  1962. disconnectModalObserver('modal timeline')
  1963. modalObservers.push(
  1964. observeElement($newTimeline, () => onIndividualTweetTimelineChange($newTimeline, {observers: modalObservers}), 'modal timeline')
  1965. )
  1966. })
  1967. })
  1968. }, 'modal timeline parent')
  1969. )
  1970. }
  1971.  
  1972. /**
  1973. * @param {HTMLElement} $timeline
  1974. */
  1975. function observeModalTimeline($timeline) {
  1976. // If the inital timeline doesn't have a style attribute it's a placeholder
  1977. if ($timeline.hasAttribute('style')) {
  1978. observeModalTimelineItems($timeline)
  1979. }
  1980. else {
  1981. log('waiting for modal timeline')
  1982. let startTime = Date.now()
  1983. modalObservers.push(
  1984. observeElement($timeline.parentElement, (mutations) => {
  1985. mutations.forEach((mutation) => {
  1986. mutation.addedNodes.forEach((/** @type {HTMLElement} */ $timeline) => {
  1987. disconnectModalObserver('modal timeline parent')
  1988. if (Date.now() > startTime) {
  1989. log(`modal timeline appeared after ${Date.now() - startTime}ms`, $timeline)
  1990. }
  1991. observeModalTimelineItems($timeline)
  1992. })
  1993. })
  1994. }, 'modal timeline parent')
  1995. )
  1996. }
  1997. }
  1998.  
  1999. // The modal timeline can be expanded and collapsed
  2000. let $expandedContainer = $initialTimeline.closest('[aria-expanded="true"]')
  2001. modalObservers.push(
  2002. observeElement($expandedContainer.parentElement, async (mutations) => {
  2003. if (mutations.some(mutation => mutation.removedNodes.length > 0)) {
  2004. log('modal timeline collapsed')
  2005. disconnectModalObserver('modal timeline parent')
  2006. disconnectModalObserver('modal timeline')
  2007. }
  2008. else if (mutations.some(mutation => mutation.addedNodes.length > 0)) {
  2009. log('modal timeline expanded')
  2010. let $timeline = await getElement(Selectors.MODAL_TIMELINE, {
  2011. context: $popup,
  2012. name: 'expanded modal timeline',
  2013. stopIf: () => !isDesktopMediaModalOpen,
  2014. })
  2015. if ($timeline == null) return
  2016. observeModalTimeline($timeline)
  2017. }
  2018. }, 'collapsible modal timeline container')
  2019. )
  2020.  
  2021. observeModalTimeline($initialTimeline)
  2022. }
  2023.  
  2024. const observeFavicon = (() => {
  2025. /** @type {HTMLElement} */
  2026. let $shortcutIcon
  2027. /** @type {MutationObserver} */
  2028. let shortcutIconObserver
  2029.  
  2030. async function observeFavicon() {
  2031. if ($shortcutIcon == null) {
  2032. $shortcutIcon = await getElement('link[rel="shortcut icon"]', {name: 'shortcut icon'})
  2033. }
  2034.  
  2035. if (!config.replaceLogo) {
  2036. if (shortcutIconObserver != null) {
  2037. shortcutIconObserver.disconnect()
  2038. shortcutIconObserver = null
  2039. if ($shortcutIcon.getAttribute('href').startsWith('data:')) {
  2040. $shortcutIcon.setAttribute('href', `//abs.twimg.com/favicons/twitter${currentNotificationCount ? '-pip' : ''}.3.ico`)
  2041. }
  2042. }
  2043. return
  2044. }
  2045.  
  2046. shortcutIconObserver = observeElement($shortcutIcon, () => {
  2047. let href = $shortcutIcon.getAttribute('href')
  2048. if (href.startsWith('data:')) return
  2049. $shortcutIcon.setAttribute('href', href.includes('pip') ? Images.TWITTER_PIP_FAVICON : Images.TWITTER_FAVICON)
  2050. }, 'shortcut icon href', {
  2051. attributes: true,
  2052. attributeFilter: ['href']
  2053. })
  2054. }
  2055.  
  2056. observeFavicon.updatePip = function(showPip) {
  2057. if (!$shortcutIcon) return
  2058. let icon = showPip ? Images.TWITTER_PIP_FAVICON : Images.TWITTER_FAVICON
  2059. if ($shortcutIcon.getAttribute('href') != icon) {
  2060. $shortcutIcon.setAttribute('href', icon)
  2061. }
  2062. }
  2063.  
  2064. return observeFavicon
  2065. })()
  2066.  
  2067. /**
  2068. * Twitter displays popups in the #layers element. It also reuses open popups
  2069. * in certain cases rather than creating one from scratch, so we also need to
  2070. * deal with nested popups, e.g. if you hover over the caret menu in a Tweet, a
  2071. * popup will be created to display a "More" tootip and clicking to open the
  2072. * menu will create a nested element in the existing popup, whereas clicking the
  2073. * caret quickly without hovering over it will display the menu in new popup.
  2074. * Use of nested popups can also differ between desktop and mobile, so features
  2075. * need to be mindful of that.
  2076. */
  2077. const observePopups = (() => {
  2078. /** @type {MutationObserver} */
  2079. let popupObserver
  2080. /** @type {WeakMap<HTMLElement, {disconnect()}>} */
  2081. let nestedObservers = new WeakMap()
  2082.  
  2083. return async function observePopups() {
  2084. if (popupObserver) {
  2085. popupObserver.disconnect()
  2086. popupObserver = null
  2087. }
  2088.  
  2089. let $layers = await getElement('#layers', {
  2090. name: 'layers',
  2091. })
  2092.  
  2093. // There can be only one
  2094. if (popupObserver) {
  2095. popupObserver.disconnect()
  2096. }
  2097.  
  2098. popupObserver = observeElement($layers, (mutations) => {
  2099. mutations.forEach((mutation) => {
  2100. mutation.addedNodes.forEach((/** @type {HTMLElement} */ $el) => {
  2101. let nestedObserver = onPopup($el)
  2102. if (nestedObserver) {
  2103. nestedObservers.set($el, nestedObserver)
  2104. }
  2105. })
  2106. mutation.removedNodes.forEach((/** @type {HTMLElement} */ $el) => {
  2107. if (nestedObservers.has($el)) {
  2108. nestedObservers.get($el).disconnect()
  2109. nestedObservers.delete($el)
  2110. }
  2111. })
  2112. })
  2113. }, 'popup container')
  2114. }
  2115. })()
  2116.  
  2117. async function observeTitle() {
  2118. let $title = await getElement('title', {name: '<title>'})
  2119. observeElement($title, () => {
  2120. let title = $title.textContent
  2121. if (config.replaceLogo && (ltr ? /X$/ : /^(?:\(\d+\+?\) )?X/).test(title)) {
  2122. document.title = title.replace(ltr ? /X$/ : 'X', getString('TWITTER'))
  2123. return
  2124. }
  2125. if (observingPageChanges) {
  2126. onTitleChange(title)
  2127. }
  2128. }, '<title>')
  2129. }
  2130. //#endregion
  2131.  
  2132. //#region Page observers
  2133. /**
  2134. * If a profile is blocked its media box won't appear, add a `Blocked` class to
  2135. * `<body>` to hide sidebar content.
  2136. * @param {string} currentPage
  2137. */
  2138. async function observeProfileBlockedStatus(currentPage) {
  2139. let $buttonContainer = await getElement(`[data-testid="userActions"] ~ [data-testid="placementTracking"], a[href="${PagePaths.PROFILE_SETTINGS}"]`, {
  2140. name: 'Follow / Unblock button container or Edit profile button',
  2141. stopIf: pageIsNot(currentPage),
  2142. })
  2143. if ($buttonContainer == null) return
  2144.  
  2145. if ($buttonContainer.hasAttribute('href')) {
  2146. log('on own profile page')
  2147. $body.classList.remove('Blocked')
  2148. return
  2149. }
  2150.  
  2151. pageObservers.push(
  2152. observeElement($buttonContainer, () => {
  2153. let isBlocked = (/** @type {HTMLElement} */ ($buttonContainer.querySelector('[role="button"]'))?.dataset.testid ?? '').endsWith('unblock')
  2154. $body.classList.toggle('Blocked', isBlocked)
  2155. }, 'Follow / Unblock button container')
  2156. )
  2157. }
  2158.  
  2159. /**
  2160. * If an account has never tweeted any media, add a `NoMedia` class to `<body>`
  2161. * to hide the "You might like" section which will appear where the media box
  2162. * would have been.
  2163. * @param {string} currentPage
  2164. */
  2165. async function observeProfileSidebar(currentPage) {
  2166. let $sidebarContent = await getElement(Selectors.SIDEBAR_WRAPPERS, {
  2167. name: 'profile sidebar content container',
  2168. stopIf: pageIsNot(currentPage),
  2169. })
  2170. if ($sidebarContent == null) return
  2171.  
  2172. let sidebarContentObserver = observeElement($sidebarContent, () => {
  2173. $body.classList.toggle('NoMedia', $sidebarContent.childElementCount == 5)
  2174. }, 'profile sidebar content container')
  2175. pageObservers.push(sidebarContentObserver)
  2176.  
  2177. // On initial appearance, the sidebar is injected with static HTML with
  2178. // spinner placeholders, which gets replaced. When this happens we need to
  2179. // observe the new content container instead.
  2180. let $sidebarContentParent = $sidebarContent.parentElement
  2181. pageObservers.push(
  2182. observeElement($sidebarContentParent, (mutations) => {
  2183. let sidebarContentReplaced = mutations.some(mutation => Array.from(mutation.removedNodes).includes($sidebarContent))
  2184. if (sidebarContentReplaced) {
  2185. log('profile sidebar content container replaced, observing new container')
  2186. sidebarContentObserver.disconnect()
  2187. pageObservers.splice(pageObservers.indexOf(sidebarContentObserver), 1)
  2188. $sidebarContent = /** @type {HTMLElement} */ ($sidebarContentParent.firstElementChild)
  2189. pageObservers.push(
  2190. observeElement($sidebarContent, () => {
  2191. $body.classList.toggle('NoMedia', $sidebarContent.childElementCount == 5)
  2192. }, 'sidebar content container')
  2193. )
  2194. }
  2195. }, 'sidebar content container parent')
  2196. )
  2197. }
  2198.  
  2199. async function observeSidebar() {
  2200. let $primaryColumn = await getElement(Selectors.PRIMARY_COLUMN, {
  2201. name: 'primary column'
  2202. })
  2203. let $sidebarContainer = $primaryColumn.parentElement
  2204. pageObservers.push(
  2205. observeElement($sidebarContainer, () => {
  2206. let $sidebar = $sidebarContainer.querySelector(Selectors.SIDEBAR)
  2207. log(`sidebar ${$sidebar ? 'appeared' : 'disappeared'}`)
  2208. $body.classList.toggle('Sidebar', Boolean($sidebar))
  2209. if ($sidebar && config.twitterBlueChecks != 'ignore' && !isOnSearchPage() && !isOnExplorePage()) {
  2210. observeSearchForm()
  2211. }
  2212. }, 'sidebar container')
  2213. )
  2214. }
  2215.  
  2216. const observeSideNavTweetButton = (() => {
  2217. /** @type {MutationObserver} */
  2218. let observer
  2219.  
  2220. return async function observeSideNavTweetButton() {
  2221. if (observer) {
  2222. observer.disconnect()
  2223. observer = null
  2224. }
  2225.  
  2226. if (!desktop || !config.replaceLogo) return
  2227.  
  2228. // This element is updated when text is added or removed on resize
  2229. let $buttonTextContainer = await getElement('a[data-testid="SideNav_NewTweet_Button"] > div > span')
  2230. observer = observeElement($buttonTextContainer, () => {
  2231. if ($buttonTextContainer.childElementCount > 0) {
  2232. let $buttonText = /** @type {HTMLElement} */ ($buttonTextContainer.querySelector('span > span'))
  2233. if ($buttonText) {
  2234. setTweetButtonText($buttonText)
  2235. } else {
  2236. warn('could not find tweet button text')
  2237. }
  2238. }
  2239. }, 'sidenav tweet button')
  2240. }
  2241. })()
  2242.  
  2243. async function observeSearchForm() {
  2244. let $searchForm = await getElement('form[role="search"]', {
  2245. name: 'search form',
  2246. stopIf: pageIsNot(currentPage),
  2247. // The sidebar on Profile pages can be really slow
  2248. timeout: 2000,
  2249. })
  2250. if (!$searchForm) return
  2251. let $results = /** @type {HTMLElement} */ ($searchForm.lastElementChild)
  2252. pageObservers.push(
  2253. observeElement($results, () => {
  2254. processBlueChecks($results)
  2255. }, 'search results', {childList: true, subtree: true})
  2256. )
  2257. }
  2258.  
  2259. /**
  2260. * @param {string} page
  2261. * @param {import("./types").TimelineOptions?} options
  2262. */
  2263. async function observeTimeline(page, options = {}) {
  2264. let {
  2265. isTabbed = false,
  2266. onTabChanged = null,
  2267. onTimelineAppeared = null,
  2268. tabbedTimelineContainerSelector = null,
  2269. timelineSelector = Selectors.TIMELINE,
  2270. } = options
  2271.  
  2272. let $timeline = await getElement(timelineSelector, {
  2273. name: 'initial timeline',
  2274. stopIf: pageIsNot(page),
  2275. })
  2276.  
  2277. if ($timeline == null) return
  2278.  
  2279. /**
  2280. * @param {HTMLElement} $timeline
  2281. */
  2282. function observeTimelineItems($timeline) {
  2283. disconnectPageObserver('timeline')
  2284. pageObservers.push(
  2285. observeElement($timeline, () => onTimelineChange($timeline, page, options), 'timeline')
  2286. )
  2287. onTimelineAppeared?.()
  2288. if (isTabbed) {
  2289. // When a tab which has been viewed before is revisited, the timeline is
  2290. // replaced.
  2291. disconnectPageObserver('timeline parent')
  2292. pageObservers.push(
  2293. observeElement($timeline.parentElement, (mutations) => {
  2294. mutations.forEach((mutation) => {
  2295. mutation.addedNodes.forEach((/** @type {HTMLElement} */ $newTimeline) => {
  2296. disconnectPageObserver('timeline')
  2297. log('tab changed')
  2298. onTabChanged?.()
  2299. pageObservers.push(
  2300. observeElement($newTimeline, () => onTimelineChange($newTimeline, page, options), 'timeline')
  2301. )
  2302. })
  2303. })
  2304. }, 'timeline parent')
  2305. )
  2306. }
  2307. }
  2308.  
  2309. // If the inital timeline doesn't have a style attribute it's a placeholder
  2310. if ($timeline.hasAttribute('style')) {
  2311. observeTimelineItems($timeline)
  2312. }
  2313. else {
  2314. log('waiting for timeline')
  2315. let startTime = Date.now()
  2316. pageObservers.push(
  2317. observeElement($timeline.parentElement, (mutations) => {
  2318. mutations.forEach((mutation) => {
  2319. mutation.addedNodes.forEach((/** @type {HTMLElement} */ $timeline) => {
  2320. disconnectPageObserver('timeline parent')
  2321. if (Date.now() > startTime) {
  2322. log(`timeline appeared after ${Date.now() - startTime}ms`, $timeline)
  2323. }
  2324. observeTimelineItems($timeline)
  2325. })
  2326. })
  2327. }, 'timeline parent')
  2328. )
  2329. }
  2330.  
  2331. // On some tabbed timeline pages, the first time a new tab is navigated to,
  2332. // the element containing the timeline is replaced with a loading spinner.
  2333. if (isTabbed && tabbedTimelineContainerSelector) {
  2334. let $tabbedTimelineContainer = document.querySelector(tabbedTimelineContainerSelector)
  2335. if ($tabbedTimelineContainer) {
  2336. let waitingForNewTimeline = false
  2337. pageObservers.push(
  2338. observeElement($tabbedTimelineContainer, async (mutations) => {
  2339. // This is going to fire twice on a new tab, as the spinner is added
  2340. // then replaced with the new timeline element.
  2341. if (!mutations.some(mutation => mutation.addedNodes.length > 0) || waitingForNewTimeline) return
  2342.  
  2343. waitingForNewTimeline = true
  2344. let $newTimeline = await getElement(timelineSelector, {
  2345. name: 'new timeline',
  2346. stopIf: pageIsNot(page),
  2347. })
  2348. waitingForNewTimeline = false
  2349. if (!$newTimeline) return
  2350.  
  2351. log('tab changed')
  2352. onTabChanged?.()
  2353. observeTimelineItems($newTimeline)
  2354. }, 'tabbed timeline container')
  2355. )
  2356. } else {
  2357. warn('tabbed timeline container not found')
  2358. }
  2359. }
  2360. }
  2361.  
  2362. /**
  2363. * @param {string} page
  2364. */
  2365. async function observeIndividualTweetTimeline(page) {
  2366. let $timeline = await getElement(Selectors.TIMELINE, {
  2367. name: 'initial individual tweet timeline',
  2368. stopIf: pageIsNot(page),
  2369. })
  2370.  
  2371. if ($timeline == null) return
  2372.  
  2373. /**
  2374. * @param {HTMLElement} $timeline
  2375. */
  2376. function observeTimelineItems($timeline) {
  2377. pageObservers.push(
  2378. observeElement($timeline, () => onIndividualTweetTimelineChange($timeline, {observers: pageObservers}), 'individual tweet timeline')
  2379. )
  2380. }
  2381.  
  2382. // If the inital timeline doesn't have a style attribute it's a placeholder
  2383. if ($timeline.hasAttribute('style')) {
  2384. observeTimelineItems($timeline)
  2385. }
  2386. else {
  2387. log('waiting for individual tweet timeline')
  2388. let startTime = Date.now()
  2389. pageObservers.push(
  2390. observeElement($timeline.parentElement, (mutations) => {
  2391. mutations.forEach((mutation) => {
  2392. mutation.addedNodes.forEach((/** @type {HTMLElement} */ $timeline) => {
  2393. disconnectPageObserver('individual tweet timeline parent')
  2394. if (Date.now() > startTime) {
  2395. log(`individual tweet timeline appeared after ${Date.now() - startTime}ms`, $timeline)
  2396. }
  2397. observeTimelineItems($timeline)
  2398. })
  2399. })
  2400. }, 'individual tweet timeline parent')
  2401. )
  2402. }
  2403. }
  2404.  
  2405. /**
  2406. * @param {{
  2407. * context?: HTMLElement
  2408. * initialPath: string
  2409. * observers: import("./types").Disconnectable[]
  2410. * }} options
  2411. */
  2412. async function observeUserListTimeline({context, initialPath, observers}) {
  2413. if (config.twitterBlueChecks == 'ignore') return
  2414.  
  2415. let $timeline = await getElement('h1[id^="accessible-list"] + div > div > div > div', {
  2416. context,
  2417. name: 'user list timeline',
  2418. stopIf: not(() => initialPath == location.pathname),
  2419. })
  2420. if (!$timeline) return
  2421.  
  2422. observers.push(
  2423. observeElement($timeline, () => {
  2424. processBlueChecks($timeline)
  2425. }, 'user list timeline')
  2426. )
  2427. }
  2428. //#endregion
  2429.  
  2430. //#region Tweak functions
  2431. /**
  2432. * Add an "Add muted word" menu item after the given link which takes you
  2433. * straight to entering a new muted word (by clicking its way through all the
  2434. * individual screens!).
  2435. * @param {HTMLElement} $link
  2436. * @param {string} linkSelector
  2437. */
  2438. async function addAddMutedWordMenuItem($link, linkSelector) {
  2439. log('adding "Add muted word" menu item')
  2440.  
  2441. // Wait for the dropdown to appear on desktop
  2442. if (desktop) {
  2443. $link = await getElement(`#layers div[data-testid="Dropdown"] ${linkSelector}`, {
  2444. name: 'rendered menu item',
  2445. timeout: 100,
  2446. })
  2447. if (!$link) return
  2448. }
  2449.  
  2450. let $addMutedWord = /** @type {HTMLElement} */ ($link.parentElement.cloneNode(true))
  2451. $addMutedWord.classList.add('tnt_menu_item')
  2452. $addMutedWord.querySelector('a').href = PagePaths.ADD_MUTED_WORD
  2453. $addMutedWord.querySelector('span').textContent = getString('ADD_MUTED_WORD')
  2454. $addMutedWord.querySelector('svg').innerHTML = Svgs.MUTE
  2455. $addMutedWord.addEventListener('click', (e) => {
  2456. e.preventDefault()
  2457. addMutedWord()
  2458. })
  2459. $link.parentElement.insertAdjacentElement('afterend', $addMutedWord)
  2460. }
  2461.  
  2462. function addCaretMenuListenerForQuoteTweet($tweet) {
  2463. let $caret = /** @type {HTMLElement} */ ($tweet.querySelector('[data-testid="caret"]'))
  2464. if ($caret && !$caret.dataset.tweakNewTwitterListener) {
  2465. $caret.addEventListener('click', () => {
  2466. quotedTweet = getQuotedTweetDetails($tweet, {getText: true})
  2467. })
  2468. $caret.dataset.tweakNewTwitterListener = 'true'
  2469. }
  2470. }
  2471.  
  2472. /**
  2473. * Add a "Mute this conversation" menu item to a Quote Tweet's menu.
  2474. * @param {HTMLElement} $blockMenuItem
  2475. */
  2476. async function addMuteQuotesMenuItem($blockMenuItem) {
  2477. log('adding "Mute this conversation" menu item')
  2478.  
  2479. // Wait for the menu to render properly on desktop
  2480. if (desktop) {
  2481. $blockMenuItem = await getElement(`:scope > div > div > div > ${Selectors.BLOCK_MENU_ITEM}`, {
  2482. context: $blockMenuItem.parentElement,
  2483. name: 'rendered block menu item',
  2484. timeout: 100,
  2485. })
  2486. if (!$blockMenuItem) return
  2487. }
  2488.  
  2489. let $muteQuotes = /** @type {HTMLElement} */ ($blockMenuItem.previousElementSibling.cloneNode(true))
  2490. $muteQuotes.classList.add('tnt_menu_item')
  2491. $muteQuotes.querySelector('span').textContent = getString('MUTE_THIS_CONVERSATION')
  2492. $muteQuotes.addEventListener('click', (e) => {
  2493. e.preventDefault()
  2494. log('muting quotes of a tweet', quotedTweet)
  2495. config.mutedQuotes = config.mutedQuotes.concat(quotedTweet)
  2496. storeConfigChanges({mutedQuotes: config.mutedQuotes})
  2497. processCurrentPage()
  2498. // Dismiss the menu
  2499. let $menuLayer = /** @type {HTMLElement} */ ($blockMenuItem.closest('[role="group"]')?.firstElementChild?.firstElementChild)
  2500. if (!$menuLayer) {
  2501. log('could not find menu layer to dismiss menu')
  2502. }
  2503. $menuLayer?.click()
  2504. })
  2505.  
  2506. $blockMenuItem.insertAdjacentElement('beforebegin', $muteQuotes)
  2507. }
  2508.  
  2509. async function addMutedWord() {
  2510. if (!document.querySelector('a[href="/settings')) {
  2511. let $settingsAndSupport = /** @type {HTMLElement} */ (document.querySelector('[data-testid="settingsAndSupport"]'))
  2512. $settingsAndSupport?.click()
  2513. }
  2514.  
  2515. for (let path of [
  2516. '/settings',
  2517. '/settings/privacy_and_safety',
  2518. '/settings/mute_and_block',
  2519. '/settings/muted_keywords',
  2520. '/settings/add_muted_keyword',
  2521. ]) {
  2522. let $link = await getElement(`a[href="${path}"]`, {timeout: 500})
  2523. if (!$link) return
  2524. $link.click()
  2525. }
  2526. let $input = await getElement('input[name="keyword"]')
  2527. setTimeout(() => $input.focus(), 100)
  2528. }
  2529.  
  2530. /**
  2531. * Add a "Turn on/off Retweets" menu item to a List's menu.
  2532. * @param {HTMLElement} $switchMenuItem
  2533. */
  2534. async function addToggleListRetweetsMenuItem($switchMenuItem) {
  2535. log('adding "Turn on/off Retweets" menu item')
  2536.  
  2537. // Wait for the menu to render properly on desktop
  2538. if (desktop) {
  2539. $switchMenuItem = await getElement(':scope > div > div > div > [role="menuitem"]', {
  2540. context: $switchMenuItem.parentElement,
  2541. name: 'rendered switch menu item',
  2542. timeout: 100,
  2543. })
  2544. if (!$switchMenuItem) return
  2545. }
  2546.  
  2547. let $toggleRetweets = /** @type {HTMLElement} */ ($switchMenuItem.cloneNode(true))
  2548. $toggleRetweets.classList.add('tnt_menu_item')
  2549. $toggleRetweets.querySelector('span').textContent = getString(`TURN_${config.listRetweets == 'ignore' ? 'OFF' : 'ON'}_RETWEETS`)
  2550. $toggleRetweets.querySelector('svg').innerHTML = config.listRetweets == 'ignore' ? Svgs.RETWEETS_OFF : Svgs.RETWEET
  2551. // Remove subtitle if the cloned menu item has one
  2552. $toggleRetweets.querySelector('div[dir] + div[dir]')?.remove()
  2553. $toggleRetweets.addEventListener('click', (e) => {
  2554. e.preventDefault()
  2555. log('toggling list retweets')
  2556. config.listRetweets = config.listRetweets == 'ignore' ? 'hide' : 'ignore'
  2557. storeConfigChanges({listRetweets: config.listRetweets})
  2558. processCurrentPage()
  2559. // Dismiss the menu
  2560. let $menuLayer = /** @type {HTMLElement} */ ($switchMenuItem.closest('[role="group"]')?.firstElementChild?.firstElementChild)
  2561. if (!$menuLayer) {
  2562. log('could not find menu layer to dismiss menu')
  2563. }
  2564. $menuLayer?.click()
  2565. })
  2566.  
  2567. $switchMenuItem.insertAdjacentElement('beforebegin', $toggleRetweets)
  2568. }
  2569.  
  2570. /**
  2571. * Redirects away from the home timeline if we're on it and it's been disabled.
  2572. * @returns {boolean} `true` if redirected as a result of this call
  2573. */
  2574. function checkforDisabledHomeTimeline() {
  2575. if (config.disableHomeTimeline && location.pathname == '/home') {
  2576. log(`home timeline disabled, redirecting to /${config.disabledHomeTimelineRedirect}`)
  2577. let primaryNavSelector = desktop ? Selectors.PRIMARY_NAV_DESKTOP : Selectors.PRIMARY_NAV_MOBILE
  2578. ;/** @type {HTMLElement} */ (
  2579. document.querySelector(`${primaryNavSelector} a[href="/${config.disabledHomeTimelineRedirect}"]`)
  2580. ).click()
  2581. return true
  2582. }
  2583. }
  2584.  
  2585. const configureCss = (() => {
  2586. let $style
  2587.  
  2588. return function configureCss() {
  2589. if ($style == null) {
  2590. $style = addStyle('features')
  2591. }
  2592. let cssRules = []
  2593. let hideCssSelectors = []
  2594. let menuRole = `[role="${desktop ? 'menu' : 'dialog'}"]`
  2595.  
  2596. // Hover colours for custom menu items
  2597. cssRules.push(`
  2598. body.Default .tnt_menu_item:hover { background-color: rgb(247, 249, 249) !important; }
  2599. body.Dim .tnt_menu_item:hover { background-color: rgb(30, 39, 50) !important; }
  2600. body.LightsOut .tnt_menu_item:hover { background-color: rgb(22, 24, 28) !important; }
  2601. `)
  2602.  
  2603. if (config.alwaysUseLatestTweets && config.hideForYouTimeline) {
  2604. cssRules.push(`
  2605. body.TabbedTimeline ${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} nav div[role="tablist"] > div:first-child {
  2606. flex: 0;
  2607. }
  2608. body.TabbedTimeline ${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} nav div[role="tablist"] > div:first-child > a {
  2609. display: none;
  2610. }
  2611. `)
  2612. }
  2613. if (config.disableTweetTextFormatting) {
  2614. cssRules.push(`
  2615. div[data-testid="tweetText"] span {
  2616. font-style: normal;
  2617. font-weight: normal;
  2618. }
  2619. `)
  2620. }
  2621. if (config.dropdownMenuFontWeight) {
  2622. cssRules.push(`
  2623. [data-testid="${desktop ? 'Dropdown' : 'sheetDialog'}"] [role="menuitem"] [dir] {
  2624. font-weight: normal;
  2625. }
  2626. `)
  2627. }
  2628. if (config.hideAnalyticsNav) {
  2629. hideCssSelectors.push(`${menuRole} a[href*="analytics.twitter.com"]`)
  2630. }
  2631. if (config.hideBookmarkButton) {
  2632. hideCssSelectors.push(
  2633. // Under individual tweets
  2634. '[data-testid="tweet"][tabindex="-1"] [role="group"][id^="id__"] > div:nth-child(4)',
  2635. )
  2636. }
  2637. if (config.hideBookmarksNav) {
  2638. hideCssSelectors.push(`${menuRole} a[href$="/bookmarks"]`)
  2639. }
  2640. if (config.hideCommunitiesNav) {
  2641. hideCssSelectors.push(`${menuRole} a[href$="/communities"]`)
  2642. }
  2643. if (config.hideShareTweetButton) {
  2644. hideCssSelectors.push(
  2645. // Under timeline tweets
  2646. `[data-testid="tweet"][tabindex="0"] [role="group"] > div[style]:not(${TWITTER_MEDIA_ASSIST_BUTTON_SELECTOR})`,
  2647. // Under individual tweets
  2648. `[data-testid="tweet"][tabindex="-1"] [role="group"] > div[style]:not(${TWITTER_MEDIA_ASSIST_BUTTON_SELECTOR})`,
  2649. )
  2650. }
  2651. if (config.hideSubscriptions) {
  2652. hideCssSelectors.push(
  2653. // Subscribe buttons in profile (multiple locations)
  2654. 'body.Profile [role="button"][style*="border-color: rgb(201, 54, 204)"]',
  2655. // Subscriptions count in profile
  2656. 'body.Profile a[href$="/creator-subscriptions/subscriptions"]',
  2657. // Subs tab in profile (3rd of 5, or 6 if they have Highlights)
  2658. 'body.Profile [data-testid="ScrollSnap-List"] > [role="presentation"]:nth-child(3):is(:nth-last-child(3), :nth-last-child(4))',
  2659. // Subscribe button in focused tweet
  2660. '[data-testid="tweet"][tabindex="-1"] [data-testid$="-subscribe"]',
  2661. // "Subscribe to" dropdown item (desktop)
  2662. '[data-testid="Dropdown"] > [data-testid="subscribe"]',
  2663. // "Subscribe to" menu item (mobile)
  2664. '[data-testid="sheetDialog"] > [data-testid="subscribe"]',
  2665. // "Subscriber" indicator in replies from subscribers
  2666. 'body.Default [data-testid="tweet"] [data-testid="userFollowIndicator"][style*="color: rgb(141, 32, 144)"]',
  2667. 'body:is(.Dim, .LightsOut) [data-testid="tweet"] [data-testid="userFollowIndicator"][style*="color: rgb(223, 130, 224)"]',
  2668. // Monetization and Subscriptions items in Settings
  2669. 'body.Settings a[href="/settings/monetization"]',
  2670. 'body.Settings a[href="/settings/manage_subscriptions"]',
  2671. )
  2672. }
  2673. if (config.hideHelpCenterNav) {
  2674. hideCssSelectors.push(`${menuRole} a[href*="support.twitter.com"]`)
  2675. }
  2676. if (config.hideMetrics) {
  2677. configureHideMetricsCss(cssRules, hideCssSelectors)
  2678. }
  2679. if (config.hideMonetizationNav) {
  2680. hideCssSelectors.push(`${menuRole} a[href$="/settings/monetization"]`)
  2681. }
  2682. if (config.hideTweetAnalyticsLinks) {
  2683. hideCssSelectors.push('[data-testid="analyticsButton"]')
  2684. }
  2685. if (config.hideTwitterAdsNav) {
  2686. hideCssSelectors.push(`${menuRole} a[href*="ads.twitter.com"]`)
  2687. }
  2688. if (config.hideTwitterBlueUpsells) {
  2689. hideCssSelectors.push(
  2690. // Premium/Verified/Verified Orgs menu item
  2691. `${menuRole} a:is([href$="/i/premium_sign_up"], [href$="/i/verified-choose"], [href$="/i/verified-orgs-signup"])`,
  2692. // "Highlight on your profile" on your tweets
  2693. '[role="menuitem"][data-testid="highlightUpsell"]',
  2694. // "Edit with Premium" on recent tweets
  2695. '[role="menuitem"][data-testid="editWithTwitterBlue"]',
  2696. // Premium item in Settings
  2697. 'body.Settings a[href="/i/premium_sign_up"]',
  2698. // "Highlight your best content instead" on the pin modal
  2699. '.PinModal [data-testid="sheetDialog"] > div > div:last-child > div > div > div:first-child',
  2700. // Highlight button on the pin modal
  2701. '.PinModal [data-testid="sheetDialog"] [role="button"]:first-child:nth-last-child(3)',
  2702. )
  2703. // Allow Pin and Cancel buttons go to max-width on the pin modal
  2704. cssRules.push(`
  2705. .PinModal [data-testid="sheetDialog"] > div > div:last-child > div > div {
  2706. width: 100%;
  2707. margin-top: 0;
  2708. padding-left: 32px;
  2709. padding-right: 32px;
  2710. }
  2711. `)
  2712. }
  2713. if (config.hideVerifiedNotificationsTab) {
  2714. hideCssSelectors.push(
  2715. `body.Notifications ${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} nav div[role="tablist"] > div:nth-child(2)`
  2716. )
  2717. }
  2718. if (config.hideViews) {
  2719. hideCssSelectors.push(
  2720. // "Views" under individual tweets
  2721. '[data-testid="tweet"][tabindex="-1"] div[dir] + div[aria-hidden="true"]:nth-child(2):nth-last-child(2)',
  2722. '[data-testid="tweet"][tabindex="-1"] div[dir] + div[aria-hidden="true"]:nth-child(2):nth-last-child(2) + div[dir]:last-child'
  2723. )
  2724. }
  2725. if (config.hideWhoToFollowEtc) {
  2726. hideCssSelectors.push(`body.Profile ${Selectors.PRIMARY_COLUMN} aside[role="complementary"]`)
  2727. }
  2728. if (config.reducedInteractionMode) {
  2729. hideCssSelectors.push(
  2730. '[data-testid="tweet"] [role="group"]',
  2731. 'body.Tweet a:is([href$="/retweets"], [href$="/likes"])',
  2732. 'body.Tweet [data-testid="tweet"] + div > div [role="group"]',
  2733. )
  2734. }
  2735. if (config.tweakQuoteTweetsPage) {
  2736. // Hide the quoted tweet, which is repeated in every quote tweet
  2737. hideCssSelectors.push('body.QuoteTweets [data-testid="tweet"] [aria-labelledby] > div:last-child')
  2738. }
  2739. if (config.twitterBlueChecks == 'hide') {
  2740. hideCssSelectors.push('.tnt_blue_check')
  2741. }
  2742. if (config.twitterBlueChecks == 'replace') {
  2743. cssRules.push(`
  2744. :is(${Selectors.VERIFIED_TICK}, svg[data-testid="verificationBadge"]).tnt_blue_check path {
  2745. d: path("${Svgs.BLUE_LOGO_PATH}");
  2746. }
  2747. `)
  2748. }
  2749.  
  2750. // Hide "Creator Studio" if all its contents are hidden
  2751. if (config.hideAnalyticsNav) {
  2752. hideCssSelectors.push(`${menuRole} div[role="button"][aria-expanded]:nth-of-type(1)`)
  2753. }
  2754. // Hide "Professional Tools" if all its contents are hidden
  2755. if (config.hideTwitterAdsNav) {
  2756. hideCssSelectors.push(`${menuRole} div[role="button"][aria-expanded]:nth-of-type(2)`)
  2757. }
  2758.  
  2759. if (shouldShowSeparatedTweetsTab()) {
  2760. cssRules.push(`
  2761. body.Default {
  2762. --active-tab-text: rgb(15, 20, 25);
  2763. --inactive-tab-text: rgb(83, 100, 113);
  2764. --tab-border: rgb(239, 243, 244);
  2765. --tab-hover: rgba(15, 20, 25, 0.1);
  2766. }
  2767. body.Dim {
  2768. --active-tab-text: rgb(247, 249, 249);
  2769. --inactive-tab-text: rgb(139, 152, 165);
  2770. --tab-border: rgb(56, 68, 77);
  2771. --tab-hover: rgba(247, 249, 249, 0.1);
  2772. }
  2773. body.LightsOut {
  2774. --active-tab-text: rgb(247, 249, 249);
  2775. --inactive-tab-text: rgb(113, 118, 123);
  2776. --tab-border: rgb(47, 51, 54);
  2777. --tab-hover: rgba(231, 233, 234, 0.1);
  2778. }
  2779.  
  2780. /* Tabbed timeline */
  2781. body.Desktop #tnt_separated_tweets_tab:hover,
  2782. body.Mobile:not(.SeparatedTweets) #tnt_separated_tweets_tab:hover,
  2783. body.Mobile #tnt_separated_tweets_tab:active {
  2784. background-color: var(--tab-hover);
  2785. }
  2786. body:not(.SeparatedTweets) #tnt_separated_tweets_tab > a > div > div,
  2787. body.TabbedTimeline.SeparatedTweets ${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} nav div[role="tablist"] > div:not(#tnt_separated_tweets_tab) > a > div > div {
  2788. font-weight: normal !important;
  2789. color: var(--inactive-tab-text) !important;
  2790. }
  2791. body.SeparatedTweets #tnt_separated_tweets_tab > a > div > div {
  2792. font-weight: bold;
  2793. color: var(--active-tab-text); !important;
  2794. }
  2795. body:not(.SeparatedTweets) #tnt_separated_tweets_tab > a > div > div > div,
  2796. body.TabbedTimeline.SeparatedTweets ${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} nav div[role="tablist"] > div:not(#tnt_separated_tweets_tab) > a > div > div > div {
  2797. height: 0 !important;
  2798. }
  2799. body.SeparatedTweets #tnt_separated_tweets_tab > a > div > div > div {
  2800. height: 4px !important;
  2801. min-width: 56px;
  2802. width: 100%;
  2803. position: absolute;
  2804. bottom: 0;
  2805. border-radius: 9999px;
  2806. }
  2807. `)
  2808. }
  2809.  
  2810. if (desktop) {
  2811. if (config.navDensity == 'comfortable' || config.navDensity == 'compact') {
  2812. cssRules.push(`
  2813. header nav > a,
  2814. header nav > div[data-testid="AppTabBar_More_Menu"] {
  2815. padding-top: 0 !important;
  2816. padding-bottom: 0 !important;
  2817. }
  2818. `)
  2819. }
  2820. if (config.navDensity == 'compact') {
  2821. cssRules.push(`
  2822. header nav > a > div,
  2823. header nav > div[data-testid="AppTabBar_More_Menu"] > div {
  2824. padding-top: 6px !important;
  2825. padding-bottom: 6px !important;
  2826. }
  2827. `)
  2828. }
  2829. if (config.hideHomeHeading) {
  2830. hideCssSelectors.push(`body.TabbedTimeline ${Selectors.DESKTOP_TIMELINE_HEADER} > div:first-child > div:first-child`)
  2831. }
  2832. if (config.hideSeeNewTweets) {
  2833. hideCssSelectors.push(`body.MainTimeline ${Selectors.PRIMARY_COLUMN} > div > div:first-child > div[style^="transform"]`)
  2834. }
  2835. if (config.disableHomeTimeline) {
  2836. hideCssSelectors.push(`${Selectors.PRIMARY_NAV_DESKTOP} a[href="/home"]`)
  2837. }
  2838. if (config.fullWidthContent) {
  2839. cssRules.push(`
  2840. /* Use full width when the sidebar is visible */
  2841. body.Sidebar${FULL_WIDTH_BODY_PSEUDO} ${Selectors.PRIMARY_COLUMN},
  2842. body.Sidebar${FULL_WIDTH_BODY_PSEUDO} ${Selectors.PRIMARY_COLUMN} > div:first-child > div:last-child {
  2843. max-width: 990px;
  2844. }
  2845. /* Make the "What's happening" input keep its original width */
  2846. body.MainTimeline ${Selectors.PRIMARY_COLUMN} > div:first-child > div:nth-of-type(3) div[role="progressbar"] + div {
  2847. max-width: 598px;
  2848. }
  2849. /* Use full width when the sidebar is not visible */
  2850. body:not(.Sidebar)${FULL_WIDTH_BODY_PSEUDO} header[role="banner"] {
  2851. flex-grow: 0;
  2852. }
  2853. body:not(.Sidebar)${FULL_WIDTH_BODY_PSEUDO} main[role="main"] > div {
  2854. width: 100%;
  2855. }
  2856. body:not(.Sidebar)${FULL_WIDTH_BODY_PSEUDO} ${Selectors.PRIMARY_COLUMN} {
  2857. max-width: unset;
  2858. width: 100%;
  2859. }
  2860. body:not(.Sidebar)${FULL_WIDTH_BODY_PSEUDO} ${Selectors.PRIMARY_COLUMN} > div:first-child > div:first-child div,
  2861. body:not(.Sidebar)${FULL_WIDTH_BODY_PSEUDO} ${Selectors.PRIMARY_COLUMN} > div:first-child > div:last-child {
  2862. max-width: unset;
  2863. }
  2864. `)
  2865. if (!config.fullWidthMedia) {
  2866. // Make media & cards keep their original width
  2867. cssRules.push(`
  2868. body${FULL_WIDTH_BODY_PSEUDO} ${Selectors.PRIMARY_COLUMN} ${Selectors.TWEET} > div > div > div:nth-of-type(2) > div:nth-of-type(2) > div[id][aria-labelledby]:not(:empty) {
  2869. max-width: 504px;
  2870. }
  2871. `)
  2872. }
  2873. // Hide the sidebar when present
  2874. hideCssSelectors.push(`body.Sidebar${FULL_WIDTH_BODY_PSEUDO} ${Selectors.SIDEBAR}`)
  2875. }
  2876. if (config.hideAccountSwitcher) {
  2877. cssRules.push(`
  2878. header[role="banner"] > div > div > div > div:last-child {
  2879. flex-shrink: 1 !important;
  2880. align-items: flex-end !important;
  2881. }
  2882. `)
  2883. hideCssSelectors.push(
  2884. '[data-testid="SideNav_AccountSwitcher_Button"] > div:first-child:not(:only-child)',
  2885. '[data-testid="SideNav_AccountSwitcher_Button"] > div:first-child + div',
  2886. )
  2887. }
  2888. if (config.hideExplorePageContents) {
  2889. hideCssSelectors.push(
  2890. // Tabs
  2891. `body.Explore ${Selectors.DESKTOP_TIMELINE_HEADER} nav`,
  2892. // Content
  2893. `body.Explore ${Selectors.TIMELINE}`,
  2894. )
  2895. }
  2896. if (config.hideConnectNav) {
  2897. hideCssSelectors.push(`${menuRole} a[href$="/i/connect_people"]`)
  2898. }
  2899. if (config.hideKeyboardShortcutsNav) {
  2900. hideCssSelectors.push(`${menuRole} a[href$="/i/keyboard_shortcuts"]`)
  2901. }
  2902. if (config.hideListsNav) {
  2903. hideCssSelectors.push(`${Selectors.PRIMARY_NAV_DESKTOP} a[href$="/lists"]`)
  2904. }
  2905. if (config.hideTwitterBlueUpsells) {
  2906. hideCssSelectors.push(`${Selectors.PRIMARY_NAV_DESKTOP} a:is([href$="/i/premium_sign_up"], [href$="/i/verified-choose"], [href$="/i/verified-orgs-signup"])`)
  2907. }
  2908. if (config.hideSidebarContent) {
  2909. // Only show the first sidebar item by default
  2910. // Re-show subsequent non-algorithmic sections on specific pages
  2911. cssRules.push(`
  2912. ${Selectors.SIDEBAR_WRAPPERS} > div:not(:first-of-type) {
  2913. display: none;
  2914. }
  2915. body.Profile:not(.Blocked, .NoMedia) ${Selectors.SIDEBAR_WRAPPERS} > div:is(:nth-of-type(2), :nth-of-type(3)) {
  2916. display: block;
  2917. }
  2918. body.Search ${Selectors.SIDEBAR_WRAPPERS} > div:nth-of-type(2) {
  2919. display: block;
  2920. }
  2921. `)
  2922. if (config.showRelevantPeople) {
  2923. cssRules.push(`
  2924. body.Tweet ${Selectors.SIDEBAR_WRAPPERS} > div:is(:nth-of-type(2), :nth-of-type(3)) {
  2925. display: block;
  2926. }
  2927. `)
  2928. }
  2929. hideCssSelectors.push(`body.HideSidebar ${Selectors.SIDEBAR}`)
  2930. } else if (config.hideTwitterBlueUpsells) {
  2931. hideCssSelectors.push(
  2932. `body.MainTimeline ${Selectors.SIDEBAR_WRAPPERS} > div:nth-of-type(3)`
  2933. )
  2934. }
  2935. if (config.hideShareTweetButton) {
  2936. hideCssSelectors.push(
  2937. // In media modal
  2938. `[aria-modal="true"] [role="group"] > div[style]:not([role]):not(${TWITTER_MEDIA_ASSIST_BUTTON_SELECTOR})`,
  2939. )
  2940. }
  2941. if (config.hideExploreNav) {
  2942. // When configured, hide Explore only when the sidebar is showing, or
  2943. // when on a page full-width content is enabled on.
  2944. let bodySelector = `${config.hideExploreNavWithSidebar ? `body.Sidebar${config.fullWidthContent ? `:not(${FULL_WIDTH_BODY_PSEUDO})` : ''} ` : ''}`
  2945. hideCssSelectors.push(`${bodySelector}${Selectors.PRIMARY_NAV_DESKTOP} a[href="/explore"]`)
  2946. }
  2947. if (config.hideBookmarksNav) {
  2948. hideCssSelectors.push(`${Selectors.PRIMARY_NAV_DESKTOP} a[href="/i/bookmarks"]`)
  2949. }
  2950. if (config.hideCommunitiesNav) {
  2951. hideCssSelectors.push(`${Selectors.PRIMARY_NAV_DESKTOP} a[href$="/communities"]`)
  2952. }
  2953. if (config.hideMessagesDrawer) {
  2954. cssRules.push(`${Selectors.MESSAGES_DRAWER} { visibility: hidden; }`)
  2955. }
  2956. if (config.hideViews) {
  2957. hideCssSelectors.push(
  2958. // Under timeline tweets
  2959. // The Buffer extension adds a new button in position 2 - use their added class to avoid
  2960. // hiding the wrong button (#209)
  2961. '[data-testid="tweet"][tabindex="0"] [role="group"]:not(.buffer-inserted) > div:nth-of-type(4)',
  2962. '[data-testid="tweet"][tabindex="0"] [role="group"].buffer-inserted > div:nth-of-type(5)',
  2963. )
  2964. }
  2965. if (config.retweets != 'separate' && config.quoteTweets != 'separate') {
  2966. hideCssSelectors.push('#tnt_separated_tweets_tab')
  2967. }
  2968. }
  2969.  
  2970. if (mobile) {
  2971. if (config.disableHomeTimeline) {
  2972. hideCssSelectors.push(`${Selectors.PRIMARY_NAV_MOBILE} a[href="/home"]`)
  2973. }
  2974. if (config.hideSeeNewTweets) {
  2975. hideCssSelectors.push(`body.MainTimeline ${Selectors.MOBILE_TIMELINE_HEADER} ~ div[style^="transform"]:last-child`)
  2976. }
  2977. if (config.hideAppNags) {
  2978. cssRules.push(`
  2979. body.Tweet ${Selectors.MOBILE_TIMELINE_HEADER} div:nth-of-type(3) > div > [role="button"] {
  2980. visibility: hidden;
  2981. }
  2982. `)
  2983. }
  2984. if (config.hideExplorePageContents) {
  2985. // Hide explore page contents so we don't get a brief flash of them
  2986. // before automatically switching the page to search mode.
  2987. hideCssSelectors.push(
  2988. // Tabs
  2989. `body.Explore ${Selectors.MOBILE_TIMELINE_HEADER} > div > div:nth-of-type(2)`,
  2990. // Content
  2991. `body.Explore ${Selectors.TIMELINE}`,
  2992. )
  2993. }
  2994. if (config.hideListsNav) {
  2995. hideCssSelectors.push(`${menuRole} a[href$="/lists"]`)
  2996. }
  2997. if (config.hideMessagesBottomNavItem) {
  2998. hideCssSelectors.push(`${Selectors.PRIMARY_NAV_MOBILE} a[href="/messages"]`)
  2999. }
  3000. if (config.hideShareTweetButton) {
  3001. hideCssSelectors.push(
  3002. // In media modal
  3003. `body.MobileMedia [role="group"] > div[style]:not(${TWITTER_MEDIA_ASSIST_BUTTON_SELECTOR})`,
  3004. )
  3005. }
  3006. if (config.hideViews) {
  3007. hideCssSelectors.push(
  3008. // Under timeline tweets
  3009. // Views only display on mobile at larger widths - only hide the 4th button if there are 5
  3010. '[data-testid="tweet"][tabindex="0"] [role="group"]:not(.buffer-inserted) > div:nth-child(4):nth-last-child(2)',
  3011. '[data-testid="tweet"][tabindex="0"] [role="group"].buffer-inserted > div:nth-child(4):nth-last-child(2)',
  3012. )
  3013. }
  3014. }
  3015.  
  3016. if (hideCssSelectors.length > 0) {
  3017. cssRules.push(`
  3018. ${hideCssSelectors.join(',\n')} {
  3019. display: none !important;
  3020. }
  3021. `)
  3022. }
  3023.  
  3024. $style.textContent = cssRules.map(dedent).join('\n')
  3025. }
  3026. })()
  3027.  
  3028. function configureFont() {
  3029. if (!fontFamilyRule) {
  3030. warn('no fontFamilyRule found for configureFont to use')
  3031. return
  3032. }
  3033.  
  3034. if (config.dontUseChirpFont) {
  3035. if (fontFamilyRule.style.fontFamily.includes('TwitterChirp')) {
  3036. fontFamilyRule.style.fontFamily = fontFamilyRule.style.fontFamily.replace(/"?TwitterChirp"?, ?/, '')
  3037. log('disabled Chirp font')
  3038. }
  3039. } else if (!fontFamilyRule.style.fontFamily.includes('TwitterChirp')) {
  3040. fontFamilyRule.style.fontFamily = `"TwitterChirp", ${fontFamilyRule.style.fontFamily}`
  3041. log(`enabled Chirp font`)
  3042. }
  3043. }
  3044.  
  3045. /**
  3046. * @param {string[]} cssRules
  3047. * @param {string[]} hideCssSelectors
  3048. */
  3049. function configureHideMetricsCss(cssRules, hideCssSelectors) {
  3050. if (config.hideFollowingMetrics) {
  3051. // User profile hover card and page metrics
  3052. hideCssSelectors.push(
  3053. ':is(#layers, body.Profile) a:is([href$="/following"], [href$="/followers"]) > :first-child'
  3054. )
  3055. // Fix display of whitespace after hidden metrics
  3056. cssRules.push(
  3057. ':is(#layers, body.Profile) a:is([href$="/following"], [href$="/followers"]) { white-space: pre-line; }'
  3058. )
  3059. }
  3060.  
  3061. if (config.hideTotalTweetsMetrics) {
  3062. // Tweet count under username header on profile pages
  3063. hideCssSelectors.push(`
  3064. body.Profile ${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} > div > div:first-of-type h2 + div[dir]
  3065. `)
  3066. }
  3067.  
  3068. let individualTweetMetricSelectors = [
  3069. config.hideRetweetMetrics && '[href$="/retweets"]',
  3070. config.hideLikeMetrics && '[href$="/likes"]',
  3071. config.hideQuoteTweetMetrics && '[href$="/retweets/with_comments"]',
  3072. ].filter(Boolean).join(', ')
  3073.  
  3074. if (individualTweetMetricSelectors) {
  3075. // Individual tweet metrics
  3076. hideCssSelectors.push(
  3077. `body.Tweet a:is(${individualTweetMetricSelectors}) > :first-child`,
  3078. `[aria-modal="true"] [data-testid="tweet"] a:is(${individualTweetMetricSelectors}) > :first-child`
  3079. )
  3080. // Fix display of whitespace after hidden metrics
  3081. cssRules.push(
  3082. `body.Tweet a:is(${individualTweetMetricSelectors}), [aria-modal="true"] [data-testid="tweet"] a:is(${individualTweetMetricSelectors}) { white-space: pre-line; }`
  3083. )
  3084. }
  3085.  
  3086. if (config.hideBookmarkMetrics) {
  3087. // Bookmark metrics are the only one without a link
  3088. hideCssSelectors.push('[data-testid="tweet"][tabindex="-1"] [role="group"]:not([id]) > div > div')
  3089. }
  3090.  
  3091. let timelineMetricSelectors = [
  3092. config.hideReplyMetrics && '[data-testid="reply"]',
  3093. config.hideRetweetMetrics && '[data-testid$="retweet"]',
  3094. config.hideLikeMetrics && '[data-testid$="like"]',
  3095. ].filter(Boolean).join(', ')
  3096.  
  3097. if (timelineMetricSelectors) {
  3098. cssRules.push(
  3099. `[role="group"] div:is(${timelineMetricSelectors}) span { visibility: hidden; }`
  3100. )
  3101. }
  3102. }
  3103.  
  3104. const configureNavFontSizeCss = (() => {
  3105. let $style
  3106.  
  3107. return function configureNavFontSizeCss() {
  3108. if ($style == null) {
  3109. $style = addStyle('nav-font-size')
  3110. }
  3111. let cssRules = []
  3112.  
  3113. if (fontSize != null && config.navBaseFontSize) {
  3114. cssRules.push(`
  3115. ${Selectors.PRIMARY_NAV_DESKTOP} div[dir] span { font-size: ${fontSize}; font-weight: normal; }
  3116. ${Selectors.PRIMARY_NAV_DESKTOP} div[dir] { margin-top: -4px; }
  3117. `)
  3118. }
  3119.  
  3120. $style.textContent = cssRules.map(dedent).join('\n')
  3121. }
  3122. })()
  3123.  
  3124. /**
  3125. * Configures – or re-configures – the separated tweets timeline title.
  3126. *
  3127. * If we're currently on the separated tweets timeline and…
  3128. * - …its title has changed, the page title will be changed to "navigate" to it.
  3129. * - …the separated tweets timeline is no longer needed, we'll change the page
  3130. * title to "navigate" back to the main timeline.
  3131. *
  3132. * @returns {boolean} `true` if "navigation" was triggered by this call
  3133. */
  3134. function configureSeparatedTweetsTimelineTitle() {
  3135. let wasOnSeparatedTweetsTimeline = isOnSeparatedTweetsTimeline()
  3136. let previousTitle = separatedTweetsTimelineTitle
  3137.  
  3138. if (config.retweets == 'separate' && config.quoteTweets == 'separate') {
  3139. separatedTweetsTimelineTitle = getString('SHARED_TWEETS')
  3140. } else if (config.retweets == 'separate') {
  3141. separatedTweetsTimelineTitle = getString('RETWEETS')
  3142. } else if (config.quoteTweets == 'separate') {
  3143. separatedTweetsTimelineTitle = getString('QUOTE_TWEETS')
  3144. } else {
  3145. separatedTweetsTimelineTitle = null
  3146. }
  3147.  
  3148. let titleChanged = previousTitle != separatedTweetsTimelineTitle
  3149. if (wasOnSeparatedTweetsTimeline) {
  3150. if (separatedTweetsTimelineTitle == null) {
  3151. log('moving from separated tweets timeline to main timeline after config change')
  3152. setTitle(getString('HOME'))
  3153. return true
  3154. }
  3155. if (titleChanged) {
  3156. log('applying new separated tweets timeline title after config change')
  3157. setTitle(separatedTweetsTimelineTitle)
  3158. return true
  3159. }
  3160. } else {
  3161. if (titleChanged && previousTitle != null && lastMainTimelineTitle == previousTitle) {
  3162. log('updating lastMainTimelineTitle with new separated tweets timeline title')
  3163. lastMainTimelineTitle = separatedTweetsTimelineTitle
  3164. }
  3165. }
  3166. }
  3167.  
  3168. const configureThemeCss = (() => {
  3169. let $style
  3170.  
  3171. return function configureThemeCss() {
  3172. if ($style == null) {
  3173. $style = addStyle('theme')
  3174. }
  3175. let cssRules = []
  3176.  
  3177. if (debug) {
  3178. cssRules.push(`
  3179. [data-item-type]::after {
  3180. position: absolute;
  3181. top: 0;
  3182. ${ltr ? 'right': 'left'}: 50px;
  3183. content: attr(data-item-type);
  3184. font-family: ${fontFamilyRule?.style.fontFamily || '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial'};
  3185. background-color: rgb(242, 29, 29);
  3186. color: white;
  3187. font-size: 11px;
  3188. font-weight: bold;
  3189. padding: 4px 6px;
  3190. border-bottom-left-radius: 1em;
  3191. border-bottom-right-radius: 1em;
  3192. }
  3193. `)
  3194. }
  3195.  
  3196. // Active tab colour for custom tabs
  3197. if (themeColor != null && shouldShowSeparatedTweetsTab()) {
  3198. cssRules.push(`
  3199. body.SeparatedTweets #tnt_separated_tweets_tab > a > div > div > div {
  3200. background-color: ${themeColor} !important;
  3201. }
  3202. `)
  3203. }
  3204.  
  3205. if (config.replaceLogo) {
  3206. let fill = themeColor || THEME_BLUE
  3207. cssRules.push(`
  3208. ${Selectors.X_LOGO_PATH} {
  3209. fill: ${fill};
  3210. d: path("${Svgs.TWITTER_LOGO_PATH}");
  3211. }
  3212. .tnt_logo {
  3213. fill: ${fill};
  3214. }
  3215. `)
  3216. }
  3217.  
  3218. if (config.uninvertFollowButtons) {
  3219. // Shared styles for Following and Follow buttons
  3220. cssRules.push(`
  3221. [role="button"][data-testid$="-unfollow"]:not(:hover) {
  3222. border-color: rgba(0, 0, 0, 0) !important;
  3223. }
  3224. [role="button"][data-testid$="-follow"] {
  3225. background-color: rgba(0, 0, 0, 0) !important;
  3226. }
  3227. `)
  3228. if (config.followButtonStyle == 'monochrome' || themeColor == null) {
  3229. cssRules.push(`
  3230. /* Following button */
  3231. body.Default [role="button"][data-testid$="-unfollow"]:not(:hover) {
  3232. background-color: rgb(15, 20, 25) !important;
  3233. }
  3234. body.Default [role="button"][data-testid$="-unfollow"]:not(:hover) > :is(div, span) {
  3235. color: rgb(255, 255, 255) !important;
  3236. }
  3237. body:is(.Dim, .LightsOut) [role="button"][data-testid$="-unfollow"]:not(:hover) {
  3238. background-color: rgb(255, 255, 255) !important;
  3239. }
  3240. body:is(.Dim, .LightsOut) [role="button"][data-testid$="-unfollow"]:not(:hover) > :is(div, span) {
  3241. color: rgb(15, 20, 25) !important;
  3242. }
  3243. /* Follow button */
  3244. body.Default [role="button"][data-testid$="-follow"] {
  3245. border-color: rgb(207, 217, 222) !important;
  3246. }
  3247. body:is(.Dim, .LightsOut) [role="button"][data-testid$="-follow"] {
  3248. border-color: rgb(83, 100, 113) !important;
  3249. }
  3250. body.Default [role="button"][data-testid$="-follow"] > :is(div, span) {
  3251. color: rgb(15, 20, 25) !important;
  3252. }
  3253. body:is(.Dim, .LightsOut) [role="button"][data-testid$="-follow"] > :is(div, span) {
  3254. color: rgb(255, 255, 255) !important;
  3255. }
  3256. body.Default [role="button"][data-testid$="-follow"]:hover {
  3257. background-color: rgba(15, 20, 25, 0.1) !important;
  3258. }
  3259. body:is(.Dim, .LightsOut) [role="button"][data-testid$="-follow"]:hover {
  3260. background-color: rgba(255, 255, 255, 0.1) !important;
  3261. }
  3262. `)
  3263. }
  3264. if (config.followButtonStyle == 'themed' && themeColor != null) {
  3265. cssRules.push(`
  3266. /* Following button */
  3267. [role="button"][data-testid$="-unfollow"]:not(:hover) {
  3268. background-color: ${themeColor} !important;
  3269. }
  3270. [role="button"][data-testid$="-unfollow"]:not(:hover) > :is(div, span) {
  3271. color: rgb(255, 255, 255) !important;
  3272. }
  3273. /* Follow button */
  3274. [role="button"][data-testid$="-follow"] {
  3275. border-color: ${themeColor} !important;
  3276. }
  3277. [role="button"][data-testid$="-follow"] > :is(div, span) {
  3278. color: ${themeColor} !important;
  3279. }
  3280. [role="button"][data-testid$="-follow"]:hover {
  3281. background-color: ${themeColor} !important;
  3282. }
  3283. [role="button"][data-testid$="-follow"]:hover > :is(div, span) {
  3284. color: rgb(255, 255, 255) !important;
  3285. }
  3286. `)
  3287. }
  3288. if (mobile) {
  3289. cssRules.push(`
  3290. body.MediaViewer [role="button"][data-testid$="follow"]:not(:hover) {
  3291. border: revert !important;
  3292. background-color: transparent !important;
  3293. }
  3294. body.MediaViewer [role="button"][data-testid$="follow"]:not(:hover) > div {
  3295. color: ${themeColor} !important;
  3296. }
  3297. `)
  3298. }
  3299. }
  3300.  
  3301. $style.textContent = cssRules.map(dedent).join('\n')
  3302. }
  3303. })()
  3304.  
  3305. /**
  3306. * @param {HTMLElement} $tweet
  3307. * @param {?{getText?: boolean}} options
  3308. * @returns {import("./types").QuotedTweet}
  3309. */
  3310. function getQuotedTweetDetails($tweet, options = {}) {
  3311. let {getText = false} = options
  3312. let $quotedTweet = $tweet.querySelector('div[id^="id__"] > div[dir] > span').parentElement.nextElementSibling
  3313. let $userName = $quotedTweet?.querySelector('[data-testid="User-Name"]')
  3314. let user = $userName?.querySelector('[tabindex="-1"]')?.textContent
  3315. let time = $userName?.querySelector('time')?.dateTime
  3316. if (!getText) return {user, time}
  3317.  
  3318. let $heading = $quotedTweet?.querySelector(':scope > div > div:first-child')
  3319. let $qtText = $heading?.nextElementSibling?.querySelector('[lang]')
  3320. let text = $qtText && Array.from($qtText.childNodes, node => {
  3321. if (node.nodeType == 1) {
  3322. if (node.nodeName == 'IMG') return node.alt
  3323. return node.textContent
  3324. }
  3325. return node.nodeValue
  3326. }).join('')
  3327. return {user, time, text}
  3328. }
  3329.  
  3330. /**
  3331. * Attempts to determine the type of a timeline Tweet given the element with
  3332. * data-testid="tweet" on it, falling back to TWEET if it doesn't appear to be
  3333. * one of the particular types we care about.
  3334. * @param {HTMLElement} $tweet
  3335. * @param {?boolean} checkSocialContext
  3336. * @returns {import("./types").TweetType}
  3337. */
  3338. function getTweetType($tweet, checkSocialContext = false) {
  3339. if ($tweet.closest(Selectors.PROMOTED_TWEET_CONTAINER)) {
  3340. return 'PROMOTED_TWEET'
  3341. }
  3342. // Assume social context tweets are Retweets
  3343. if ($tweet.querySelector('[data-testid="socialContext"]')) {
  3344. if (checkSocialContext) {
  3345. let svgPath = $tweet.querySelector('svg path')?.getAttribute('d') ?? ''
  3346. if (svgPath.startsWith('M7 4.5C7 3.12 8.12 2 9.5 2h5C1')) return 'PINNED_TWEET'
  3347. }
  3348. // Quoted tweets from accounts you blocked or muted are displayed as an
  3349. // <article> with "This Tweet is unavailable."
  3350. if ($tweet.querySelector('article')) {
  3351. return 'UNAVAILABLE_RETWEET'
  3352. }
  3353. // Quoted tweets are preceded by visually-hidden "Quote" text
  3354. if ($tweet.querySelector('div[id^="id__"] > div[dir] > span')?.textContent.includes(getString('QUOTE'))) {
  3355. return 'RETWEETED_QUOTE_TWEET'
  3356. }
  3357. return 'RETWEET'
  3358. }
  3359. // Quoted tweets are preceded by visually-hidden "Quote" text
  3360. if ($tweet.querySelector('div[id^="id__"] > div[dir] > span')?.textContent.includes(getString('QUOTE'))) {
  3361. return 'QUOTE_TWEET'
  3362. }
  3363. // Quoted tweets from accounts you blocked or muted are displayed as an
  3364. // <article> with "This Tweet is unavailable."
  3365. if ($tweet.querySelector('article')) {
  3366. return 'UNAVAILABLE_QUOTE_TWEET'
  3367. }
  3368. return 'TWEET'
  3369. }
  3370.  
  3371. // Add 1 every time this gets broken: 6
  3372. function getVerifiedProps($svg) {
  3373. let propsGetter = (props) => props?.children?.props?.children?.[0]?.[0]?.props
  3374. let $parent = $svg.parentElement.parentElement
  3375. // Verified badge button on the profile screen
  3376. if (isOnProfilePage() && $svg.parentElement.getAttribute('role') == 'button') {
  3377. $parent = $svg.closest('span').parentElement
  3378. }
  3379. // Link variant in "user followed/liked/retweeted" notifications
  3380. else if (isOnNotificationsPage() && $parent.getAttribute('role') == 'link') {
  3381. propsGetter = (props) => {
  3382. let linkChildren = props?.children?.props?.children?.[0]
  3383. return linkChildren?.[linkChildren.length - 1]?.props
  3384. }
  3385. }
  3386. if ($parent.wrappedJSObject) {
  3387. $parent = $parent.wrappedJSObject
  3388. }
  3389. let reactPropsKey = Object.keys($parent).find(key => key.startsWith('__reactProps$'))
  3390. let props = propsGetter($parent[reactPropsKey])
  3391. if (!props) {
  3392. warn('React props not found for', $svg)
  3393. }
  3394. else if (!('isVerified' in props)) {
  3395. warn('isVerified not in React props for', $svg, {props})
  3396. }
  3397. return props
  3398. }
  3399.  
  3400. /**
  3401. * @param {HTMLElement} $popup
  3402. * @returns {{tookAction: boolean, onPopupClosed?: () => void}}
  3403. */
  3404. function handlePopup($popup) {
  3405. let result = {tookAction: false, onPopupClosed: null}
  3406.  
  3407. if (desktop && !isDesktopComposeTweetModalOpen && location.pathname.startsWith(PagePaths.COMPOSE_TWEET)) {
  3408. log('compose tweet modal opened')
  3409. isDesktopComposeTweetModalOpen = true
  3410. observeDesktopComposeTweetModal($popup)
  3411. return {
  3412. tookAction: true,
  3413. onPopupClosed() {
  3414. log('compose tweet modal closed')
  3415. isDesktopComposeTweetModalOpen = false
  3416. // The Tweet button will re-render if the modal was opened to edit
  3417. // multiple Tweets on the home timeline.
  3418. if (config.replaceLogo && isOnHomeTimeline()) {
  3419. tweakTweetButton()
  3420. }
  3421. }
  3422. }
  3423. }
  3424.  
  3425. if (desktop && !isDesktopMediaModalOpen && URL_MEDIA_RE.test(location.pathname) && currentPath != location.pathname) {
  3426. log('media modal opened')
  3427. isDesktopMediaModalOpen = true
  3428. observeDesktopModalTimeline($popup)
  3429. return {
  3430. tookAction: true,
  3431. onPopupClosed() {
  3432. log('media modal closed')
  3433. isDesktopMediaModalOpen = false
  3434. disconnectAllModalObservers()
  3435. }
  3436. }
  3437. }
  3438.  
  3439. if (desktop && !isDesktopUserListModalOpen && URL_TWEET_LIKES_RETWEETS_RE.test(location.pathname)) {
  3440. let modalType = URL_TWEET_LIKES_RETWEETS_RE.exec(location.pathname)[1]
  3441. log(`${modalType} modal opened`)
  3442. isDesktopUserListModalOpen = true
  3443. tweakUserModalTimelineHeading(location.pathname)
  3444. observeUserListTimeline({context: $popup, initialPath: location.pathname, observers: modalObservers})
  3445. return {
  3446. tookAction: true,
  3447. onPopupClosed() {
  3448. log(`${modalType} modal closed`)
  3449. isDesktopUserListModalOpen = false
  3450. disconnectAllModalObservers()
  3451. }
  3452. }
  3453. }
  3454.  
  3455. if (config.replaceLogo) {
  3456. let $retweetDropdownItem = $popup.querySelector('div:is([data-testid="retweetConfirm"], [data-testid="repostConfirm"])')
  3457. if ($retweetDropdownItem) {
  3458. tweakRetweetsDropdown($retweetDropdownItem)
  3459. return {tookAction: true}
  3460. }
  3461.  
  3462. let $hoverLabel = $popup.querySelector('span[data-testid="HoverLabel"] > span')
  3463. if ($hoverLabel?.textContent == getString('REPOST')) {
  3464. $hoverLabel.textContent = getString('RETWEET')
  3465. }
  3466. }
  3467.  
  3468. if (isOnListPage()) {
  3469. let $switchSvg = $popup.querySelector(`svg path[d^="M12 3.75c-4.56 0-8.25 3.69-8.25 8.25s"]`)
  3470. if ($switchSvg) {
  3471. addToggleListRetweetsMenuItem($popup.querySelector(`[role="menuitem"]`))
  3472. return {tookAction: true}
  3473. }
  3474. }
  3475.  
  3476. if (config.mutableQuoteTweets) {
  3477. if (quotedTweet) {
  3478. let $blockMenuItem = /** @type {HTMLElement} */ ($popup.querySelector(Selectors.BLOCK_MENU_ITEM))
  3479. if ($blockMenuItem) {
  3480. addMuteQuotesMenuItem($blockMenuItem)
  3481. result.tookAction = true
  3482. // Clear the quoted tweet when the popup closes
  3483. result.onPopupClosed = () => {
  3484. quotedTweet = null
  3485. }
  3486. } else {
  3487. quotedTweet = null
  3488. }
  3489. }
  3490. }
  3491.  
  3492. if (config.fastBlock) {
  3493. if (blockMenuItemSeen && $popup.querySelector('[data-testid="confirmationSheetConfirm"]')) {
  3494. log('fast blocking')
  3495. ;/** @type {HTMLElement} */ ($popup.querySelector('[data-testid="confirmationSheetConfirm"]')).click()
  3496. result.tookAction = true
  3497. }
  3498. else if ($popup.querySelector(Selectors.BLOCK_MENU_ITEM)) {
  3499. log('preparing for fast blocking')
  3500. blockMenuItemSeen = true
  3501. // Create a nested observer for mobile, as it reuses the popup element
  3502. result.tookAction = !mobile
  3503. } else {
  3504. blockMenuItemSeen = false
  3505. }
  3506. }
  3507.  
  3508. if (config.hideTwitterBlueUpsells) {
  3509. // The "Pin to your profile" menu item is currently the only one which opens
  3510. // a sheet dialog.
  3511. if (pinMenuItemSeen && $popup.querySelector('[data-testid="sheetDialog"]')) {
  3512. log('pin to your profile modal opened')
  3513. $popup.classList.add('PinModal')
  3514. result.tookAction = true
  3515. }
  3516. else if ($popup.querySelector('[data-testid="highlighOnPin"]')) {
  3517. log('preparing to hide Twitter Blue upsell when pinning a tweet')
  3518. pinMenuItemSeen = true
  3519. // Create a nested observer for mobile, as it reuses the popup element
  3520. result.tookAction = !mobile
  3521. } else {
  3522. pinMenuItemSeen = false
  3523. }
  3524. }
  3525.  
  3526. if (config.addAddMutedWordMenuItem) {
  3527. let linkSelector = desktop ? 'a[href$="/compose/tweet/unsent/drafts"]' : 'a[href$="/bookmarks"]'
  3528. let $link = /** @type {HTMLElement} */ ($popup.querySelector(linkSelector))
  3529. if ($link) {
  3530. addAddMutedWordMenuItem($link, linkSelector)
  3531. result.tookAction = true
  3532. }
  3533. }
  3534.  
  3535. if (config.twitterBlueChecks != 'ignore') {
  3536. // User typeahead dropdown
  3537. let $typeaheadDropdown = /** @type {HTMLElement} */ ($popup.querySelector('div[id^="typeaheadDropdown"]'))
  3538. if ($typeaheadDropdown) {
  3539. log('typeahead dropdown appeared')
  3540. let observer = observeElement($typeaheadDropdown, () => {
  3541. processBlueChecks($typeaheadDropdown)
  3542. }, 'popup typeahead dropdown')
  3543. return {
  3544. tookAction: true,
  3545. onPopupClosed() {
  3546. log('typeahead dropdown closed')
  3547. observer.disconnect()
  3548. }
  3549. }
  3550. }
  3551.  
  3552. // User hovercard popup
  3553. let $hoverCard = /** @type {HTMLElement} */ ($popup.querySelector('[data-testid="HoverCard"]'))
  3554. if ($hoverCard) {
  3555. result.tookAction = true
  3556. getElement('div[data-testid^="UserAvatar-Container"]', {
  3557. context: $hoverCard,
  3558. name: 'user hovercard contents',
  3559. timeout: 500,
  3560. }).then(($contents) => {
  3561. if ($contents) processBlueChecks($popup)
  3562. })
  3563. }
  3564. }
  3565.  
  3566. // Verified account popup when you press the check button on a profile page
  3567. if (config.twitterBlueChecks == 'replace' && isOnProfilePage()) {
  3568. if (mobile) {
  3569. let $verificationBadge = /** @type {HTMLElement} */ ($popup.querySelector('[data-testid="sheetDialog"] [data-testid="verificationBadge"]'))
  3570. if ($verificationBadge) {
  3571. result.tookAction = true
  3572. let $headerBlueCheck = document.querySelector(`body.Profile ${Selectors.MOBILE_TIMELINE_HEADER} .tnt_blue_check`)
  3573. if ($headerBlueCheck) {
  3574. blueCheck($verificationBadge)
  3575. }
  3576. }
  3577. } else {
  3578. let $hoverCard = /** @type {HTMLElement} */ ($popup.querySelector('[data-testid="HoverCard"]'))
  3579. if ($hoverCard) {
  3580. result.tookAction = true
  3581. getElement(':scope > div > div > div > svg[data-testid="verificationBadge"]', {
  3582. context: $hoverCard,
  3583. name: 'verified account hovercard verification badge',
  3584. timeout: 500,
  3585. }).then(($verificationBadge) => {
  3586. if (!$verificationBadge) return
  3587.  
  3588. let $headerBlueCheck = document.querySelector(`body.Profile ${Selectors.PRIMARY_COLUMN} > div > div:first-of-type h2 .tnt_blue_check`)
  3589. if (!$headerBlueCheck) return
  3590.  
  3591. // Wait for the hovercard to render its contents
  3592. let popupRenderObserver = observeElement($popup, (mutations) => {
  3593. if (!mutations.length) return
  3594. blueCheck($popup.querySelector('svg[data-testid="verificationBadge"]'))
  3595. popupRenderObserver.disconnect()
  3596. }, 'verified popup render', {childList: true, subtree: true})
  3597. })
  3598. }
  3599. }
  3600. }
  3601.  
  3602. return result
  3603. }
  3604.  
  3605. function isBlueVerified($svg) {
  3606. let props = getVerifiedProps($svg)
  3607. return Boolean(props && props.isBlueVerified && !(
  3608. props.verifiedType || (
  3609. props.affiliateBadgeInfo?.userLabelType == 'BusinessLabel' &&
  3610. props.affiliateBadgeInfo?.description == 'X'
  3611. )
  3612. ))
  3613. }
  3614.  
  3615. /**
  3616. * Checks if a tweet is preceded by an element creating a vertical reply line.
  3617. * @param {HTMLElement} $tweet
  3618. * @returns {boolean}
  3619. */
  3620. function isReplyToPreviousTweet($tweet) {
  3621. let $replyLine = $tweet.firstElementChild?.firstElementChild?.firstElementChild?.firstElementChild?.firstElementChild?.firstElementChild
  3622. if ($replyLine) {
  3623. return getComputedStyle($replyLine).width == '2px'
  3624. }
  3625. }
  3626.  
  3627. /**
  3628. * @returns {{disconnect()}}
  3629. */
  3630. function onPopup($popup) {
  3631. log('popup appeared', $popup, location.pathname)
  3632.  
  3633. // If handlePopup did something, we don't need to observe nested popups
  3634. let {tookAction, onPopupClosed} = handlePopup($popup)
  3635. if (tookAction) {
  3636. return onPopupClosed ? {disconnect: onPopupClosed} : null
  3637. }
  3638.  
  3639. /** @type {HTMLElement} */
  3640. let $nestedPopup
  3641.  
  3642. let nestedObserver = observeElement($popup, (mutations) => {
  3643. mutations.forEach((mutation) => {
  3644. mutation.addedNodes.forEach((/** @type {HTMLElement} */ $el) => {
  3645. log('nested popup appeared', $el)
  3646. $nestedPopup = $el
  3647. ;({onPopupClosed} = handlePopup($el))
  3648. })
  3649. mutation.removedNodes.forEach((/** @type {HTMLElement} */ $el) => {
  3650. if ($el !== $nestedPopup) return
  3651. if (onPopupClosed) {
  3652. log('cleaning up after nested popup removed')
  3653. onPopupClosed()
  3654. }
  3655. })
  3656. })
  3657. }, 'nested popup observer')
  3658.  
  3659. let disconnect = nestedObserver.disconnect.bind(nestedObserver)
  3660. nestedObserver.disconnect = () => {
  3661. if (onPopupClosed) {
  3662. log('cleaning up after nested popup observer disconnected')
  3663. onPopupClosed()
  3664. }
  3665. disconnect()
  3666. }
  3667.  
  3668. return nestedObserver
  3669. }
  3670.  
  3671. /**
  3672. * @param {HTMLElement} $timeline
  3673. * @param {string} page
  3674. * @param {import("./types").TimelineOptions?} options
  3675. */
  3676. function onTimelineChange($timeline, page, options = {}) {
  3677. let startTime = Date.now()
  3678. let {classifyTweets = true, hideHeadings = true} = options
  3679.  
  3680. let isOnMainTimeline = isOnMainTimelinePage()
  3681. let isOnListTimeline = isOnListPage()
  3682. let isOnProfileTimeline = isOnProfilePage()
  3683. let timelineHasSpecificHandling = isOnMainTimeline || isOnListTimeline || isOnProfileTimeline
  3684.  
  3685. if (config.twitterBlueChecks != 'ignore' && !timelineHasSpecificHandling) {
  3686. processBlueChecks($timeline)
  3687. }
  3688.  
  3689. if (isSafari && config.replaceLogo && isOnNotificationsPage()) {
  3690. processTwitterLogos($timeline)
  3691. }
  3692.  
  3693. if (!classifyTweets) return
  3694.  
  3695. let itemTypes = {}
  3696. let hiddenItemCount = 0
  3697. let hiddenItemTypes = {}
  3698.  
  3699. /** @type {?boolean} */
  3700. let hidPreviousItem = null
  3701. /** @type {{$item: Element, hideItem?: boolean}[]} */
  3702. let changes = []
  3703.  
  3704. for (let $item of $timeline.children) {
  3705. /** @type {?import("./types").TimelineItemType} */
  3706. let itemType = null
  3707. /** @type {?boolean} */
  3708. let hideItem = null
  3709. /** @type {?HTMLElement} */
  3710. let $tweet = $item.querySelector(Selectors.TWEET)
  3711. /** @type {boolean} */
  3712. let isReply = false
  3713. /** @type {boolean} */
  3714. let isBlueTweet = false
  3715.  
  3716. if ($tweet != null) {
  3717. itemType = getTweetType($tweet, isOnProfileTimeline)
  3718. if (timelineHasSpecificHandling) {
  3719. isReply = isReplyToPreviousTweet($tweet)
  3720. if (isReply && hidPreviousItem != null) {
  3721. hideItem = hidPreviousItem
  3722. } else {
  3723. if (isOnMainTimeline) {
  3724. hideItem = shouldHideMainTimelineItem(itemType, page)
  3725. }
  3726. else if (isOnListTimeline) {
  3727. hideItem = shouldHideListTimelineItem(itemType)
  3728. }
  3729. else if (isOnProfileTimeline) {
  3730. hideItem = shouldHideProfileTimelineItem(itemType)
  3731. }
  3732. }
  3733.  
  3734. if (!hideItem && config.mutableQuoteTweets && (itemType == 'QUOTE_TWEET' || itemType == 'RETWEETED_QUOTE_TWEET')) {
  3735. if (config.mutedQuotes.length > 0) {
  3736. let quotedTweet = getQuotedTweetDetails($tweet)
  3737. hideItem = config.mutedQuotes.some(muted => muted.user == quotedTweet.user && muted.time == quotedTweet.time)
  3738. }
  3739. if (!hideItem) {
  3740. addCaretMenuListenerForQuoteTweet($tweet)
  3741. }
  3742. }
  3743.  
  3744. if (config.twitterBlueChecks != 'ignore') {
  3745. for (let $svg of $tweet.querySelectorAll(Selectors.VERIFIED_TICK)) {
  3746. let isBlueCheck = isBlueVerified($svg)
  3747. if (!isBlueCheck) continue
  3748.  
  3749. blueCheck($svg)
  3750.  
  3751. let userProfileLink = $svg.closest('a[role="link"]:not([href^="/i/status"])')
  3752. if (!userProfileLink) continue
  3753.  
  3754. isBlueTweet = true
  3755. }
  3756. }
  3757. }
  3758. }
  3759. else if (!timelineHasSpecificHandling) {
  3760. if ($item.querySelector(':scope > div > div > div > article')) {
  3761. itemType = 'UNAVAILABLE'
  3762. }
  3763. }
  3764.  
  3765. if (!timelineHasSpecificHandling) {
  3766. if (itemType != null) {
  3767. hideItem = shouldHideOtherTimelineItem(itemType)
  3768. }
  3769. }
  3770.  
  3771. if (itemType == null) {
  3772. if ($item.querySelector(Selectors.TIMELINE_HEADING)) {
  3773. itemType = 'HEADING'
  3774. hideItem = hideHeadings && config.hideWhoToFollowEtc
  3775. }
  3776. }
  3777.  
  3778. if (debug && itemType != null) {
  3779. $item.firstElementChild.dataset.itemType = `${itemType}${isReply ? ' / REPLY' : ''}${isBlueTweet ? ' / BLUE' : ''}`
  3780. }
  3781.  
  3782. // Assume a non-identified item following an identified item is related
  3783. if (itemType == null && hidPreviousItem != null) {
  3784. hideItem = hidPreviousItem
  3785. itemType = 'SUBSEQUENT_ITEM'
  3786. }
  3787.  
  3788. if (itemType != null) {
  3789. itemTypes[itemType] ||= 0
  3790. itemTypes[itemType]++
  3791. }
  3792.  
  3793. if (hideItem) {
  3794. hiddenItemCount++
  3795. hiddenItemTypes[itemType] ||= 0
  3796. hiddenItemTypes[itemType]++
  3797. }
  3798.  
  3799. if (hideItem != null && $item.firstElementChild) {
  3800. if (/** @type {HTMLElement} */ ($item.firstElementChild).style.display != (hideItem ? 'none' : '')) {
  3801. changes.push({$item, hideItem})
  3802. }
  3803. }
  3804.  
  3805. hidPreviousItem = hideItem
  3806. }
  3807.  
  3808. for (let change of changes) {
  3809. /** @type {HTMLElement} */ (change.$item.firstElementChild).style.display = change.hideItem ? 'none' : ''
  3810. }
  3811.  
  3812. log(
  3813. `processed ${$timeline.children.length} timeline item${s($timeline.children.length)} in ${Date.now() - startTime}ms`,
  3814. itemTypes, `hid ${hiddenItemCount}`, hiddenItemTypes
  3815. )
  3816. }
  3817.  
  3818. /**
  3819. * @param {HTMLElement} $timeline
  3820. * @param {import("./types").IndividualTweetTimelineOptions} options
  3821. */
  3822. function onIndividualTweetTimelineChange($timeline, options) {
  3823. let startTime = Date.now()
  3824.  
  3825. let itemTypes = {}
  3826. let hiddenItemCount = 0
  3827. let hiddenItemTypes = {}
  3828.  
  3829. /** @type {?boolean} */
  3830. let hidPreviousItem = null
  3831. /** @type {boolean} */
  3832. let hideAllSubsequentItems = false
  3833. /** @type {string} */
  3834. let opScreenName = /^\/([a-zA-Z\d_]{1,20})\//.exec(location.pathname)[1].toLowerCase()
  3835. /** @type {{$item: Element, hideItem?: boolean}[]} */
  3836. let changes = []
  3837. /** @type {import("./types").UserInfoObject} */
  3838. let userInfo = getUserInfo()
  3839. /** @type {?HTMLElement} */
  3840. let $focusedTweet
  3841.  
  3842. for (let $item of $timeline.children) {
  3843. /** @type {?import("./types").TimelineItemType} */
  3844. let itemType = null
  3845. /** @type {?boolean} */
  3846. let hideItem = null
  3847. /** @type {?HTMLElement} */
  3848. let $tweet = $item.querySelector(Selectors.TWEET)
  3849. /** @type {boolean} */
  3850. let isFocusedTweet = false
  3851. /** @type {boolean} */
  3852. let isReply = false
  3853. /** @type {boolean} */
  3854. let isBlueTweet = false
  3855. /** @type {boolean} */
  3856. let isShy = false
  3857. /** @type {?string} */
  3858. let screenName = null
  3859.  
  3860. if (hideAllSubsequentItems) {
  3861. hideItem = true
  3862. itemType = 'DISCOVER_MORE_TWEET'
  3863. }
  3864. else if ($tweet != null) {
  3865. isFocusedTweet = $tweet.tabIndex == -1
  3866. isReply = isReplyToPreviousTweet($tweet)
  3867. if (isFocusedTweet) {
  3868. itemType = 'FOCUSED_TWEET'
  3869. hideItem = false
  3870. $focusedTweet = $tweet
  3871. } else {
  3872. itemType = getTweetType($tweet)
  3873. if (isReply && hidPreviousItem != null) {
  3874. hideItem = hidPreviousItem
  3875. } else {
  3876. hideItem = shouldHideIndividualTweetTimelineItem(itemType)
  3877. }
  3878. }
  3879.  
  3880. if (config.twitterBlueChecks != 'ignore' || config.hideTwitterBlueReplies) {
  3881. for (let $svg of $tweet.querySelectorAll(Selectors.VERIFIED_TICK)) {
  3882. let isBlueCheck = isBlueVerified($svg)
  3883. if (!isBlueCheck) continue
  3884.  
  3885. if (config.twitterBlueChecks != 'ignore') {
  3886. blueCheck($svg)
  3887. }
  3888.  
  3889. let $userProfileLink = /** @type {HTMLAnchorElement} */ ($svg.closest('a[role="link"]:not([href^="/i/status"])'))
  3890. if (!$userProfileLink) continue
  3891.  
  3892. isBlueTweet = true
  3893. screenName = $userProfileLink.href.split('/').pop()
  3894. }
  3895.  
  3896. // Check replies to the focused tweet for Blue users hiding their check
  3897. // if (!isBlueTweet && !isFocusedTweet && !isReply) {
  3898. // let $userProfileLink = /** @type {HTMLAnchorElement} */ ($tweet.querySelector('[data-testid="User-Name"] a'))
  3899. // if ($userProfileLink) {
  3900. // screenName = $userProfileLink.href.split('/').pop()
  3901. // if (userInfo[screenName]?.shyBlue) {
  3902. // isBlueTweet = true
  3903. // isShy = true
  3904. // }
  3905. // }
  3906. // }
  3907.  
  3908. // Replies to the focused tweet don't have the reply indicator
  3909. if (isBlueTweet && !isFocusedTweet && !isReply && screenName.toLowerCase() != opScreenName) {
  3910. itemType = 'BLUE_REPLY'
  3911. if (!hideItem) {
  3912. let user = userInfo[screenName]
  3913. hideItem = config.hideTwitterBlueReplies && (user == null || !(
  3914. user.following && !config.hideBlueReplyFollowing ||
  3915. user.followedBy && !config.hideBlueReplyFollowedBy ||
  3916. user.followersCount >= 1000000 && config.showBlueReplyFollowersCount
  3917. ))
  3918. }
  3919. }
  3920. }
  3921. }
  3922. else if ($item.querySelector('article')) {
  3923. if ($item.querySelector('[role="button"]')?.textContent == getString('SHOW')) {
  3924. itemType = 'SHOW_MORE'
  3925. } else {
  3926. itemType = 'UNAVAILABLE'
  3927. hideItem = config.hideUnavailableQuoteTweets
  3928. }
  3929. } else {
  3930. // We need to identify "Show more replies" so it doesn't get hidden if the
  3931. // item immediately before it was hidden.
  3932. let $button = $item.querySelector('div[role="button"]')
  3933. if ($button) {
  3934. if ($button?.textContent == getString('SHOW_MORE_REPLIES')) {
  3935. itemType = 'SHOW_MORE'
  3936. }
  3937. } else {
  3938. let $heading = $item.querySelector(Selectors.TIMELINE_HEADING)
  3939. if ($heading) {
  3940. // Discover More headings have a description next to them
  3941. if ($heading.nextElementSibling &&
  3942. $heading.nextElementSibling.tagName == 'DIV' &&
  3943. $heading.nextElementSibling.getAttribute('dir') != null) {
  3944. itemType = 'DISCOVER_MORE_HEADING'
  3945. hideItem = config.hideMoreTweets
  3946. hideAllSubsequentItems = config.hideMoreTweets
  3947. } else {
  3948. itemType = 'HEADING'
  3949. }
  3950. }
  3951. }
  3952. }
  3953.  
  3954. if (debug && itemType != null) {
  3955. $item.firstElementChild.dataset.itemType = `${itemType}${isReply ? ' / REPLY' : ''}${isBlueTweet && itemType != 'BLUE_REPLY' ? ' / BLUE' : ''}${isShy ? ' / SHY' : ''}`
  3956. }
  3957.  
  3958. // Assume a non-identified item following an identified item is related
  3959. if (itemType == null && hidPreviousItem != null) {
  3960. hideItem = hidPreviousItem
  3961. itemType = 'SUBSEQUENT_ITEM'
  3962. }
  3963.  
  3964. if (itemType != null) {
  3965. itemTypes[itemType] ||= 0
  3966. itemTypes[itemType]++
  3967. }
  3968.  
  3969. if (hideItem) {
  3970. hiddenItemCount++
  3971. hiddenItemTypes[itemType] ||= 0
  3972. hiddenItemTypes[itemType]++
  3973. }
  3974.  
  3975. if (isFocusedTweet) {
  3976. // Tweets prior to the focused tweet should never be hidden
  3977. changes = []
  3978. hiddenItemCount = 0
  3979. hiddenItemTypes = {}
  3980. }
  3981. else if (hideItem != null && $item.firstElementChild) {
  3982. if (/** @type {HTMLElement} */ ($item.firstElementChild).style.display != (hideItem ? 'none' : '')) {
  3983. changes.push({$item, hideItem})
  3984. }
  3985. }
  3986.  
  3987. hidPreviousItem = hideItem
  3988. }
  3989.  
  3990. for (let change of changes) {
  3991. /** @type {HTMLElement} */ (change.$item.firstElementChild).style.display = change.hideItem ? 'none' : ''
  3992. }
  3993.  
  3994. if (config.replaceLogo) {
  3995. tweakFocusedTweet($focusedTweet, options)
  3996. }
  3997.  
  3998. log(
  3999. `processed ${$timeline.children.length} thread item${s($timeline.children.length)} in ${Date.now() - startTime}ms`,
  4000. itemTypes, `hid ${hiddenItemCount}`, hiddenItemTypes
  4001. )
  4002. }
  4003.  
  4004. /**
  4005. * Title format (including notification count):
  4006. * - LTR: (3) ${title} / X
  4007. * - RTL: (3) X \ ${title}
  4008. * @param {string} title
  4009. */
  4010. function onTitleChange(title) {
  4011. log('title changed', {title, path: location.pathname})
  4012.  
  4013. if (checkforDisabledHomeTimeline()) return
  4014.  
  4015. // Ignore leading notification counts in titles
  4016. let notificationCount = ''
  4017. if (TITLE_NOTIFICATION_RE.test(title)) {
  4018. notificationCount = TITLE_NOTIFICATION_RE.exec(title)[0]
  4019. title = title.replace(TITLE_NOTIFICATION_RE, '')
  4020. }
  4021.  
  4022. if (config.replaceLogo && Boolean(notificationCount) != Boolean(currentNotificationCount)) {
  4023. observeFavicon.updatePip(Boolean(notificationCount))
  4024. }
  4025.  
  4026. let homeNavigationWasUsed = homeNavigationIsBeingUsed
  4027. homeNavigationIsBeingUsed = false
  4028.  
  4029. if (title == 'X' || title == getString('TWITTER')) {
  4030. // Mobile uses "Twitter" when viewing media - we need to let these process
  4031. // so the next page will be re-processed when the media is closed.
  4032. if (mobile && (URL_MEDIA_RE.test(location.pathname) || URL_MEDIAVIEWER_RE.test(location.pathname))) {
  4033. log('viewing media on mobile')
  4034. }
  4035. // Ignore Flash of Uninitialised Title when navigating to a page for the
  4036. // first time.
  4037. else {
  4038. log('ignoring Flash of Uninitialised Title')
  4039. return
  4040. }
  4041. }
  4042.  
  4043. // Remove " / Twitter" or "Twitter \ " from the title
  4044. let newPage = title
  4045. if (newPage != 'X' && newPage != getString('TWITTER')) {
  4046. newPage = title.slice(...ltr ? [0, title.lastIndexOf('/') - 1] : [title.indexOf('\\') + 2])
  4047. }
  4048.  
  4049. // Only allow the same page to re-process after a title change on desktop if
  4050. // the "Customize your view" dialog is currently open.
  4051. if (newPage == currentPage && !(desktop && location.pathname == PagePaths.CUSTOMIZE_YOUR_VIEW)) {
  4052. log('ignoring duplicate title change')
  4053. currentNotificationCount = notificationCount
  4054. return
  4055. }
  4056.  
  4057. // Search terms are shown in the title
  4058. if (currentPath == PagePaths.SEARCH && location.pathname == PagePaths.SEARCH) {
  4059. log('ignoring title change on Search page')
  4060. currentNotificationCount = notificationCount
  4061. return
  4062. }
  4063.  
  4064. // On desktop, stay on the separated tweets timeline when…
  4065. if (desktop && currentPage == separatedTweetsTimelineTitle &&
  4066. // …the title has changed back to the main timeline…
  4067. (newPage == getString('HOME')) &&
  4068. // …the Home nav link or Following / Home header _wasn't_ clicked and…
  4069. !homeNavigationWasUsed &&
  4070. (
  4071. // …the user viewed media.
  4072. URL_MEDIA_RE.test(location.pathname) ||
  4073. // …the user stopped viewing media.
  4074. URL_MEDIA_RE.test(currentPath) ||
  4075. // …the user opened or used the "Customize your view" dialog.
  4076. location.pathname == PagePaths.CUSTOMIZE_YOUR_VIEW ||
  4077. // …the user closed the "Customize your view" dialog.
  4078. currentPath == PagePaths.CUSTOMIZE_YOUR_VIEW ||
  4079. // …the user opened the "Send via Direct Message" dialog.
  4080. location.pathname == PagePaths.COMPOSE_MESSAGE ||
  4081. // …the user closed the "Send via Direct Message" dialog.
  4082. currentPath == PagePaths.COMPOSE_MESSAGE ||
  4083. // …the user opened the compose Tweet dialog.
  4084. location.pathname == PagePaths.COMPOSE_TWEET ||
  4085. // …the user closed the compose Tweet dialog.
  4086. currentPath == PagePaths.COMPOSE_TWEET ||
  4087. // …the notification count in the title changed.
  4088. notificationCount != currentNotificationCount
  4089. )) {
  4090. log('ignoring title change on separated tweets timeline')
  4091. currentNotificationCount = notificationCount
  4092. currentPath = location.pathname
  4093. setTitle(separatedTweetsTimelineTitle)
  4094. return
  4095. }
  4096.  
  4097. // Restore display of the separated tweets timelne if it's the last one we
  4098. // saw, and the user navigated back home without using the Home navigation
  4099. // item.
  4100. if (location.pathname == PagePaths.HOME &&
  4101. currentPath != PagePaths.HOME &&
  4102. !homeNavigationWasUsed &&
  4103. lastMainTimelineTitle != null &&
  4104. separatedTweetsTimelineTitle != null &&
  4105. lastMainTimelineTitle == separatedTweetsTimelineTitle) {
  4106. log('restoring display of the separated tweets timeline')
  4107. currentNotificationCount = notificationCount
  4108. currentPath = location.pathname
  4109. setTitle(separatedTweetsTimelineTitle)
  4110. return
  4111. }
  4112.  
  4113. // Assumption: all non-FOUT, non-duplicate title changes are navigation, which
  4114. // need the page to be re-processed.
  4115.  
  4116. currentPage = newPage
  4117. currentNotificationCount = notificationCount
  4118. currentPath = location.pathname
  4119.  
  4120. if (isOnMainTimelinePage()) {
  4121. lastMainTimelineTitle = currentPage
  4122. }
  4123.  
  4124. log('processing new page')
  4125.  
  4126. processCurrentPage()
  4127. }
  4128.  
  4129. /**
  4130. * Processes all Twitter Blue checks inside an element.
  4131. * @param {HTMLElement} $el
  4132. */
  4133. function processBlueChecks($el) {
  4134. for (let $svg of $el.querySelectorAll(`${Selectors.VERIFIED_TICK}:not(.tnt_blue_check)`)) {
  4135. if (isBlueVerified($svg)) {
  4136. blueCheck($svg)
  4137. }
  4138. }
  4139. }
  4140.  
  4141. /**
  4142. * Processes all Twitter logos inside an element.
  4143. */
  4144. function processTwitterLogos($el) {
  4145. for (let $svgPath of $el.querySelectorAll(Selectors.X_LOGO_PATH)) {
  4146. twitterLogo($svgPath)
  4147. }
  4148. }
  4149.  
  4150. function processCurrentPage() {
  4151. if (pageObservers.length > 0) {
  4152. log(
  4153. `disconnecting ${pageObservers.length} page observer${s(pageObservers.length)}`,
  4154. pageObservers.map(observer => observer['name'])
  4155. )
  4156. pageObservers.forEach(observer => observer.disconnect())
  4157. pageObservers = []
  4158. }
  4159.  
  4160. // Hooks for styling pages
  4161. $body.classList.toggle('Community', isOnCommunityPage())
  4162. $body.classList.toggle('Explore', isOnExplorePage())
  4163. $body.classList.toggle('HideSidebar', shouldHideSidebar())
  4164. $body.classList.toggle('List', isOnListPage())
  4165. $body.classList.toggle('MainTimeline', isOnMainTimelinePage())
  4166. $body.classList.toggle('Notifications', isOnNotificationsPage())
  4167. $body.classList.toggle('Profile', isOnProfilePage())
  4168. if (!isOnProfilePage()) {
  4169. $body.classList.remove('Blocked', 'NoMedia')
  4170. }
  4171. $body.classList.toggle('QuoteTweets', isOnQuoteTweetsPage())
  4172. $body.classList.toggle('Tweet', isOnIndividualTweetPage())
  4173. $body.classList.toggle('Search', isOnSearchPage())
  4174. $body.classList.toggle('Settings', isOnSettingsPage())
  4175. $body.classList.toggle('MobileMedia', mobile && URL_MEDIA_RE.test(location.pathname))
  4176. $body.classList.toggle('MediaViewer', mobile && URL_MEDIAVIEWER_RE.test(location.pathname))
  4177. $body.classList.remove('TabbedTimeline')
  4178. $body.classList.remove('SeparatedTweets')
  4179.  
  4180. if (desktop) {
  4181. let shouldObserveSidebarForConfig = (
  4182. config.twitterBlueChecks != 'ignore' ||
  4183. config.fullWidthContent ||
  4184. config.hideExploreNav && config.hideExploreNavWithSidebar
  4185. )
  4186. if (shouldObserveSidebarForConfig && !isOnMessagesPage() && !isOnSettingsPage()) {
  4187. observeSidebar()
  4188. } else {
  4189. $body.classList.remove('Sidebar')
  4190. }
  4191. if (isSafari && config.replaceLogo) {
  4192. tweakDesktopLogo()
  4193. }
  4194. }
  4195.  
  4196. if (config.twitterBlueChecks != 'ignore' && (isOnSearchPage() || isOnExplorePage())) {
  4197. observeSearchForm()
  4198. }
  4199.  
  4200. if (isOnMainTimelinePage()) {
  4201. tweakMainTimelinePage()
  4202. }
  4203. else {
  4204. removeMobileTimelineHeaderElements()
  4205. }
  4206.  
  4207. if (isOnProfilePage()) {
  4208. tweakProfilePage()
  4209. }
  4210. else if (isOnFollowListPage()) {
  4211. tweakFollowListPage()
  4212. }
  4213. else if (isOnIndividualTweetPage()) {
  4214. tweakIndividualTweetPage()
  4215. }
  4216. else if (isOnNotificationsPage()) {
  4217. tweakNotificationsPage()
  4218. }
  4219. else if (isOnSearchPage()) {
  4220. tweakSearchPage()
  4221. }
  4222. else if (isOnQuoteTweetsPage()) {
  4223. tweakQuoteTweetsPage()
  4224. }
  4225. else if (isOnListPage()) {
  4226. tweakListPage()
  4227. }
  4228. else if (isOnExplorePage()) {
  4229. tweakExplorePage()
  4230. }
  4231. else if (isOnBookmarksPage()) {
  4232. tweakBookmarksPage()
  4233. }
  4234. else if (isOnCommunitiesPage()) {
  4235. tweakCommunitiesPage()
  4236. }
  4237. else if (isOnCommunityPage()) {
  4238. tweakCommunityPage()
  4239. }
  4240. else if (isOnCommunityMembersPage()) {
  4241. tweakCommunityMembersPage()
  4242. }
  4243.  
  4244. // On mobile, these are pages instead of modals
  4245. if (mobile) {
  4246. if (currentPath == PagePaths.COMPOSE_TWEET) {
  4247. tweakMobileComposeTweetPage()
  4248. }
  4249. else if (URL_MEDIAVIEWER_RE.test(currentPath)) {
  4250. tweakMobileMediaViewerPage()
  4251. }
  4252. else if (URL_TWEET_LIKES_RETWEETS_RE.test(currentPath)) {
  4253. tweakMobileUserListPage()
  4254. }
  4255. }
  4256. }
  4257.  
  4258. /**
  4259. * The mobile version of Twitter reuses heading elements between screens, so we
  4260. * always remove any elements which could be there from the previous page and
  4261. * re-add them later when needed.
  4262. */
  4263. function removeMobileTimelineHeaderElements() {
  4264. if (mobile) {
  4265. document.querySelector('#tnt_separated_tweets_tab')?.remove()
  4266. }
  4267. }
  4268.  
  4269. /**
  4270. * Sets the page name in <title>, retaining any current notification count.
  4271. * @param {string} page
  4272. */
  4273. function setTitle(page) {
  4274. document.title = ltr ? (
  4275. `${currentNotificationCount}${page} / ${getString('TWITTER')}`
  4276. ) : (
  4277. `${currentNotificationCount}${getString('TWITTER')} \\ ${page}`
  4278. )
  4279. }
  4280.  
  4281. /**
  4282. * @param {import("./types").TimelineItemType} type
  4283. * @returns {boolean}
  4284. */
  4285. function shouldHideIndividualTweetTimelineItem(type) {
  4286. switch (type) {
  4287. case 'QUOTE_TWEET':
  4288. case 'RETWEET':
  4289. case 'RETWEETED_QUOTE_TWEET':
  4290. case 'TWEET':
  4291. return false
  4292. case 'UNAVAILABLE_QUOTE_TWEET':
  4293. case 'UNAVAILABLE_RETWEET':
  4294. return config.hideUnavailableQuoteTweets
  4295. default:
  4296. return true
  4297. }
  4298. }
  4299.  
  4300. /**
  4301. * @param {import("./types").TimelineItemType} type
  4302. * @returns {boolean}
  4303. */
  4304. function shouldHideListTimelineItem(type) {
  4305. switch (type) {
  4306. case 'RETWEET':
  4307. case 'RETWEETED_QUOTE_TWEET':
  4308. return config.listRetweets == 'hide'
  4309. case 'UNAVAILABLE_QUOTE_TWEET':
  4310. return config.hideUnavailableQuoteTweets
  4311. case 'UNAVAILABLE_RETWEET':
  4312. return config.hideUnavailableQuoteTweets || config.listRetweets == 'hide'
  4313. default:
  4314. return false
  4315. }
  4316. }
  4317.  
  4318. /**
  4319. * @param {import("./types").TimelineItemType} type
  4320. * @param {string} page
  4321. * @returns {boolean}
  4322. */
  4323. function shouldHideMainTimelineItem(type, page) {
  4324. switch (type) {
  4325. case 'QUOTE_TWEET':
  4326. return shouldHideSharedTweet(config.quoteTweets, page)
  4327. case 'RETWEET':
  4328. return selectedHomeTabIndex >= 2 ? config.listRetweets == 'hide' : shouldHideSharedTweet(config.retweets, page)
  4329. case 'RETWEETED_QUOTE_TWEET':
  4330. return selectedHomeTabIndex >= 2 ? (
  4331. config.listRetweets == 'hide'
  4332. ) : (
  4333. shouldHideSharedTweet(config.retweets, page) || shouldHideSharedTweet(config.quoteTweets, page)
  4334. )
  4335. case 'TWEET':
  4336. return page == separatedTweetsTimelineTitle
  4337. case 'UNAVAILABLE_QUOTE_TWEET':
  4338. return config.hideUnavailableQuoteTweets || shouldHideSharedTweet(config.quoteTweets, page)
  4339. case 'UNAVAILABLE_RETWEET':
  4340. return config.hideUnavailableQuoteTweets || selectedHomeTabIndex >= 2 ? config.listRetweets == 'hide' : shouldHideSharedTweet(config.retweets, page)
  4341. default:
  4342. return true
  4343. }
  4344. }
  4345.  
  4346. /**
  4347. * @param {import("./types").TimelineItemType} type
  4348. * @returns {boolean}
  4349. */
  4350. function shouldHideProfileTimelineItem(type) {
  4351. switch (type) {
  4352. case 'PINNED_TWEET':
  4353. case 'QUOTE_TWEET':
  4354. case 'TWEET':
  4355. return false
  4356. case 'RETWEET':
  4357. case 'RETWEETED_QUOTE_TWEET':
  4358. return config.hideProfileRetweets
  4359. case 'UNAVAILABLE_QUOTE_TWEET':
  4360. return config.hideUnavailableQuoteTweets
  4361. default:
  4362. return true
  4363. }
  4364. }
  4365.  
  4366. /**
  4367. * @param {import("./types").TimelineItemType} type
  4368. * @returns {boolean}
  4369. */
  4370. function shouldHideOtherTimelineItem(type) {
  4371. switch (type) {
  4372. case 'QUOTE_TWEET':
  4373. case 'RETWEET':
  4374. case 'RETWEETED_QUOTE_TWEET':
  4375. case 'TWEET':
  4376. case 'UNAVAILABLE':
  4377. case 'UNAVAILABLE_QUOTE_TWEET':
  4378. case 'UNAVAILABLE_RETWEET':
  4379. return false
  4380. default:
  4381. return true
  4382. }
  4383. }
  4384.  
  4385. /**
  4386. * @param {import("./types").SharedTweetsConfig} config
  4387. * @param {string} page
  4388. * @returns {boolean}
  4389. */
  4390. function shouldHideSharedTweet(config, page) {
  4391. switch (config) {
  4392. case 'hide': return true
  4393. case 'ignore': return page == separatedTweetsTimelineTitle
  4394. case 'separate': return page != separatedTweetsTimelineTitle
  4395. }
  4396. }
  4397.  
  4398. async function tweakBookmarksPage() {
  4399. if (config.twitterBlueChecks != 'ignore') {
  4400. observeTimeline(currentPage, {
  4401. classifyTweets: false,
  4402. })
  4403. }
  4404. }
  4405.  
  4406. async function tweakExplorePage() {
  4407. if (!config.hideExplorePageContents) return
  4408.  
  4409. let $searchInput = await getElement('input[data-testid="SearchBox_Search_Input"]', {
  4410. name: 'explore page search input',
  4411. stopIf: () => !isOnExplorePage(),
  4412. })
  4413. if (!$searchInput) return
  4414.  
  4415. log('focusing search input')
  4416. $searchInput.focus()
  4417.  
  4418. if (mobile) {
  4419. // The back button appears after the search input is focused on mobile. When
  4420. // you tap it or otherwise navigate back, it's replaced with the slide-out
  4421. // menu button and Explore page contents are shown - we want to skip that.
  4422. let $backButton = await getElement('div[data-testid="app-bar-back"]', {
  4423. name: 'back button',
  4424. stopIf: () => !isOnExplorePage(),
  4425. })
  4426. if (!$backButton) return
  4427.  
  4428. pageObservers.push(
  4429. observeElement($backButton.parentElement, (mutations) => {
  4430. mutations.forEach((mutation) => {
  4431. mutation.addedNodes.forEach((/** @type {HTMLElement} */ $el) => {
  4432. if ($el.querySelector('[data-testid="DashButton_ProfileIcon_Link"]')) {
  4433. log('slide-out menu button appeared, going back to skip Explore page')
  4434. history.go(-2)
  4435. }
  4436. })
  4437. })
  4438. }, 'back button parent')
  4439. )
  4440. }
  4441. }
  4442.  
  4443. function tweakCommunitiesPage() {
  4444. observeTimeline(currentPage)
  4445. }
  4446.  
  4447. function tweakCommunityPage() {
  4448. if (config.twitterBlueChecks != 'ignore') {
  4449. observeTimeline(currentPage, {
  4450. classifyTweets: false,
  4451. isTabbed: true,
  4452. tabbedTimelineContainerSelector: `${Selectors.PRIMARY_COLUMN} > div > div:last-child`,
  4453. onTimelineAppeared() {
  4454. // The About tab has static content at the top which can include a check
  4455. if (/\/about\/?$/.test(location.pathname)) {
  4456. processBlueChecks(document.querySelector(Selectors.PRIMARY_COLUMN))
  4457. }
  4458. }
  4459. })
  4460. }
  4461. }
  4462.  
  4463. function tweakCommunityMembersPage() {
  4464. if (config.twitterBlueChecks != 'ignore') {
  4465. observeTimeline(currentPage, {
  4466. classifyTweets: false,
  4467. isTabbed: true,
  4468. timelineSelector: 'div[data-testid="primaryColumn"] > div > div:last-child',
  4469. })
  4470. }
  4471. }
  4472.  
  4473. /**
  4474. * @param {HTMLElement} $focusedTweet
  4475. * @param {import("./types").IndividualTweetTimelineOptions} options
  4476. */
  4477. async function tweakFocusedTweet($focusedTweet, options) {
  4478. let {observers} = options
  4479. if ($focusedTweet) {
  4480. // TODO Observe this if it's singular to catch it moving to plural
  4481. let $retweetsText = $focusedTweet.querySelector('a:is([href$="/retweets"], [href$="/reposts"]) > span > span')
  4482. if ($retweetsText) {
  4483. let currentText = $retweetsText.textContent
  4484. if (currentText != getString('RETWEETS') && currentText != getString('RETWEET')) {
  4485. $retweetsText.textContent = getString(currentText == getString('REPOSTS') ? 'RETWEETS' : 'RETWEET')
  4486. }
  4487. }
  4488.  
  4489. if (mobile) {
  4490. let $textArea = /** @type {HTMLTextAreaElement} */ (await getElement('textarea', {
  4491. context: $focusedTweet.parentElement,
  4492. name: 'mobile textarea',
  4493. timeout: 500,
  4494. }))
  4495. if ($textArea) {
  4496. if ($textArea.placeholder != getString('TWEET_YOUR_REPLY')) {
  4497. $textArea.placeholder = getString('TWEET_YOUR_REPLY')
  4498. }
  4499. return
  4500. }
  4501. }
  4502.  
  4503. if (!isObserving(observers, 'tweet editor')) {
  4504. let $editorRoot = await getElement('.DraftEditor-root', {
  4505. context: $focusedTweet.parentElement,
  4506. name: 'tweet editor in focused tweet',
  4507. timeout: 500,
  4508. })
  4509. if ($editorRoot && !isObserving(observers, 'tweet editor')) {
  4510. observers.unshift(
  4511. observeElement($editorRoot, () => {
  4512. if ($editorRoot.firstElementChild.classList.contains('public-DraftEditorPlaceholder-root')) {
  4513. let $placeholder = $editorRoot.querySelector('.public-DraftEditorPlaceholder-inner')
  4514. if ($placeholder) {
  4515. $placeholder.textContent = getString('TWEET_YOUR_REPLY')
  4516. }
  4517. }
  4518. }, 'tweet editor')
  4519. )
  4520. }
  4521. }
  4522. }
  4523. else {
  4524. disconnectObserver('tweet editor', observers)
  4525. }
  4526. }
  4527.  
  4528. function tweakFollowListPage() {
  4529. if (config.twitterBlueChecks != 'ignore') {
  4530. observeTimeline(currentPage, {
  4531. classifyTweets: false,
  4532. })
  4533. }
  4534. }
  4535.  
  4536. async function tweakIndividualTweetPage() {
  4537. observeIndividualTweetTimeline(currentPage)
  4538.  
  4539. if (config.replaceLogo) {
  4540. let $headingText = await getElement(`${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} h2 span`, {
  4541. name: 'tweet thread heading',
  4542. stopIf: pageIsNot(currentPage)
  4543. })
  4544. if ($headingText && $headingText.textContent != getString('TWEET')) {
  4545. $headingText.textContent = getString('TWEET')
  4546. }
  4547. }
  4548. }
  4549.  
  4550. function tweakListPage() {
  4551. observeTimeline(currentPage, {
  4552. hideHeadings: false,
  4553. })
  4554. }
  4555.  
  4556. async function tweakDesktopLogo() {
  4557. let $logoPath = await getElement(`h1 ${Selectors.X_LOGO_PATH}`, {name: 'desktop nav logo', timeout: 5000})
  4558. if ($logoPath) {
  4559. twitterLogo($logoPath)
  4560. }
  4561. }
  4562.  
  4563. async function tweakTweetBox() {
  4564. // Observe username typeahead dropdowns to replace Blue checks
  4565. if (config.twitterBlueChecks != 'ignore') {
  4566. let $tweetTextarea = await getElement(`${desktop ? 'div[data-testid="primaryColumn"]': 'main'} label[data-testid^="tweetTextarea"]`, {
  4567. name: 'tweet textarea',
  4568. stopIf: pageIsNot(currentPage),
  4569. })
  4570. if (!$tweetTextarea) return
  4571.  
  4572. /** @type {HTMLElement} */
  4573. let $typeaheadDropdown
  4574.  
  4575. pageObservers.push(
  4576. observeElement($tweetTextarea.parentElement.parentElement.parentElement.parentElement, (mutations) => {
  4577. for (let mutation of mutations) {
  4578. if ($typeaheadDropdown && mutations.some(mutation => Array.from(mutation.removedNodes).includes($typeaheadDropdown))) {
  4579. disconnectPageObserver('tweet textarea typeahead dropdown')
  4580. $typeaheadDropdown = null
  4581. }
  4582. for (let $addedNode of mutation.addedNodes) {
  4583. if ($addedNode instanceof HTMLElement && $addedNode.getAttribute('id')?.startsWith('typeaheadDropdown')) {
  4584. $typeaheadDropdown = $addedNode
  4585. pageObservers.push(
  4586. observeElement($typeaheadDropdown, () => {
  4587. processBlueChecks($typeaheadDropdown)
  4588. }, 'tweet textarea typeahead dropdown')
  4589. )
  4590. }
  4591. }
  4592. }
  4593. }, 'tweet textarea typeahead dropdown container')
  4594. )
  4595. }
  4596.  
  4597. if (config.replaceLogo) {
  4598. tweakTweetButton()
  4599. }
  4600. }
  4601.  
  4602. async function tweakTweetButton() {
  4603. let $tweetButton = await getElement(`${desktop ? 'div[data-testid="primaryColumn"]': 'main'} div[data-testid^="tweetButton"]`, {
  4604. name: 'tweet button',
  4605. stopIf: pageIsNot(currentPage),
  4606. })
  4607. if ($tweetButton) {
  4608. let $text = $tweetButton.querySelector('span > span')
  4609. if ($text) {
  4610. setTweetButtonText($text)
  4611. } else {
  4612. warn('could not find tweet button text')
  4613. }
  4614. }
  4615. }
  4616.  
  4617. function tweakMainTimelinePage() {
  4618. if (desktop) {
  4619. tweakTweetBox()
  4620. }
  4621.  
  4622. let $timelineTabs = document.querySelector(`${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} nav`)
  4623.  
  4624. // "Which version of the main timeline are we on?" hooks for styling
  4625. $body.classList.toggle('TabbedTimeline', $timelineTabs != null)
  4626. $body.classList.toggle('SeparatedTweets', isOnSeparatedTweetsTimeline())
  4627.  
  4628. if ($timelineTabs == null) {
  4629. warn('could not find timeline tabs')
  4630. return
  4631. }
  4632.  
  4633. tweakTimelineTabs($timelineTabs)
  4634. if (mobile && isSafari && config.replaceLogo) {
  4635. processTwitterLogos(document.querySelector(Selectors.MOBILE_TIMELINE_HEADER))
  4636. }
  4637.  
  4638. function updateSelectedHomeTabIndex() {
  4639. let $selectedHomeTabLink = $timelineTabs.querySelector('div[role="tablist"] a[aria-selected="true"]')
  4640. if ($selectedHomeTabLink) {
  4641. selectedHomeTabIndex = Array.from($selectedHomeTabLink.parentElement.parentElement.children).indexOf($selectedHomeTabLink.parentElement)
  4642. log({selectedHomeTabIndex})
  4643. } else {
  4644. warn('could not find selected Home tab link')
  4645. selectedHomeTabIndex = -1
  4646. }
  4647. }
  4648.  
  4649. updateSelectedHomeTabIndex()
  4650.  
  4651. // If there are pinned lists, the timeline tabs <nav> will be replaced when they load
  4652. pageObservers.push(
  4653. observeElement($timelineTabs.parentElement, (mutations) => {
  4654. let timelineTabsReplaced = mutations.some(mutation => Array.from(mutation.removedNodes).includes($timelineTabs))
  4655. if (timelineTabsReplaced) {
  4656. log('timeline tabs replaced')
  4657. $timelineTabs = document.querySelector(`${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} nav`)
  4658. tweakTimelineTabs($timelineTabs)
  4659. }
  4660. }, 'timeline tabs nav container')
  4661. )
  4662.  
  4663. observeTimeline(currentPage, {
  4664. isTabbed: true,
  4665. onTabChanged: () => {
  4666. updateSelectedHomeTabIndex()
  4667. wasForYouTabSelected = selectedHomeTabIndex == 0
  4668. },
  4669. tabbedTimelineContainerSelector: 'div[data-testid="primaryColumn"] > div > div:last-child > div',
  4670. })
  4671. }
  4672.  
  4673. function tweakMobileComposeTweetPage() {
  4674. tweakTweetBox()
  4675. }
  4676.  
  4677. function tweakMobileMediaViewerPage() {
  4678. if (config.twitterBlueChecks == 'ignore') return
  4679.  
  4680. let $timeline = /** @type {HTMLElement} */ (document.querySelector('[data-testid="vss-scroll-view"] > div'))
  4681. if (!$timeline) {
  4682. warn('media viewer timeline not found')
  4683. return
  4684. }
  4685.  
  4686. observeElement($timeline, (mutations) => {
  4687. for (let mutation of mutations) {
  4688. if (!mutation.addedNodes) continue
  4689. for (let $addedNode of mutation.addedNodes) {
  4690. if ($addedNode.querySelector?.('div[data-testid^="immersive-tweet-ui-content-container"]')) {
  4691. processBlueChecks($addedNode)
  4692. }
  4693. }
  4694. }
  4695. }, 'media viewer timeline', {childList: true, subtree: true})
  4696. }
  4697.  
  4698. async function tweakTimelineTabs($timelineTabs) {
  4699. let $followingTabLink = /** @type {HTMLElement} */ ($timelineTabs.querySelector('div[role="tablist"] > div:nth-child(2) > a'))
  4700.  
  4701. if (config.alwaysUseLatestTweets && !document.title.startsWith(separatedTweetsTimelineTitle)) {
  4702. let isForYouTabSelected = Boolean($timelineTabs.querySelector('div[role="tablist"] > div:first-child > a[aria-selected="true"]'))
  4703. if (isForYouTabSelected && (!wasForYouTabSelected || config.hideForYouTimeline)) {
  4704. log('switching to Following timeline')
  4705. $followingTabLink.click()
  4706. wasForYouTabSelected = false
  4707. } else {
  4708. wasForYouTabSelected = isForYouTabSelected
  4709. }
  4710. }
  4711.  
  4712. if (shouldShowSeparatedTweetsTab()) {
  4713. let $newTab = /** @type {HTMLElement} */ ($timelineTabs.querySelector('#tnt_separated_tweets_tab'))
  4714. if ($newTab) {
  4715. log('separated tweets timeline tab already present')
  4716. $newTab.querySelector('span').textContent = separatedTweetsTimelineTitle
  4717. }
  4718. else {
  4719. log('inserting separated tweets tab')
  4720. $newTab = /** @type {HTMLElement} */ ($followingTabLink.parentElement.cloneNode(true))
  4721. $newTab.id = 'tnt_separated_tweets_tab'
  4722. $newTab.querySelector('span').textContent = separatedTweetsTimelineTitle
  4723. let $link = $newTab.querySelector('a')
  4724. $link.removeAttribute('aria-selected')
  4725.  
  4726. // This script assumes navigation has occurred when the document title
  4727. // changes, so by changing the title we fake navigation to a non-existent
  4728. // page representing the separated tweets timeline.
  4729. $link.addEventListener('click', (e) => {
  4730. e.preventDefault()
  4731. e.stopPropagation()
  4732. if (!document.title.startsWith(separatedTweetsTimelineTitle)) {
  4733. // The separated tweets tab belongs to the Following tab
  4734. let isFollowingTabSelected = Boolean($timelineTabs.querySelector('div[role="tablist"] > div:nth-child(2) > a[aria-selected="true"]'))
  4735. if (!isFollowingTabSelected) {
  4736. log('switching to the Following tab for separated tweets')
  4737. $followingTabLink.click()
  4738. }
  4739. setTitle(separatedTweetsTimelineTitle)
  4740. }
  4741. window.scrollTo({top: 0})
  4742. })
  4743. $followingTabLink.parentElement.insertAdjacentElement('afterend', $newTab)
  4744.  
  4745. // Return to the main timeline view when any other tab is clicked
  4746. $followingTabLink.parentElement.parentElement.addEventListener('click', () => {
  4747. if (location.pathname == '/home' && !document.title.startsWith(getString('HOME'))) {
  4748. log('setting title to Home')
  4749. homeNavigationIsBeingUsed = true
  4750. setTitle(getString('HOME'))
  4751. }
  4752. })
  4753.  
  4754. // Return to the main timeline when the Home nav link is clicked
  4755. let $homeNavLink = await getElement(Selectors.NAV_HOME_LINK, {
  4756. name: 'home nav link',
  4757. stopIf: pathIsNot(currentPath),
  4758. })
  4759. if ($homeNavLink && !$homeNavLink.dataset.tweakNewTwitterListener) {
  4760. $homeNavLink.addEventListener('click', () => {
  4761. homeNavigationIsBeingUsed = true
  4762. if (location.pathname == '/home' && !document.title.startsWith(getString('HOME'))) {
  4763. setTitle(getString('HOME'))
  4764. }
  4765. })
  4766. $homeNavLink.dataset.tweakNewTwitterListener = 'true'
  4767. }
  4768. }
  4769. } else {
  4770. removeMobileTimelineHeaderElements()
  4771. }
  4772. }
  4773.  
  4774. async function tweakMobileUserListPage() {
  4775. tweakUserModalTimelineHeading(currentPath)
  4776. observeUserListTimeline({initialPath: currentPath, observers: pageObservers})
  4777. }
  4778.  
  4779. function tweakNotificationsPage() {
  4780. let $navigationTabs = document.querySelector(`${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} nav`)
  4781. if ($navigationTabs == null) {
  4782. warn('could not find Notifications tabs')
  4783. return
  4784. }
  4785.  
  4786. if (config.hideVerifiedNotificationsTab) {
  4787. let isVerifiedTabSelected = Boolean($navigationTabs.querySelector('div[role="tablist"] > div:nth-child(2) > a[aria-selected="true"]'))
  4788. if (isVerifiedTabSelected) {
  4789. log('switching to All tab')
  4790. $navigationTabs.querySelector('div[role="tablist"] > div:nth-child(1) > a')?.click()
  4791. }
  4792. }
  4793.  
  4794. if (config.twitterBlueChecks != 'ignore') {
  4795. observeTimeline(currentPage, {
  4796. classifyTweets: false,
  4797. isTabbed: true,
  4798. tabbedTimelineContainerSelector: 'div[data-testid="primaryColumn"] > div > div:last-child',
  4799. })
  4800. }
  4801. }
  4802.  
  4803. async function tweakProfilePage() {
  4804. if (config.twitterBlueChecks != 'ignore') {
  4805. if (mobile) {
  4806. processBlueChecks(document.querySelector(Selectors.MOBILE_TIMELINE_HEADER))
  4807. }
  4808. processBlueChecks(document.querySelector(Selectors.PRIMARY_COLUMN))
  4809. }
  4810.  
  4811. observeTimeline(currentPage)
  4812.  
  4813. if (desktop && config.hideSidebarContent) {
  4814. observeProfileBlockedStatus(currentPage)
  4815. observeProfileSidebar(currentPage)
  4816. }
  4817.  
  4818. if (config.replaceLogo) {
  4819. let $profileTabs = await getElement(`${Selectors.PRIMARY_COLUMN} nav`, {
  4820. name: 'profile tabs',
  4821. stopIf: pageIsNot(currentPage),
  4822. })
  4823. if (!$profileTabs) return
  4824. // The Profile tabs <nav> can be replaced
  4825. pageObservers.push(
  4826. observeElement($profileTabs.parentElement, async (mutations) => {
  4827. if (mutations.length > 0) {
  4828. let $newProfileTabs = findAddedNode(mutations, ($el) => $el instanceof HTMLElement && $el.tagName == 'NAV')
  4829. if ($newProfileTabs == null) return
  4830. $profileTabs = /** @type {HTMLElement} */ ($newProfileTabs)
  4831. }
  4832. let $tweetsTabText = await getElement('[data-testid="ScrollSnap-List"] > [role="presentation"]:first-child div[dir] > span:first-child', {
  4833. context: $profileTabs,
  4834. name: 'Tweets tab text',
  4835. stopIf: pageIsNot(currentPage),
  4836. })
  4837. if ($tweetsTabText && $tweetsTabText.textContent != getString('TWEETS')) {
  4838. $tweetsTabText.textContent = getString('TWEETS')
  4839. }
  4840. }, 'profile tabs', {childList: true})
  4841. )
  4842. }
  4843. }
  4844.  
  4845. async function tweakQuoteTweetsPage() {
  4846. if (config.twitterBlueChecks != 'ignore') {
  4847. observeTimeline(currentPage)
  4848. }
  4849. if (config.replaceLogo) {
  4850. let $headingText = await getElement(`${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} h2 span`, {
  4851. name: 'quote tweets heading',
  4852. stopIf: pageIsNot(currentPage)
  4853. })
  4854. if ($headingText) {
  4855. $headingText.textContent = getString('QUOTE_TWEETS')
  4856. }
  4857. }
  4858. }
  4859.  
  4860. async function tweakRetweetsDropdown($retweetDropdownItem) {
  4861. log('tweaking Retweet/Quote Tweet dropdown')
  4862.  
  4863. if (desktop) {
  4864. $retweetDropdownItem = await getElement(`
  4865. #layers div[data-testid="Dropdown"] div:is([data-testid="retweetConfirm"], [data-testid="repostConfirm"]
  4866. `, {
  4867. name: 'rendered Retweet menu item',
  4868. timeout: 100,
  4869. })
  4870. if (!$retweetDropdownItem) return
  4871. }
  4872.  
  4873. let $retweetText = $retweetDropdownItem.querySelector('div[dir] > span')
  4874. if ($retweetText) $retweetText.textContent = getString('RETWEET')
  4875.  
  4876. let $quoteTweetText = $retweetDropdownItem.nextElementSibling?.querySelector('div[dir] > span')
  4877. if ($quoteTweetText) $quoteTweetText.textContent = getString('QUOTE_TWEET')
  4878. }
  4879.  
  4880. async function tweakUserModalTimelineHeading(initialPath) {
  4881. let listType = initialPath.match(URL_TWEET_LIKES_RETWEETS_RE)?.[1]
  4882. if (!config.replaceLogo || !listType || listType == 'likes') return
  4883.  
  4884. let $headingText = await getElement(`h2#modal-header span`, {
  4885. name: 'Retweeted by heading',
  4886. stopIf: not(() => initialPath == location.pathname),
  4887. })
  4888. if (!$headingText) return
  4889.  
  4890. $headingText.textContent = getString('RETWEETED_BY')
  4891. }
  4892.  
  4893. function tweakSearchPage() {
  4894. let $searchTabs = document.querySelector(`${mobile ? Selectors.MOBILE_TIMELINE_HEADER : Selectors.PRIMARY_COLUMN} nav`)
  4895. if ($searchTabs != null) {
  4896. if (config.defaultToLatestSearch) {
  4897. let isTopTabSelected = Boolean($searchTabs.querySelector('div[role="tablist"] > div:nth-child(1) > a[aria-selected="true"]'))
  4898. if (isTopTabSelected) {
  4899. log('switching to Latest tab')
  4900. $searchTabs.querySelector('div[role="tablist"] > div:nth-child(2) > a')?.click()
  4901. }
  4902. }
  4903. } else {
  4904. warn('could not find Search tabs')
  4905. }
  4906.  
  4907. observeTimeline(currentPage, {
  4908. hideHeadings: false,
  4909. isTabbed: true,
  4910. tabbedTimelineContainerSelector: 'div[data-testid="primaryColumn"] > div > div:last-child',
  4911. })
  4912. }
  4913. //#endregion
  4914.  
  4915. //#region Main
  4916. async function main() {
  4917. let $settings = /** @type {HTMLScriptElement} */ (document.querySelector('script#tnt_settings'))
  4918. if ($settings) {
  4919. try {
  4920. Object.assign(config, JSON.parse($settings.innerText))
  4921. } catch(e) {
  4922. error('error parsing initial settings', e)
  4923. }
  4924.  
  4925. let settingsChangeObserver = new MutationObserver(() => {
  4926. /** @type {Partial<import("./types").Config>} */
  4927. let configChanges
  4928. try {
  4929. configChanges = JSON.parse($settings.innerText)
  4930. } catch(e) {
  4931. error('error parsing incoming settings change', e)
  4932. return
  4933. }
  4934.  
  4935. if ('debug' in configChanges) {
  4936. log('disabling debug mode')
  4937. debug = configChanges.debug
  4938. log('enabled debug mode')
  4939. configureThemeCss()
  4940. return
  4941. }
  4942.  
  4943. Object.assign(config, configChanges)
  4944. configChanged(configChanges)
  4945. })
  4946. settingsChangeObserver.observe($settings, {childList: true})
  4947. }
  4948.  
  4949. if (config.debug) {
  4950. debug = true
  4951. }
  4952.  
  4953. observeTitle()
  4954.  
  4955. let $loadingStyle
  4956. if (config.replaceLogo) {
  4957. getElement('html', {name: 'html element'}).then(($html) => {
  4958. $loadingStyle = document.createElement('style')
  4959. $loadingStyle.dataset.insertedBy = 'control-panel-for-twitter'
  4960. $loadingStyle.dataset.role = 'loading-logo'
  4961. let fill = themeColor || THEME_BLUE
  4962. $loadingStyle.textContent = dedent(`
  4963. ${Selectors.X_LOGO_PATH} {
  4964. fill: ${isSafari ? 'transparent' : fill};
  4965. d: path("${Svgs.TWITTER_LOGO_PATH}");
  4966. }
  4967. .tnt_logo {
  4968. fill: ${fill};
  4969. }
  4970. `)
  4971. $html.appendChild($loadingStyle)
  4972. })
  4973.  
  4974. if (isSafari) {
  4975. getElement(Selectors.X_LOGO_PATH, {name: 'pre-loading indicator logo', timeout: 1000}).then(($logoPath) => {
  4976. if ($logoPath) {
  4977. twitterLogo($logoPath)
  4978. }
  4979. })
  4980. }
  4981.  
  4982. observeFavicon()
  4983. }
  4984.  
  4985. let $appWrapper = await getElement('#layers + div', {name: 'app wrapper'})
  4986.  
  4987. $html = document.querySelector('html')
  4988. $body = document.body
  4989. $reactRoot = document.querySelector('#react-root')
  4990. lang = $html.lang
  4991. dir = $html.dir
  4992. ltr = dir == 'ltr'
  4993. let lastFlexDirection
  4994.  
  4995. observeElement($appWrapper, () => {
  4996. let flexDirection = getComputedStyle($appWrapper).flexDirection
  4997.  
  4998. mobile = flexDirection == 'column'
  4999. desktop = !mobile
  5000.  
  5001. /** @type {'mobile' | 'desktop'} */
  5002. let version = mobile ? 'mobile' : 'desktop'
  5003.  
  5004. if (version != config.version) {
  5005. log('setting version to', version)
  5006. config.version = version
  5007. // Let the options page know which version is being used
  5008. storeConfigChanges({version})
  5009. }
  5010.  
  5011. if (lastFlexDirection == null) {
  5012. log('initial config', {config, lang, version})
  5013.  
  5014. // One-time setup
  5015. checkReactNativeStylesheet()
  5016. observeBodyBackgroundColor()
  5017. observeColor()
  5018.  
  5019. // Repeatable configuration setup
  5020. configureSeparatedTweetsTimelineTitle()
  5021. configureCss()
  5022. configureThemeCss()
  5023. observeHtmlFontSize()
  5024. observePopups()
  5025. observeSideNavTweetButton()
  5026.  
  5027. // Start taking action on page changes
  5028. observingPageChanges = true
  5029.  
  5030. // Delay removing loading icon styles to avoid Flash of X
  5031. if ($loadingStyle) {
  5032. setTimeout(() => $loadingStyle.remove(), 1000)
  5033. }
  5034. }
  5035. else if (flexDirection != lastFlexDirection) {
  5036. observeHtmlFontSize()
  5037. configChanged({version})
  5038. }
  5039.  
  5040. $body.classList.toggle('Mobile', mobile)
  5041. $body.classList.toggle('Desktop', desktop)
  5042.  
  5043. lastFlexDirection = flexDirection
  5044. }, 'app wrapper class attribute for version changes (mobile ↔ desktop)', {
  5045. attributes: true,
  5046. attributeFilter: ['class']
  5047. })
  5048. }
  5049.  
  5050. /**
  5051. * @param {Partial<import("./types").Config>} changes
  5052. */
  5053. function configChanged(changes) {
  5054. log('config changed', changes)
  5055.  
  5056. configureCss()
  5057. configureFont()
  5058. configureNavFontSizeCss()
  5059. configureThemeCss()
  5060. observeFavicon()
  5061. observePopups()
  5062. observeSideNavTweetButton()
  5063.  
  5064. // Only re-process the current page if navigation wasn't already triggered
  5065. // while applying the following config changes (if there were any).
  5066. let navigationTriggered = (
  5067. configureSeparatedTweetsTimelineTitle() ||
  5068. checkforDisabledHomeTimeline()
  5069. )
  5070. if (!navigationTriggered) {
  5071. processCurrentPage()
  5072. }
  5073. }
  5074.  
  5075. main()
  5076. //#endregion
  5077.  
  5078. }()