ImageDownloaderLib

Image downloader for manga download scripts.

目前为 2022-09-22 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/451810/1096733/ImageDownloaderLib.js

  1. function ImageDownloader({
  2. getImagePromises,
  3. isOKToDownload = () => true,
  4. title = `package_${Date.now()}`,
  5. zipOptions = {},
  6. imageSuffix = 'jpg',
  7. cssVerticalDistance = 'top: 80px',
  8. cssHorizontalDistance = 'left: 80px'
  9. }) {
  10. // create download button element
  11. const dlBtn = document.createElement('button');
  12. dlBtn.textContent = 'Download';
  13. dlBtn.style = `
  14. position: fixed;
  15. ${cssVerticalDistance};
  16. ${cssHorizontalDistance};
  17. z-index: 9999999;
  18.  
  19. width: 128px;
  20. height: 48px;
  21.  
  22. display: flex;
  23. justify-content: center;
  24. align-items: center;
  25.  
  26. font-size: 14px;
  27. font-family: 'Consolas', 'Monaco', 'Microsoft YaHei';
  28. color: #fff;
  29.  
  30. background-color: #0984e3;
  31. border: none;
  32. border-radius: 4px;
  33. cursor: pointer;
  34. `;
  35.  
  36. // setup click event callback
  37. dlBtn.onclick = function () {
  38. if (!isOKToDownload()) return;
  39.  
  40. dlBtn.disabled = true;
  41. dlBtn.textContent = "Processing";
  42. dlBtn.style.backgroundColor = '#aaa';
  43. dlBtn.style.cursor = 'not-allowed';
  44. download(getImagePromises, title, zipOptions);
  45. }
  46.  
  47. // add button to body
  48. document.body.appendChild(dlBtn);
  49.  
  50. // download
  51. async function download(getImagePromises, title, zipOptions) {
  52. const images = await Promise.all(getImagePromises());
  53.  
  54. // create zip
  55. const zip = new JSZip(); // JSZip library should be imported already
  56. const folder = zip.folder(title);
  57. images.forEach((image, index) => {
  58. const filename = `${index + 1}`.padStart(images.length >= 100 ? 3 : 2, '0') + `.${imageSuffix}`;
  59. folder.file(filename, image, zipOptions);
  60. });
  61.  
  62. // pop up download window
  63. const content = await zip.generateAsync({ type: "blob" });
  64. saveAs(content, `${title}.zip`); // FileSaver library should be imported already
  65.  
  66. // change the text of download button
  67. dlBtn.innerText = "Completed";
  68. }
  69. }

QingJ © 2025

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