zipped

Use web worker to compress images

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/20372/130355/zipped.js

  1. // https://github.com/baivong/Userscript
  2.  
  3. (function () {
  4. 'use strict';
  5.  
  6. function generateZip(index, name) {
  7.  
  8. var zip = new JSZip();
  9.  
  10. box[('item' + index)].forEach(function (imgBlob) {
  11. zip.file(imgBlob.name, imgBlob.content);
  12. });
  13.  
  14. zip.generateAsync({
  15. type: 'blob'
  16. }).then(function (blob) {
  17. self.postMessage({
  18. index: index,
  19. name: name,
  20. content: blob
  21. });
  22. }, function (reason) {
  23. self.postMessage(reason);
  24. });
  25.  
  26. }
  27.  
  28. var box = {};
  29.  
  30. self.addEventListener('message', function (e) {
  31.  
  32. var i = 'item' + e.data.index;
  33. if (!box[i]) box[i] = [];
  34.  
  35. if (e.data.run) {
  36. generateZip(e.data.index, e.data.name);
  37. } else {
  38. box[i].push({
  39. name: e.data.name,
  40. content: e.data.content
  41. });
  42. }
  43.  
  44. }, false);
  45.  
  46. })();

QingJ © 2025

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