Telegram 受限图片视频下载器 (批量支持)

批量下载禁止保存的Telegram频道内容

  1. // ==UserScript==
  2. // @name Telegram Media Downloader (Batch Support)
  3. // @name:en Telegram Media Downloader (Batch Support)
  4. // @name:zh-CN Telegram 受限图片视频下载器 (批量支持)
  5. // @name:zh-TW Telegram 受限圖片影片下載器 (批次支援)
  6. // @name:ru Telegram: загрузчик медиафайлов (пакетная загрузка)
  7. // @version 1.207
  8. // @namespace https://github.com/Neet-Nestor/Telegram-Media-Downloader
  9. // @description Enhanced version with batch download support for restricted Telegram content
  10. // @description:en Download multiple images/videos at once from restricted Telegram channels
  11. // @description:ru Пакетная загрузка медиафайлов из закрытых Telegram-каналов
  12. // @description:zh-CN 批量下载禁止保存的Telegram频道内容
  13. // @description:zh-TW 批次下載禁止儲存的 Telegram 頻道內容
  14. // @author Nestor Qin + Modifications
  15. // @license GNU GPLv3
  16. // @website https://github.com/Neet-Nestor/Telegram-Media-Downloader
  17. // @match https://web.telegram.org/*
  18. // @match https://webk.telegram.org/*
  19. // @match https://webz.telegram.org/*
  20. // @icon https://img.icons8.com/color/452/telegram-app--v5.png
  21. // @grant GM_download
  22. // @grant GM_xmlhttpRequest
  23. // ==/UserScript==
  24.  
  25. (function() {
  26. 'use strict';
  27. // Existing logger and constants remain unchanged
  28. const logger = { /* ... original logger code ... */ };
  29. const contentRangeRegex = /^bytes (\d+)-(\d+)\/(\d+)$/;
  30. const REFRESH_DELAY = 500;
  31. const hashCode = s => { /* ... original hash code ... */ };
  32.  
  33. // Batch Download System
  34. const batchManager = {
  35. queue: new Map(),
  36. isProcessing: false,
  37. addToQueue: function(url, type, element) {
  38. this.queue.set(url, { type, element });
  39. element.classList.add('tel-batch-selected');
  40. },
  41. removeFromQueue: function(url) {
  42. this.queue.delete(url);
  43. },
  44. processQueue: async function() {
  45. this.isProcessing = true;
  46. const batchSize = this.queue.size;
  47. for (const [url, {type, element}] of this.queue) {
  48. try {
  49. await new Promise((resolve, reject) => {
  50. setTimeout(() => {
  51. try {
  52. switch(type) {
  53. case 'video': tel_download_video(url); break;
  54. case 'audio': tel_download_audio(url); break;
  55. case 'image': tel_download_image(url); break;
  56. }
  57. resolve();
  58. } catch(e) {
  59. reject(e);
  60. }
  61. }, 1000);
  62. });
  63. element.classList.remove('tel-batch-selected');
  64. } catch(e) {
  65. logger.error(`Batch failed for ${url}: ${e.message}`);
  66. }
  67. }
  68. this.queue.clear();
  69. this.isProcessing = false;
  70. }
  71. };
  72.  
  73. // Batch UI Elements
  74. const createBatchUI = () => {
  75. const existingButton = document.getElementById('tel-batch-download');
  76. if (!existingButton) {
  77. const batchButton = document.createElement('button');
  78. batchButton.id = 'tel-batch-download';
  79. batchButton.textContent = `Batch Download (${batchManager.queue.size})`;
  80. Object.assign(batchButton.style, {
  81. position: 'fixed',
  82. bottom: '20px',
  83. right: '20px',
  84. zIndex: '99999',
  85. padding: '10px 20px',
  86. backgroundColor: '#0088cc',
  87. color: 'white',
  88. border: 'none',
  89. borderRadius: '5px',
  90. cursor: 'pointer'
  91. });
  92. batchButton.addEventListener('click', () => {
  93. if (!batchManager.isProcessing && batchManager.queue.size > 0) {
  94. batchButton.textContent = 'Processing...';
  95. batchManager.processQueue().finally(() => {
  96. batchButton.textContent = 'Batch Download (0)';
  97. });
  98. }
  99. });
  100. document.body.appendChild(batchButton);
  101. }
  102. };
  103.  
  104. // Modified media injection with checkboxes
  105. const injectMediaElements = (mediaElements, mediaType) => {
  106. mediaElements.forEach(element => {
  107. if (element.querySelector('.tel-batch-checkbox')) return;
  108. const url = element.querySelector('video,img,audio')?.src;
  109. if (!url) return;
  110.  
  111. const checkbox = document.createElement('input');
  112. checkbox.type = 'checkbox';
  113. checkbox.className = 'tel-batch-checkbox';
  114. Object.assign(checkbox.style, {
  115. position: 'absolute',
  116. top: '5px',
  117. left: '5px',
  118. zIndex: '1000',
  119. width: '18px',
  120. height: '18px'
  121. });
  122.  
  123. checkbox.addEventListener('change', (e) => {
  124. if (e.target.checked) {
  125. batchManager.addToQueue(url, mediaType, element);
  126. } else {
  127. batchManager.removeFromQueue(url);
  128. }
  129. document.getElementById('tel-batch-download').textContent =
  130. `Batch Download (${batchManager.queue.size})`;
  131. });
  132.  
  133. element.style.position = 'relative';
  134. element.appendChild(checkbox);
  135. });
  136. };
  137.  
  138. // Modified interval handlers
  139. const createMediaHandlers = () => {
  140. // Original media detection code modified to include batch checkboxes
  141. setInterval(() => {
  142. // Video elements
  143. const videoElements = document.querySelectorAll('.VideoPlayer, video');
  144. injectMediaElements(videoElements, 'video');
  145.  
  146. // Image elements
  147. const imageElements = document.querySelectorAll('img.PVZ8TOWS, img.media-photo');
  148. injectMediaElements(imageElements, 'image');
  149.  
  150. // Audio elements
  151. const audioElements = document.querySelectorAll('audio-element, audio');
  152. injectMediaElements(audioElements, 'audio');
  153.  
  154. createBatchUI();
  155. }, REFRESH_DELAY);
  156. };
  157.  
  158. // Existing progress bar setup remains unchanged
  159. const setupProgressBar = () => { /* ... original progress bar code ... */ };
  160.  
  161. // Original download functions remain unchanged
  162. const tel_download_video = url => { /* ... original video download ... */ };
  163. const tel_download_audio = url => { /* ... original audio download ... */ };
  164. const tel_download_image = url => { /* ... original image download ... */ };
  165.  
  166. // Initialization
  167. (function init() {
  168. setupProgressBar();
  169. createMediaHandlers();
  170. logger.info('Batch download system initialized');
  171. })();
  172.  
  173. })();

QingJ © 2025

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