Twitter 媒体下载

一键保存视频/图片

目前为 2023-07-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Twitter Media Downloader
  3. // @name:ja Twitter Media Downloader
  4. // @name:zh-cn Twitter 媒体下载
  5. // @name:zh-tw Twitter 媒體下載
  6. // @description Save Video/Photo by One-Click.
  7. // @description:ja ワンクリックで動画・画像を保存する。
  8. // @description:zh-cn 一键保存视频/图片
  9. // @description:zh-tw 一鍵保存視頻/圖片
  10. // @version 1.10
  11. // @author AMANE
  12. // @namespace none
  13. // @match https://twitter.com/*
  14. // @match https://mobile.twitter.com/*
  15. // @match https://tweetdeck.twitter.com/*
  16. // @grant GM_registerMenuCommand
  17. // @grant GM_setValue
  18. // @grant GM_getValue
  19. // @grant GM_download
  20. // @compatible Chrome
  21. // @compatible Firefox
  22. // ==/UserScript==
  23. /* jshint esversion: 8 */
  24.  
  25. const filename = 'twitter_{user-name}(@{user-id})_{date-time}_{status-id}_{file-type}';
  26.  
  27. const TMD = (function () {
  28. let lang, host, history, show_sensitive, is_tweetdeck;
  29. return {
  30. init: async function () {
  31. GM_registerMenuCommand((this.language[navigator.language] || this.language.en).settings, this.settings);
  32. document.head.insertAdjacentHTML('beforeend', '<style>' + this.css + '</style>');
  33. lang = this.language[document.querySelector('html').lang] || this.language.en;
  34. host = location.hostname;
  35. is_tweetdeck = host.indexOf('tweetdeck') >= 0;
  36. history = this.storage_obsolete();
  37. if (history.length) {
  38. this.storage(history);
  39. this.storage_obsolete(true);
  40. } else history = await this.storage();
  41. show_sensitive = GM_getValue('show_sensitive', false);
  42. },
  43. inject: function (article) {
  44. let media_selector = [
  45. 'a[href*="/photo/1"]',
  46. 'div[role="progressbar"]',
  47. 'div[data-testid="playButton"]',
  48. 'a[href="/settings/content_you_see"]', //hidden content
  49. 'div.media-image-container', // for tweetdeck
  50. 'div.media-preview-container', // for tweetdeck
  51. 'div[aria-labelledby]>div:first-child>div[role="button"][tabindex="0"]' //for audio (experimental)
  52. ];
  53. let media = article.querySelector(media_selector.join(','));
  54. if (media) {
  55. let status_id = article.querySelector('a[href*="/status/"]').href.split('/status/').pop().split('/').shift();
  56. let btn_group = article.querySelector('div[role="group"]:last-of-type, ul.tweet-actions, ul.tweet-detail-actions');
  57. let btn_share = Array.from(btn_group.querySelectorAll(':scope>div>div, li.tweet-action-item>a, li.tweet-detail-action-item>a')).pop().parentNode;
  58. let btn_down = btn_share.cloneNode(true);
  59. if (is_tweetdeck) {
  60. btn_down.firstElementChild.innerHTML = '<svg viewBox="0 0 24 24" style="width: 18px; height: 18px;">' + this.svg + '</svg>';
  61. btn_down.firstElementChild.removeAttribute('rel');
  62. btn_down.classList.replace("pull-left", "pull-right");
  63. } else {
  64. btn_down.querySelector('svg').innerHTML = this.svg;
  65. }
  66. let is_exist = history.indexOf(status_id) >= 0;
  67. this.status(btn_down, 'tmd-down');
  68. this.status(btn_down, is_exist ? 'completed' : 'download', is_exist ? lang.completed : lang.download);
  69. btn_group.insertBefore(btn_down, btn_share.nextSibling);
  70. btn_down.onclick = () => this.click(btn_down, status_id, is_exist);
  71. article.dataset.injected = 'true';
  72. if (show_sensitive) {
  73. let btn_show = article.querySelector('div[aria-labelledby] div[role="button"][tabindex="0"]:not([data-testid]) > div[dir] > span > span');
  74. if (btn_show) btn_show.click();
  75. }
  76. }
  77. let imgs = article.querySelectorAll('a[href*="/photo/"]');
  78. if (imgs.length > 1) {
  79. let status_id = article.querySelector('a[href*="/status/"]').href.split('/status/').pop().split('/').shift();
  80. let btn_group = article.querySelector('div[role="group"]:last-of-type');
  81. let btn_share = Array.from(btn_group.querySelectorAll(':scope>div>div')).pop().parentNode;
  82. imgs.forEach(img => {
  83. let index = img.href.split('/status/').pop().split('/').pop();
  84. let btn_down = btn_share.cloneNode(true);
  85. btn_down.querySelector('svg').innerHTML = this.svg;
  86. let is_exist = history.indexOf(status_id) >= 0;
  87. this.status(btn_down, 'tmd-down');
  88. this.status(btn_down, 'tmd-img');
  89. this.status(btn_down, 'download', lang.download);
  90. img.parentNode.appendChild(btn_down);
  91. btn_down.onclick = () => this.click(btn_down, status_id, is_exist, index);
  92. });
  93. }
  94. },
  95. click: async function (btn, status_id, is_exist, index) {
  96. if (btn.classList.contains('loading')) return;
  97. this.status(btn, 'loading');
  98. let out = (await GM_getValue('filename', filename)).split('\n').join('');
  99. let save_history = await GM_getValue('save_history', true);
  100. let json = await this.fetchJson(status_id);
  101. let tweet = json.legacy;
  102. let user = json.core.user_results.result.legacy;
  103. let invalid_chars = {'\\': '\', '\/': '/', '\|': '|', '<': '<', '>': '>', ':': ':', '*': '*', '?': '?', '"': '"', '\u200b': '', '\u200c': '', '\u200d': '', '\u2060': '', '\ufeff': '', '🔞': ''};
  104. let datetime = out.match(/{date-time(-local)?:[^{}]+}/) ? out.match(/{date-time(?:-local)?:([^{}]+)}/)[1].replace(/[\\/|<>*?:"]/g, v => invalid_chars[v]) : 'YYYYMMDD-hhmmss';
  105. let info = {};
  106. info['status-id'] = status_id;
  107. info['user-name'] = user.name.replace(/([\\/|*?:"]|[\u200b-\u200d\u2060\ufeff]|🔞)/g, v => invalid_chars[v]);
  108. info['user-id'] = user.screen_name;
  109. info['date-time'] = this.formatDate(tweet.created_at, datetime);
  110. info['date-time-local'] = this.formatDate(tweet.created_at, datetime, true);
  111. info['full-text'] = tweet.full_text.split('\n').join(' ').replace(/\s*https:\/\/t\.co\/\w+/g, '').replace(/[\\/|<>*?:"]|[\u200b-\u200d\u2060\ufeff]/g, v => invalid_chars[v]);
  112. let medias = tweet.extended_entities && tweet.extended_entities.media;
  113. if (index) medias = [medias[index - 1]];
  114. if (medias.length > 0) {
  115. let tasks = medias.length;
  116. let tasks_result = [];
  117. medias.forEach((media, i) => {
  118. info.url = media.type == 'photo' ? media.media_url_https + ':orig' : media.video_info.variants.filter(n => n.content_type == 'video/mp4').sort((a, b) => b.bitrate - a.bitrate)[0].url;
  119. info.file = info.url.split('/').pop().split(/[:?]/).shift();
  120. info['file-name'] = info.file.split('.').shift();
  121. info['file-ext'] = info.file.split('.').pop();
  122. info['file-type'] = media.type.replace('animated_', '');
  123. info.out = (out.replace(/\.?{file-ext}/, '') + ((medias.length > 1 || index) && !out.match('{file-name}') ? '-' + (index ? index - 1 : i) : '') + '.{file-ext}').replace(/{([^{}:]+)(:[^{}]+)?}/g, (match, name) => info[name]);
  124. this.downloader.add({
  125. url: info.url,
  126. name: info.out,
  127. onload: () => {
  128. tasks -= 1;
  129. tasks_result.push(((medias.length > 1 || index) ? (index ? index : i + 1) + ': ' : '') + lang.completed);
  130. this.status(btn, null, tasks_result.sort().join('\n'));
  131. if (tasks === 0) {
  132. this.status(btn, 'completed', lang.completed);
  133. if (save_history && !is_exist) {
  134. history.push(status_id);
  135. this.storage(status_id);
  136. }
  137. }
  138. },
  139. onerror: result => {
  140. tasks = -1;
  141. tasks_result.push((medias.length > 1 ? i + 1 + ': ' : '') + result.details.current);
  142. this.status(btn, 'failed', tasks_result.sort().join('\n'));
  143. }
  144. });
  145. });
  146. } else {
  147. this.status(btn, 'failed', 'MEDIA_NOT_FOUND');
  148. }
  149. },
  150. status: function (btn, css, title, style) {
  151. if (css) {
  152. btn.classList.remove('download', 'completed', 'loading', 'failed');
  153. btn.classList.add(css);
  154. }
  155. if (title) btn.title = title;
  156. if (style) btn.style.cssText = style;
  157. },
  158. settings: async function () {
  159. const $element = (parent, tag, style, content, css) => {
  160. let el = document.createElement(tag);
  161. if (style) el.style.cssText = style;
  162. if (typeof content !== 'undefined') {
  163. if (tag == 'input') {
  164. if (content == 'checkbox') el.type = content;
  165. else el.value = content;
  166. } else el.innerHTML = content;
  167. }
  168. if (css) css.split(' ').forEach(c => el.classList.add(c));
  169. parent.appendChild(el);
  170. return el;
  171. };
  172. let wapper = $element(document.body, 'div', 'position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; background-color: #0009; z-index: 10;');
  173. let wapper_close;
  174. wapper.onmousedown = e => {
  175. wapper_close = e.target == wapper;
  176. };
  177. wapper.onmouseup = e => {
  178. if (wapper_close && e.target == wapper) wapper.remove();
  179. };
  180. let dialog = $element(wapper, 'div', 'position: absolute; left: 50%; top: 50%; transform: translateX(-50%) translateY(-50%); width: fit-content; width: -moz-fit-content; background-color: #f3f3f3; border: 1px solid #ccc; border-radius: 10px; color: black;');
  181. let title = $element(dialog, 'h3', 'margin: 10px 20px;', lang.dialog.title);
  182. let options = $element(dialog, 'div', 'margin: 10px; border: 1px solid #ccc; border-radius: 5px;');
  183. let save_history_label = $element(options, 'label', 'display: block; margin: 10px;', lang.dialog.save_history);
  184. let save_history_input = $element(save_history_label, 'input', 'float: left;', 'checkbox');
  185. save_history_input.checked = await GM_getValue('save_history', true);
  186. save_history_input.onchange = () => {
  187. GM_setValue('save_history', save_history_input.checked);
  188. }
  189. let clear_history = $element(save_history_label, 'label', 'display: inline-block; margin: 0 10px; color: blue;', lang.dialog.clear_history);
  190. clear_history.onclick = () => {
  191. if (confirm(lang.dialog.clear_confirm)) {
  192. history = [];
  193. GM_setValue('download_history', []);
  194. }
  195. };
  196. let show_sensitive_label = $element(options, 'label', 'display: block; margin: 10px;', lang.dialog.show_sensitive);
  197. let show_sensitive_input = $element(show_sensitive_label, 'input', 'float: left;', 'checkbox');
  198. show_sensitive_input.checked = await GM_getValue('show_sensitive', false);
  199. show_sensitive_input.onchange = () => {
  200. show_sensitive = show_sensitive_input.checked;
  201. GM_setValue('show_sensitive', show_sensitive);
  202. };
  203. let filename_div = $element(dialog, 'div', 'margin: 10px; border: 1px solid #ccc; border-radius: 5px;');
  204. let filename_label = $element(filename_div, 'label', 'display: block; margin: 10px 15px;', lang.dialog.pattern);
  205. let filename_input = $element(filename_label, 'textarea', 'display: block; min-width: 500px; max-width: 500px; min-height: 100px; font-size: inherit; background: white; color: black;', await GM_getValue('filename', filename));
  206. let filename_tags = $element(filename_div, 'label', 'display: table; margin: 10px;', `
  207. <span class="tmd-tag" title="user name">{user-name}</span>
  208. <span class="tmd-tag" title="The user name after @ sign.">{user-id}</span>
  209. <span class="tmd-tag" title="example: 1234567890987654321">{status-id}</span>
  210. <span class="tmd-tag" title="{date-time} : Posted time in UTC.\n{date-time-local} : Your local time zone.\n\nDefault:\nYYYYMMDD-hhmmss => 20201231-235959\n\nExample of custom:\n{date-time:DD-MMM-YY hh.mm} => 31-DEC-21 23.59">{date-time}</span><br>
  211. <span class="tmd-tag" title="Text content in tweet.">{full-text}</span>
  212. <span class="tmd-tag" title="Type of &#34;video&#34; or &#34;photo&#34; or &#34;gif&#34;.">{file-type}</span>
  213. <span class="tmd-tag" title="Original filename from URL.">{file-name}</span>
  214. `);
  215. filename_input.selectionStart = filename_input.value.length;
  216. filename_tags.querySelectorAll('.tmd-tag').forEach(tag => {
  217. tag.onclick = () => {
  218. let ss = filename_input.selectionStart;
  219. let se = filename_input.selectionEnd;
  220. filename_input.value = filename_input.value.substring(0, ss) + tag.innerText + filename_input.value.substring(se);
  221. filename_input.selectionStart = ss + tag.innerText.length;
  222. filename_input.selectionEnd = ss + tag.innerText.length;
  223. filename_input.focus();
  224. };
  225. });
  226. let btn_save = $element(title, 'label', 'float: right;', lang.dialog.save, 'tmd-btn');
  227. btn_save.onclick = async () => {
  228. await GM_setValue('filename', filename_input.value);
  229. wapper.remove();
  230. };
  231. },
  232. fetchJson: async function (status_id) {
  233. let base_url = `https://${host}/i/api/graphql/NmCeCgkVlsRGS1cAwqtgmw/TweetDetail`;
  234. let variables = {
  235. "focalTweetId":status_id,
  236. "with_rux_injections":false,
  237. "includePromotedContent":true,
  238. "withCommunity":true,
  239. "withQuickPromoteEligibilityTweetFields":true,
  240. "withBirdwatchNotes":true,
  241. "withVoice":true,
  242. "withV2Timeline":true
  243. };
  244. let features = {
  245. "rweb_lists_timeline_redesign_enabled":true,
  246. "responsive_web_graphql_exclude_directive_enabled":true,
  247. "verified_phone_label_enabled":false,
  248. "creator_subscriptions_tweet_preview_api_enabled":true,
  249. "responsive_web_graphql_timeline_navigation_enabled":true,
  250. "responsive_web_graphql_skip_user_profile_image_extensions_enabled":false,
  251. "tweetypie_unmention_optimization_enabled":true,
  252. "responsive_web_edit_tweet_api_enabled":true,
  253. "graphql_is_translatable_rweb_tweet_is_translatable_enabled":true,
  254. "view_counts_everywhere_api_enabled":true,
  255. "longform_notetweets_consumption_enabled":true,
  256. "responsive_web_twitter_article_tweet_consumption_enabled":false,
  257. "tweet_awards_web_tipping_enabled":false,
  258. "freedom_of_speech_not_reach_fetch_enabled":true,
  259. "standardized_nudges_misinfo":true,
  260. "tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled":true,
  261. "longform_notetweets_rich_text_read_enabled":true,
  262. "longform_notetweets_inline_media_enabled":true,
  263. "responsive_web_media_download_video_enabled":false,
  264. "responsive_web_enhance_cards_enabled":false
  265. };
  266. let url = encodeURI(`${base_url}?variables=${JSON.stringify(variables)}&features=${JSON.stringify(features)}`);
  267. let cookies = this.getCookie();
  268. let headers = {
  269. 'authorization': 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA',
  270. 'x-twitter-active-user': 'yes',
  271. 'x-twitter-client-language': cookies.lang,
  272. 'x-csrf-token': cookies.ct0
  273. };
  274. if (cookies.ct0.length == 32) headers['x-guest-token'] = cookies.gt;
  275. let tweet_detail = await fetch(url, {headers: headers}).then(result => result.json());
  276. let tweet_result = tweet_detail.data.threaded_conversation_with_injections_v2.instructions[0].entries[0].content.itemContent.tweet_results.result;
  277. return tweet_result;
  278. },
  279. getCookie: function (name) {
  280. let cookies = {};
  281. document.cookie.split(';').filter(n => n.indexOf('=') > 0).forEach(n => {
  282. n.replace(/^([^=]+)=(.+)$/, (match, name, value) => {
  283. cookies[name.trim()] = value.trim();
  284. });
  285. });
  286. return name ? cookies[name] : cookies;
  287. },
  288. storage: async function (value) {
  289. let data = await GM_getValue('download_history', []);
  290. let data_length = data.length;
  291. if (value) {
  292. if (Array.isArray(value)) data = data.concat(value);
  293. else if (data.indexOf(value) < 0) data.push(value);
  294. } else return data;
  295. if (data.length > data_length) GM_setValue('download_history', data);
  296. },
  297. storage_obsolete: function (is_remove) {
  298. let data = JSON.parse(localStorage.getItem('history') || '[]');
  299. if (is_remove) localStorage.removeItem('history');
  300. else return data;
  301. },
  302. formatDate: function (i, o, tz) {
  303. let d = new Date(i);
  304. if (tz) d.setMinutes(d.getMinutes() - d.getTimezoneOffset());
  305. let m = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'];
  306. let v = {
  307. YYYY: d.getUTCFullYear().toString(),
  308. YY: d.getUTCFullYear().toString(),
  309. MM: d.getUTCMonth() + 1,
  310. MMM: m[d.getUTCMonth()],
  311. DD: d.getUTCDate(),
  312. hh: d.getUTCHours(),
  313. mm: d.getUTCMinutes(),
  314. ss: d.getUTCSeconds(),
  315. h2: d.getUTCHours() % 12,
  316. ap: d.getUTCHours() < 12 ? 'AM' : 'PM'
  317. };
  318. return o.replace(/(YY(YY)?|MMM?|DD|hh|mm|ss|h2|ap)/g, n => ('0' + v[n]).substr(-n.length));
  319. },
  320. downloader: (function () {
  321. let tasks = [], thread = 0, max_thread = 2, retry = 0, max_retry = 2, failed = 0, notifier, has_failed = false;
  322. return {
  323. add: function (task) {
  324. tasks.push(task);
  325. if (thread < max_thread) {
  326. thread += 1;
  327. this.next();
  328. } else this.update();
  329. },
  330. next: async function () {
  331. let task = tasks.shift();
  332. await this.start(task);
  333. if (tasks.length > 0 && thread <= max_thread) this.next();
  334. else thread -= 1;
  335. this.update();
  336. },
  337. start: function (task) {
  338. this.update();
  339. return new Promise(resolve => {
  340. GM_download({
  341. url: task.url,
  342. name: task.name,
  343. onload: result => {
  344. task.onload();
  345. resolve();
  346. },
  347. onerror: result => {
  348. this.retry(task, result);
  349. resolve();
  350. },
  351. ontimeout: result => {
  352. this.retry(task, result);
  353. resolve();
  354. }
  355. });
  356. });
  357. },
  358. retry: function (task, result) {
  359. retry += 1;
  360. if (retry == 3) max_thread = 1;
  361. if (task.retry && task.retry >= max_retry ||
  362. result.details && result.details.current == 'USER_CANCELED') {
  363. task.onerror(result);
  364. failed += 1;
  365. } else {
  366. if (max_thread == 1) task.retry = (task.retry || 0) + 1;
  367. this.add(task);
  368. }
  369. },
  370. update: function() {
  371. if (!notifier) {
  372. notifier = document.createElement('div');
  373. notifier.title = 'Twitter Media Downloader';
  374. notifier.classList.add('tmd-notifier');
  375. notifier.innerHTML = '<label>0</label>|<label>0</label>';
  376. document.body.appendChild(notifier);
  377. }
  378. if (failed > 0 && !has_failed) {
  379. has_failed = true;
  380. notifier.innerHTML += '|';
  381. let clear = document.createElement('label');
  382. notifier.appendChild(clear);
  383. clear.onclick = () => {
  384. notifier.innerHTML = '<label>0</label>|<label>0</label>';
  385. failed = 0;
  386. has_failed = false;
  387. this.update();
  388. };
  389. }
  390. notifier.firstChild.innerText = thread;
  391. notifier.firstChild.nextElementSibling.innerText = tasks.length;
  392. if (failed > 0) notifier.lastChild.innerText = failed;
  393. if (thread > 0 || tasks.length > 0 || failed > 0) notifier.classList.add('running');
  394. else notifier.classList.remove('running');
  395. }
  396. };
  397. })(),
  398. language: {
  399. en: {download: 'Download', completed: 'Download Completed', settings: 'Settings', dialog: {title: 'Download Settings', save: 'Save', save_history: 'Remember download history', clear_history: '(Clear)', clear_confirm: 'Clear download history?', show_sensitive: 'Always show sensitive content', pattern: 'File Name Pattern'}},
  400. ja: {download: 'ダウンロード', completed: 'ダウンロード完了', settings: '設定', dialog: {title: 'ダウンロード設定', save: '保存', save_history: 'ダウンロード履歴を保存する', clear_history: '(クリア)', clear_confirm: 'ダウンロード履歴を削除する?', show_sensitive: 'センシティブな内容を常に表示する', pattern: 'ファイル名パターン'}},
  401. zh: {download: '下载', completed: '下载完成', settings: '设置', dialog: {title: '下载设置', save: '保存', save_history: '保存下载记录', clear_history: '(清除)', clear_confirm: '确认要清除下载记录?', show_sensitive: '自动显示敏感的内容', pattern: '文件名格式'}},
  402. 'zh-Hant': {download: '下載', completed: '下載完成', settings: '設置', dialog: {title: '下載設置', save: '保存', save_history: '保存下載記錄', clear_history: '(清除)', clear_confirm: '確認要清除下載記錄?', show_sensitive: '自動顯示敏感的内容', pattern: '文件名規則'}}
  403. },
  404. css: `
  405. .tmd-down > div > div > div:nth-child(2) {display: none}
  406. .tmd-down:hover > div > div > div {color: rgba(29, 161, 242, 1.0);}
  407. .tmd-down:hover > div > div > div > div > div {background-color: rgba(29, 161, 242, 0.1);}
  408. .tmd-down:active > div > div > div > div > div {background-color: rgba(29, 161, 242, 0.2);}
  409. .tmd-down g {display: none;}
  410. .tmd-down.download g.download, .tmd-down.completed g.completed, .tmd-down.loading g.loading,.tmd-down.failed g.failed {display: unset;}
  411. .tmd-down.loading svg {animation: spin 1s linear infinite;}
  412. @keyframes spin {0% {transform: rotate(0deg);} 100% {transform: rotate(360deg);}}
  413. .tmd-btn {display: inline-block; background-color: #1DA1F2; color: #FFFFFF; padding: 0 20px; border-radius: 99px;}
  414. .tmd-tag {display: inline-block; background-color: #FFFFFF; color: #1DA1F2; padding: 0 10px; border-radius: 10px; border: 1px solid #1DA1F2; font-weight: bold; margin: 5px;}
  415. .tmd-btn:hover {background-color: rgba(29, 161, 242, 0.9);}
  416. .tmd-tag:hover {background-color: rgba(29, 161, 242, 0.1);}
  417. .tmd-notifier {display: none; position: fixed; left: 16px; bottom: 16px; background: #fff; border: 1px solid #ccc; border-radius: 8px; padding: 4px;}
  418. .tmd-notifier.running {display: flex; align-items: center;}
  419. .tmd-notifier label {display: inline-flex; align-items: center; margin: 0 8px;}
  420. .tmd-notifier label:before {content: " "; width: 32px; height: 16px; background-position: center; background-repeat: no-repeat;}
  421. .tmd-notifier label:nth-child(1):before {background-image:url("data:image/svg+xml;charset=utf8,<svg xmlns=%22http://www.w3.org/2000/svg%22 width=%2216%22 height=%2216%22 viewBox=%220 0 24 24%22><path d=%22M3,14 v5 q0,2 2,2 h14 q2,0 2,-2 v-5 M7,10 l4,4 q1,1 2,0 l4,-4 M12,3 v11%22 fill=%22none%22 stroke=%22%23666%22 stroke-width=%222%22 stroke-linecap=%22round%22 /></svg>");}
  422. .tmd-notifier label:nth-child(2):before {background-image:url("data:image/svg+xml;charset=utf8,<svg xmlns=%22http://www.w3.org/2000/svg%22 width=%2216%22 height=%2216%22 viewBox=%220 0 24 24%22><path d=%22M12,2 a1,1 0 0 1 0,20 a1,1 0 0 1 0,-20 M12,5 v7 h6%22 fill=%22none%22 stroke=%22%23999%22 stroke-width=%222%22 stroke-linejoin=%22round%22 stroke-linecap=%22round%22 /></svg>");}
  423. .tmd-notifier label:nth-child(3):before {background-image:url("data:image/svg+xml;charset=utf8,<svg xmlns=%22http://www.w3.org/2000/svg%22 width=%2216%22 height=%2216%22 viewBox=%220 0 24 24%22><path d=%22M12,0 a2,2 0 0 0 0,24 a2,2 0 0 0 0,-24%22 fill=%22%23f66%22 stroke=%22none%22 /><path d=%22M14.5,5 a1,1 0 0 0 -5,0 l0.5,9 a1,1 0 0 0 4,0 z M12,17 a2,2 0 0 0 0,5 a2,2 0 0 0 0,-5%22 fill=%22%23fff%22 stroke=%22none%22 /></svg>");}
  424. .tmd-down.tmd-img {position: absolute; right: .75em; bottom: .75em; display: none !important;}
  425. :hover > .tmd-down.tmd-img, .tmd-img.loading, .tmd-img.completed, .tmd-img.failed {display: block !important;}
  426. :hover > .tmd-down.tmd-img > div > div > div {color: rgba(0, 0, 0, 0.6);}
  427. :hover > .tmd-down.tmd-img > div > div > div > div > div {background-color: rgba(255,255,255, 0.6);}
  428. :hover > .tmd-down.tmd-img:hover > div > div > div {color: rgba(29, 161, 242, 1.0);}
  429. .tweet-detail-action-item {width: 20% !important;}
  430. `,
  431. svg: `
  432. <g class="download"><path d="M3,14 v5 q0,2 2,2 h14 q2,0 2,-2 v-5 M7,10 l4,4 q1,1 2,0 l4,-4 M12,3 v11" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" /></g>
  433. <g class="completed"><path d="M3,14 v5 q0,2 2,2 h14 q2,0 2,-2 v-5 M7,10 l3,4 q1,1 2,0 l8,-11" fill="none" stroke="#1DA1F2" stroke-width="2" stroke-linecap="round" /></g>
  434. <g class="loading"><circle cx="12" cy="12" r="10" fill="none" stroke="#1DA1F2" stroke-width="4" opacity="0.4" /><path d="M12,2 a10,10 0 0 1 10,10" fill="none" stroke="#1DA1F2" stroke-width="4" stroke-linecap="round" /></g>
  435. <g class="failed"><circle cx="12" cy="12" r="11" fill="#f33" stroke="currentColor" stroke-width="2" opacity="0.8" /><path d="M14,5 a1,1 0 0 0 -4,0 l0.5,9.5 a1.5,1.5 0 0 0 3,0 z M12,17 a2,2 0 0 0 0,4 a2,2 0 0 0 0,-4" fill="#fff" stroke="none" /></g>
  436. `
  437. };
  438. })();
  439.  
  440. (function () {
  441. TMD.init();
  442. new MutationObserver(ms => ms.forEach(m => m.addedNodes.forEach(node => {
  443. let article = node.tagName == 'ARTICLE' && node || node.tagName == 'DIV' && (node.querySelector('article') || node.closest('article'));
  444. if (article && !article.dataset.injected) TMD.inject(article);
  445. }))).observe(document.body, {childList: true, subtree: true});
  446. })();