Control Panel for Twitter

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

当前为 2024-01-26 提交的版本,查看 最新版本

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