Control Panel for Twitter

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

当前为 2023-08-14 提交的版本,查看 最新版本

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