bsky Media Downloader

Save Video/Photo by One-Click.

  1. // ==UserScript==
  2. // @name bsky Media Downloader
  3. // @name:ja bsky Media Downloader
  4. // @name:zh-cn bsky 媒体下载
  5. // @name:zh-tw bsky 媒體下載
  6. // @description Save Video/Photo by One-Click.
  7. // @description:ja ワンクリックで動画・画像を保存する。
  8. // @description:zh-cn 一键保存视频/图片
  9. // @description:zh-tw 一鍵保存視頻/圖片
  10. // @version 0.2
  11. // @author MJ
  12. // @namespace none
  13. // @match https://bsky.app/*
  14. // @grant GM_registerMenuCommand
  15. // @grant GM_setValue
  16. // @grant GM_getValue
  17. // @grant GM_download
  18. // @license MIT
  19. // ==/UserScript==
  20. /* jshint esversion: 8 */
  21.  
  22. const filename = 'bsky_{user-name}(@{user-id})_{date-time}_{rkey}_{file-type}';
  23.  
  24. const TMD = (function () {
  25. let lang, host, history, show_sensitive;
  26. return {
  27. init: async function () {
  28. GM_registerMenuCommand((this.language[navigator.language] || this.language.en).settings, this.settings);
  29. lang = this.language[document.querySelector('html').lang.substr(0, 2)] || this.language.en;
  30. host = location.hostname;
  31. history = this.storage_obsolete();
  32. if (history.length) {
  33. this.storage(history);
  34. this.storage_obsolete(true);
  35. } else history = await this.storage();
  36. show_sensitive = GM_getValue('show_sensitive', false);
  37. document.head.insertAdjacentHTML('beforeend', '<style>' + this.css + (show_sensitive ? this.css_ss : '') + '</style>');
  38. let observer = new MutationObserver(ms => ms.forEach(m => m.addedNodes.forEach(node => this.detect(node))));
  39. observer.observe(document.body, {
  40. childList: true,
  41. subtree: true
  42. });
  43. },
  44. detect: function (node) {
  45. if (typeof node.querySelector !== 'function') return;
  46. let nodediv = '';
  47. if (window.location.pathname.includes('/post/')) {
  48. nodediv = node.querySelector('div[data-testid*="postThreadItem"]');
  49. if (nodediv) nodediv = nodediv.lastChild;
  50. } else if (window.location.pathname.includes('/hashtag/') || window.location.pathname.includes('/search?')) {
  51. nodediv = node.querySelector('div[role="link"]>div');
  52. if (nodediv) {
  53. let nodechildren = node.lastChild.children;
  54. for (let i=1;i<nodechildren.length;i++) {
  55. nodediv = nodechildren[i].querySelector('div[role="link"]');
  56. if (nodediv) {
  57. nodediv = nodediv.lastChild.lastChild;
  58. if (nodediv) this.addButtonTo(nodediv);
  59. }
  60. }
  61. }
  62. return;
  63. } else {
  64. nodediv = node.querySelector('div[role="link"]>div');
  65. if (nodediv) nodediv = nodediv.lastChild.lastChild;
  66. }
  67. if (nodediv) this.addButtonTo(nodediv);
  68. },
  69. extractPostInfo: function (posturl, mediaurl) {
  70. const res = {
  71. handle: '',
  72. did: '',
  73. rkey: '',
  74. h_r: '',
  75. };
  76. const match_post = posturl.match(/^https:\/\/bsky\.app\/profile\/([^/]+)\/post\/([^/]+)$/);
  77. if (match_post) {
  78. res.handle = match_post[1];
  79. res.rkey = match_post[2];
  80. res.h_r = res.handle + '_' + res.rkey;
  81. }
  82. mediaurl = decodeURIComponent(mediaurl);
  83. const match_media = mediaurl.match(/did:plc:([^/]+)\//);
  84. if (match_media) {
  85. res.did = match_media[1];
  86. }
  87. return res;
  88. },
  89. addButtonTo: function (nodediv) {
  90. if (nodediv.dataset.detected) return;
  91. nodediv.dataset.detected = 'true';
  92. let _this = this;
  93. let observer = new MutationObserver(function(mutations) {
  94. mutations.forEach(function(mutation) {
  95. if (mutation.type === 'childList') {
  96. observer.disconnect(); // 停止观察
  97. mutation.addedNodes.forEach((node) => {
  98. if (node.tagName === 'DIV' || node.tagName === 'FIGURE') {
  99. let media = node.querySelector('img, video');
  100. if (media.tagName === 'VIDEO' || media.tagName === 'IMG') {
  101. if (media) {
  102. let mediaurl = '';
  103. if (media.tagName == 'VIDEO') {
  104. mediaurl = media.poster;
  105. } else if (media.tagName == 'IMG') {
  106. mediaurl = media.src;
  107. }
  108. let btn_group = nodediv.lastChild;
  109. let posturlhrefa = nodediv.querySelector('a[href*="/post/"]');
  110. let posturl = '';
  111. if (posturlhrefa) {
  112. posturl = posturlhrefa.href;
  113. } else {
  114. btn_group = btn_group.lastChild;
  115. posturl = window.location.href;
  116. }
  117. if (btn_group.dataset.detected) return;
  118. btn_group.dataset.detected = 'true';
  119. let btn_more = btn_group.lastChild;
  120. let btn_down = btn_more.cloneNode(true);
  121.  
  122. let post_info = _this.extractPostInfo(posturl, mediaurl);
  123. btn_down.lastChild.querySelector('svg').innerHTML = _this.svg;
  124. let is_exist = history.indexOf(post_info.h_r) >= 0;
  125. _this.status(btn_down, 'tmd-down');
  126. _this.status(btn_down, is_exist ? 'completed' : 'download', is_exist ? lang.completed : lang.download);
  127. btn_group.appendChild(btn_down);
  128. btn_down.onclick = (event) => _this.click(event, btn_down, post_info, is_exist);
  129. if (show_sensitive) {
  130. let btn_show = nodediv.querySelector('div[aria-labelledby] div[role="button"][tabindex="0"]:not([data-testid]) > div[dir] > span > span');
  131. if (btn_show) btn_show.click();
  132. }
  133. }
  134. }
  135. }
  136. });
  137. }
  138. });
  139. });
  140. observer.observe(nodediv, {
  141. childList: true, // 观察子节点的变化
  142. subtree: true // 观察整个子树
  143. });
  144. },
  145. click: async function (event, btn, post_info, is_exist) {
  146. event.stopPropagation(); // 阻止事件冒泡
  147. if (btn.classList.contains('loading')) return;
  148. this.status(btn, 'loading');
  149. let out = (await GM_getValue('filename', filename)).split('\n').join('');
  150. let save_history = await GM_getValue('save_history', true);
  151. const json = await this.fetchJson(post_info);
  152. const threadPost = json.thread.post;
  153. let invalid_chars = {
  154. '\\': '\',
  155. '\/': '/',
  156. '\|': '|',
  157. '<': '<',
  158. '>': '>',
  159. ':': ':',
  160. '*': '*',
  161. '?': '?',
  162. '"': '"',
  163. '\u200b': '',
  164. '\u200c': '',
  165. '\u200d': '',
  166. '\u2060': '',
  167. '\ufeff': '',
  168. '🔞': ''
  169. };
  170. const createdAt = threadPost.record?.createdAt || threadPost.indexedAt || new Date().toISOString();
  171. let datetime = out.match(/{date-time(-local)?:[^{}]+}/) ? out.match(/{date-time(?:-local)?:([^{}]+)}/)[1].replace(/[\\/|<>*?:"]/g, v => invalid_chars[v]) : 'YYYYMMDD-hhmmss';
  172. let info = {};
  173. info.rkey = post_info.rkey;
  174. info['user-name'] = threadPost.author.displayName.replace(/([\\/|*?:"]|[\u200b-\u200d\u2060\ufeff]|🔞)/g, v => invalid_chars[v]);
  175. info['user-id'] = threadPost.author.handle.replace(/[^a-z0-9_\-]/gi, '_');
  176. info['date-time'] = this.formatDate(createdAt, datetime);
  177. info['date-time-local'] = this.formatDate(createdAt, datetime, true);
  178. const embed = threadPost.embed;
  179. let medias = [];
  180. if (embed) {
  181. if (embed.$type === 'app.bsky.embed.video#view') medias.push(embed.playlist); // video
  182. else if (embed.$type === 'app.bsky.embed.images#view') { // image
  183. for (let i = 0; i < embed.images.length; i++) {
  184. let image = embed.images[i];
  185. medias.push(image.fullsize);
  186. }
  187. }
  188. }
  189. if (medias.length > 0) {
  190. let tasks = medias.length;
  191. let tasks_result = [];
  192. medias.forEach((media, i) => {
  193. info.url = media;
  194. info.file = info.url.split('/').pop();
  195. info['file-name'] = info.file.split(/[.@]/).shift();
  196. info['file-ext'] = info.file.split(/[.@]/).pop();
  197. if (info['file-ext'] === 'jpeg') info['file-ext'] = 'jpg';
  198. else if (info['file-ext'] === 'm3u8') info['file-ext'] = 'mp4';
  199. info['file-type'] = info['file-ext'] === 'mp4' ? 'video' : 'photo';
  200. info.out = (out + (medias.length > 1 && !out.match('{file-name}') ? '-' + i : '') + '.{file-ext}').replace(/{([^{}:]+)(:[^{}]+)?}/g, (match, name) => info[name]);
  201. this.downloader.add({
  202. url: info.url,
  203. name: info.out,
  204. type: info['file-type'],
  205. onload: () => {
  206. tasks -= 1;
  207. tasks_result.push((medias.length > 1 ? ': ' : '') + lang.completed);
  208. this.status(btn, null, tasks_result.sort().join('\n'));
  209. if (tasks === 0) {
  210. this.status(btn, 'completed', lang.completed);
  211. if (save_history && !is_exist) {
  212. history.push(post_info.h_r);
  213. this.storage(post_info);
  214. }
  215. }
  216. },
  217. onerror: result => {
  218. tasks = -1;
  219. tasks_result.push((medias.length > 1 ? i + 1 + ': ' : '') + result.details.current);
  220. this.status(btn, 'failed', tasks_result.sort().join('\n'));
  221. }
  222. });
  223. });
  224. } else {
  225. this.status(btn, 'failed', 'MEDIA_NOT_FOUND');
  226. }
  227. },
  228. status: function (btn, css, title, style) {
  229. if (css) {
  230. btn.classList.remove('download', 'completed', 'loading', 'failed');
  231. btn.classList.add(css);
  232. }
  233. if (title) btn.title = title;
  234. if (style) btn.style.cssText = style;
  235. },
  236. settings: async function () {
  237. const $element = (parent, tag, style, content, css) => {
  238. let el = document.createElement(tag);
  239. if (style) el.style.cssText = style;
  240. if (typeof content !== 'undefined') {
  241. if (tag == 'input') {
  242. if (content == 'checkbox') el.type = content;
  243. else el.value = content;
  244. } else el.innerHTML = content;
  245. }
  246. if (css) css.split(' ').forEach(c => el.classList.add(c));
  247. parent.appendChild(el);
  248. return el;
  249. };
  250. let wapper = $element(document.body, 'div', 'position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; background-color: #0009; z-index: 10;');
  251. let wapper_close;
  252. wapper.onmousedown = e => {
  253. wapper_close = e.target == wapper;
  254. };
  255. wapper.onmouseup = e => {
  256. if (wapper_close && e.target == wapper) wapper.remove();
  257. };
  258. 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;');
  259. let title = $element(dialog, 'h3', 'margin: 10px 20px;', lang.dialog.title);
  260. let options = $element(dialog, 'div', 'margin: 10px; border: 1px solid #ccc; border-radius: 5px;');
  261. let save_history_label = $element(options, 'label', 'display: block; margin: 10px;', lang.dialog.save_history);
  262. let save_history_input = $element(save_history_label, 'input', 'float: left;', 'checkbox');
  263. save_history_input.checked = await GM_getValue('save_history', true);
  264. save_history_input.onchange = () => {
  265. GM_setValue('save_history', save_history_input.checked);
  266. }
  267. let clear_history = $element(save_history_label, 'label', 'display: inline-block; margin: 0 10px; color: blue;', lang.dialog.clear_history);
  268. clear_history.onclick = () => {
  269. if (confirm(lang.dialog.clear_confirm)) {
  270. history = [];
  271. GM_setValue('download_history', []);
  272. }
  273. };
  274. let show_sensitive_label = $element(options, 'label', 'display: block; margin: 10px;', lang.dialog.show_sensitive);
  275. let show_sensitive_input = $element(show_sensitive_label, 'input', 'float: left;', 'checkbox');
  276. show_sensitive_input.checked = await GM_getValue('show_sensitive', false);
  277. show_sensitive_input.onchange = () => {
  278. show_sensitive = show_sensitive_input.checked;
  279. GM_setValue('show_sensitive', show_sensitive);
  280. };
  281. let filename_div = $element(dialog, 'div', 'margin: 10px; border: 1px solid #ccc; border-radius: 5px;');
  282. let filename_label = $element(filename_div, 'label', 'display: block; margin: 10px 15px;', lang.dialog.pattern);
  283. 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));
  284. let filename_tags = $element(filename_div, 'label', 'display: table; margin: 10px;', `
  285. <span class="tmd-tag" title="user name">{user-name}</span>
  286. <span class="tmd-tag" title="The user name after @ sign.">{user-id}</span>
  287. <span class="tmd-tag" title="example: 1234567890987654321">{rkey}</span>
  288. <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>
  289. <span class="tmd-tag" title="Type of &#34;video&#34; or &#34;photo&#34; or &#34;gif&#34;.">{file-type}</span>
  290. <span class="tmd-tag" title="Original filename from URL.">{file-name}</span>
  291. `);
  292. filename_input.selectionStart = filename_input.value.length;
  293. filename_tags.querySelectorAll('.tmd-tag').forEach(tag => {
  294. tag.onclick = () => {
  295. let ss = filename_input.selectionStart;
  296. let se = filename_input.selectionEnd;
  297. filename_input.value = filename_input.value.substring(0, ss) + tag.innerText + filename_input.value.substring(se);
  298. filename_input.selectionStart = ss + tag.innerText.length;
  299. filename_input.selectionEnd = ss + tag.innerText.length;
  300. filename_input.focus();
  301. };
  302. });
  303. let btn_save = $element(title, 'label', 'float: right;', lang.dialog.save, 'tmd-btn');
  304. btn_save.onclick = async () => {
  305. await GM_setValue('filename', filename_input.value);
  306. wapper.remove();
  307. };
  308. },
  309. fetchJson: async function (post_info) {
  310. const postUri = `at://did:plc:${post_info.did}/app.bsky.feed.post/${post_info.rkey}`;
  311. const encodedUri = encodeURIComponent(postUri);
  312. const response = await fetch(`https://public.api.bsky.app/xrpc/app.bsky.feed.getPostThread?uri=${encodedUri}&depth=0`);
  313.  
  314. if (!response.ok) {
  315. throw new Error(`HTTP error! status: ${response.status}`);
  316. }
  317.  
  318. return await response.json();
  319. },
  320. storage: async function (value) {
  321. let data = await GM_getValue('download_history', []);
  322. let data_length = data.length;
  323. if (value) {
  324. if (Array.isArray(value)) data = data.concat(value);
  325. else if (data.indexOf(value) < 0) data.push(value);
  326. } else return data;
  327. if (data.length > data_length) GM_setValue('download_history', data);
  328. },
  329. storage_obsolete: function (is_remove) {
  330. let data = JSON.parse(localStorage.getItem('history') || '[]');
  331. if (is_remove) localStorage.removeItem('history');
  332. else return data;
  333. },
  334. formatDate: function (i, o, tz) {
  335. let d = new Date(i);
  336. if (tz) d.setMinutes(d.getMinutes() - d.getTimezoneOffset());
  337. let m = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
  338. let v = {
  339. YYYY: d.getUTCFullYear().toString(),
  340. YY: d.getUTCFullYear().toString(),
  341. MM: d.getUTCMonth() + 1,
  342. MMM: m[d.getUTCMonth()],
  343. DD: d.getUTCDate(),
  344. hh: d.getUTCHours(),
  345. mm: d.getUTCMinutes(),
  346. ss: d.getUTCSeconds(),
  347. h2: d.getUTCHours() % 12,
  348. ap: d.getUTCHours() < 12 ? 'AM' : 'PM'
  349. };
  350. return o.replace(/(YY(YY)?|MMM?|DD|hh|mm|ss|h2|ap)/g, n => ('0' + v[n]).substr(-n.length));
  351. },
  352. downloader: (function () {
  353. let tasks = [],
  354. thread = 0,
  355. max_thread = 2,
  356. retry = 0,
  357. max_retry = 2,
  358. failed = 0,
  359. notifier, has_failed = false;
  360. return {
  361. add: function (task) {
  362. tasks.push(task);
  363. if (thread < max_thread) {
  364. thread += 1;
  365. this.next();
  366. } else this.update();
  367. },
  368. next: async function () {
  369. let task = tasks.shift();
  370. await this.start(task);
  371. if (tasks.length > 0 && thread <= max_thread) this.next();
  372. else thread -= 1;
  373. this.update();
  374. },
  375. start: async function (task) {
  376. this.update();
  377. let mediaurl = task.url;
  378. if (task.type === 'video') {
  379. const masterPlaylistResponse = await fetch(task.url);
  380. const masterPlaylist = await masterPlaylistResponse.text();
  381. const videoPlaylistUrl = this.parseHighestQualityVideoUrl(masterPlaylist, task.url);
  382. const videoPlaylistResponse = await fetch(videoPlaylistUrl);
  383. const videoPlaylist = await videoPlaylistResponse.text();
  384. const segmentUrls = this.parseSegmentUrls(videoPlaylist, videoPlaylistUrl);
  385. const chunks = await this.downloadSegments(segmentUrls);
  386. const videoBlob = new Blob(chunks, {
  387. type: 'video/mp4'
  388. });
  389. mediaurl = URL.createObjectURL(videoBlob);
  390. }
  391. return new Promise(resolve => {
  392. GM_download({
  393. url: mediaurl,
  394. name: task.name,
  395. onload: result => {
  396. task.onload();
  397. resolve();
  398. },
  399. onerror: result => {
  400. this.retry(task, result);
  401. resolve();
  402. },
  403. ontimeout: result => {
  404. this.retry(task, result);
  405. resolve();
  406. }
  407. });
  408. });
  409. },
  410. retry: function (task, result) {
  411. retry += 1;
  412. if (retry == 3) max_thread = 1;
  413. if (task.retry && task.retry >= max_retry ||
  414. result.details && result.details.current == 'USER_CANCELED') {
  415. task.onerror(result);
  416. failed += 1;
  417. } else {
  418. if (max_thread == 1) task.retry = (task.retry || 0) + 1;
  419. this.add(task);
  420. }
  421. },
  422. update: function () {
  423. if (!notifier) {
  424. notifier = document.createElement('div');
  425. notifier.title = 'bsky Media Downloader';
  426. notifier.classList.add('tmd-notifier');
  427. notifier.innerHTML = '<label>0</label>|<label>0</label>';
  428. document.body.appendChild(notifier);
  429. }
  430. if (failed > 0 && !has_failed) {
  431. has_failed = true;
  432. notifier.innerHTML += '|';
  433. let clear = document.createElement('label');
  434. notifier.appendChild(clear);
  435. clear.onclick = () => {
  436. notifier.innerHTML = '<label>0</label>|<label>0</label>';
  437. failed = 0;
  438. has_failed = false;
  439. this.update();
  440. };
  441. }
  442. notifier.firstChild.innerText = thread;
  443. notifier.firstChild.nextElementSibling.innerText = tasks.length;
  444. if (failed > 0) notifier.lastChild.innerText = failed;
  445. if (thread > 0 || tasks.length > 0 || failed > 0) notifier.classList.add('running');
  446. else notifier.classList.remove('running');
  447. },
  448. parseHighestQualityVideoUrl: function (masterPlaylist, baseUrl) {
  449. const lines = masterPlaylist.split('\n');
  450. let highestBandwidth = 0;
  451. let highestQualityUrl = '';
  452. for (let i = 0; i < lines.length; i++) {
  453. if (lines[i].startsWith('#EXT-X-STREAM-INF')) {
  454. const bandwidthMatch = lines[i].match(/BANDWIDTH=(\d+)/);
  455. if (bandwidthMatch) {
  456. const bandwidth = parseInt(bandwidthMatch[1]);
  457. if (bandwidth > highestBandwidth) {
  458. highestBandwidth = bandwidth;
  459. highestQualityUrl = lines[i + 1];
  460. }
  461. }
  462. }
  463. }
  464. return new URL(highestQualityUrl, baseUrl).toString();
  465. },
  466. parseSegmentUrls: function (videoPlaylist, baseUrl) {
  467. return videoPlaylist.split('\n')
  468. .filter(line => !line.startsWith('#') && line.trim() !== '')
  469. .map(segment => new URL(segment, baseUrl).toString());
  470. },
  471. downloadSegments: async function (segmentUrls, progressCallback = null) {
  472. const chunks = [];
  473. const totalSegments = segmentUrls.length;
  474. for (let i = 0; i < totalSegments; i++) {
  475. const url = segmentUrls[i];
  476. const response = await fetch(url);
  477. const chunk = await response.arrayBuffer();
  478. chunks.push(chunk);
  479.  
  480. if (progressCallback) progressCallback((i + 1) / totalSegments);
  481. }
  482. return chunks;
  483. }
  484. };
  485. })(),
  486. language: {
  487. en: {
  488. download: 'Download',
  489. completed: 'Download Completed',
  490. settings: 'Settings',
  491. dialog: {
  492. title: 'Download Settings',
  493. save: 'Save',
  494. save_history: 'Remember download history',
  495. clear_history: '(Clear)',
  496. clear_confirm: 'Clear download history?',
  497. show_sensitive: 'Always show sensitive content',
  498. pattern: 'File Name Pattern'
  499. }
  500. },
  501. ja: {
  502. download: 'ダウンロード',
  503. completed: 'ダウンロード完了',
  504. settings: '設定',
  505. dialog: {
  506. title: 'ダウンロード設定',
  507. save: '保存',
  508. save_history: 'ダウンロード履歴を保存する',
  509. clear_history: '(クリア)',
  510. clear_confirm: 'ダウンロード履歴を削除する?',
  511. show_sensitive: 'センシティブな内容を常に表示する',
  512. pattern: 'ファイル名パターン'
  513. }
  514. },
  515. zh: {
  516. download: '下载',
  517. completed: '下载完成',
  518. settings: '设置',
  519. dialog: {
  520. title: '下载设置',
  521. save: '保存',
  522. save_history: '保存下载记录',
  523. clear_history: '(清除)',
  524. clear_confirm: '确认要清除下载记录?',
  525. show_sensitive: '自动显示敏感的内容',
  526. pattern: '文件名格式'
  527. }
  528. },
  529. 'zh-Hant': {
  530. download: '下載',
  531. completed: '下載完成',
  532. settings: '設置',
  533. dialog: {
  534. title: '下載設置',
  535. save: '保存',
  536. save_history: '保存下載記錄',
  537. clear_history: '(清除)',
  538. clear_confirm: '確認要清除下載記錄?',
  539. show_sensitive: '自動顯示敏感的内容',
  540. pattern: '文件名規則'
  541. }
  542. }
  543. },
  544. css: `
  545. .tmd-down {margin-left: 12px; order: 99;}
  546. .tmd-down:hover > div > div > div > div {color: rgba(29, 161, 242, 1.0);}
  547. .tmd-down:hover > div > div > div > div > div {background-color: rgba(29, 161, 242, 0.1);}
  548. .tmd-down:active > div > div > div > div > div {background-color: rgba(29, 161, 242, 0.2);}
  549. .tmd-down:hover svg {color: rgba(29, 161, 242, 1.0);}
  550. .tmd-down:hover div:first-child:not(:last-child) {background-color: rgba(29, 161, 242, 0.1);}
  551. .tmd-down:active div:first-child:not(:last-child) {background-color: rgba(29, 161, 242, 0.2);}
  552. .tmd-down.tmd-media {position: absolute; right: 0;}
  553. .tmd-down.tmd-media > div {display: flex; border-radius: 99px; margin: 2px;}
  554. .tmd-down.tmd-media > div > div {display: flex; margin: 6px; color: #fff;}
  555. .tmd-down.tmd-media:hover > div {background-color: rgba(255,255,255, 0.6);}
  556. .tmd-down.tmd-media:hover > div > div {color: rgba(29, 161, 242, 1.0);}
  557. .tmd-down.tmd-media:not(:hover) > div > div {filter: drop-shadow(0 0 1px #000);}
  558. .tmd-down g {display: none;}
  559. .tmd-down.download g.download, .tmd-down.completed g.completed, .tmd-down.loading g.loading,.tmd-down.failed g.failed {display: unset;}
  560. .tmd-down.loading svg {animation: spin 1s linear infinite;}
  561. @keyframes spin {0% {transform: rotate(0deg);} 100% {transform: rotate(360deg);}}
  562. .tmd-btn {display: inline-block; background-color: #1DA1F2; color: #FFFFFF; padding: 0 20px; border-radius: 99px;}
  563. .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;}
  564. .tmd-btn:hover {background-color: rgba(29, 161, 242, 0.9);}
  565. .tmd-tag:hover {background-color: rgba(29, 161, 242, 0.1);}
  566. .tmd-notifier {display: none; position: fixed; left: 16px; bottom: 16px; color: #000; background: #fff; border: 1px solid #ccc; border-radius: 8px; padding: 4px;}
  567. .tmd-notifier.running {display: flex; align-items: center;}
  568. .tmd-notifier label {display: inline-flex; align-items: center; margin: 0 8px;}
  569. .tmd-notifier label:before {content: " "; width: 32px; height: 16px; background-position: center; background-repeat: no-repeat;}
  570. .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>");}
  571. .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>");}
  572. .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>");}
  573. .tmd-down.tmd-img {position: absolute; right: 0; bottom: 0; display: none !important;}
  574. .tmd-down.tmd-img > div {display: flex; border-radius: 99px; margin: 2px; background-color: rgba(255,255,255, 0.6);}
  575. .tmd-down.tmd-img > div > div {display: flex; margin: 6px; color: #fff !important;}
  576. .tmd-down.tmd-img:not(:hover) > div > div {filter: drop-shadow(0 0 1px #000);}
  577. .tmd-down.tmd-img:hover > div > div {color: rgba(29, 161, 242, 1.0);}
  578. :hover > .tmd-down.tmd-img, .tmd-img.loading, .tmd-img.completed, .tmd-img.failed {display: block !important;}
  579. `,
  580. css_ss: `
  581. /* show sensitive in media tab */
  582. li[role="listitem"]>div>div>div>div:not(:last-child) {filter: none;}
  583. li[role="listitem"]>div>div>div>div+div:last-child {display: none;}
  584. `,
  585. svg: `
  586. <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="#788EA5" stroke-width="2" stroke-linecap="round" /></g>
  587. <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>
  588. <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>
  589. <g class="failed"><circle cx="12" cy="12" r="11" fill="#f33" stroke="#788EA5" 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>
  590. `
  591. };
  592. })();
  593.  
  594. TMD.init();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址