图片下载器

可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,不能右键保存图片或者保存的图片文件格式无法识别,均可以用脚本提取,然后用脚本提供的下载按钮,就可以下载到正确格式的图片文件。点击右键-tampermonkey-图片下载器-打开脚本(或快捷键alt+w),按这个顺序使用。(目前只适合chrome+tampermonkey,其他组合多少有问题)

目前为 2021-12-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Image Downloader
  3. // @name:zh-CN 图片下载器
  4. // @name:zh-TW 图片下载器
  5. // @namespace http://tampermonkey.net/
  6. // @description You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  7. // @description:zh-CN 可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,不能右键保存图片或者保存的图片文件格式无法识别,均可以用脚本提取,然后用脚本提供的下载按钮,就可以下载到正确格式的图片文件。点击右键-tampermonkey-图片下载器-打开脚本(或快捷键alt+w),按这个顺序使用。(目前只适合chrome+tampermonkey,其他组合多少有问题)
  8. // @description:zh-TW 可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,不能右键保存图片或者保存的图片文件格式无法识别,均可以用脚本提取,然后用脚本提供的下载按钮,就可以下载到正确格式的图片文件。点击右键-tampermonkey-图片下载器-打开脚本(或快捷键alt+w),按这个顺序使用。(目前只适合chrome+tampermonkey,其他组合多少有问题)
  9. // @version 1.68
  10. // @author 桃源隐叟
  11. // @include *
  12. // @connect *
  13. // @grant GM_openInTab
  14. // @grant GM_registerMenuCommand
  15. // @grant GM_setValue
  16. // @grant GM_getValue
  17. // @grant GM_xmlhttpRequest
  18. // @grant GM_download
  19. // @require https://cdn.jsdelivr.net/npm/hotkeys-js@3.7.2/dist/hotkeys.min.js
  20. // @require https://cdn.bootcss.com/jszip/3.7.1/jszip.min.js
  21. // @require https://cdn.bootcss.com/FileSaver.js/1.3.8/FileSaver.min.js
  22. // @run-at document-end
  23. // @match *
  24. // @match https://www.bilibili.com/
  25. // @match https://588ku.com/
  26. // @homepageURL https://github.com/taoyuancun123/modifyText/blob/master/modifyText.js
  27. // @supportURL https://greasyfork.org/zh-CN/scripts/419894/feedback
  28. // @license GPLv3
  29. // ==/UserScript==
  30. (function () {
  31. 'use strict';
  32. var lang = navigator.appName == "Netscape" ? navigator.language : navigator.userLanguage;
  33. var langSet;
  34. var localization = {
  35. zh: {
  36. selectAll: "全选",
  37. downloadBtn: "下载",
  38. downloadMenuText: "打开脚本(Alt+w)",
  39. zipDownloadBtn: "zip下载"
  40. },
  41. en: {
  42. selectAll: "selectAll",
  43. downloadBtn: "download",
  44. downloadMenuText: "Open(Alt+w)",
  45. zipDownloadBtn: "zip Download"
  46. }
  47. }
  48. if (lang.toLowerCase().includes("zh-")) {
  49. langSet = localization.zh;
  50. } else {
  51. langSet = localization.en;
  52. }
  53. GM_registerMenuCommand(langSet.downloadMenuText, wrapper);
  54. hotkeys('alt+w', wrapper);
  55. function wrapper() {
  56. try {
  57. document.querySelector(".tyc-image-container").remove();
  58. } catch {
  59. }
  60. var imgUrls = [];
  61. var bodyStr = document.body.innerHTML;
  62. var imgSelected = [];
  63. var zipImgSelected = [];
  64. var imgWaitDownload = [];
  65. var zipImgWaitDownload = [];
  66. var widthFilter = { min: 0, max: 3000 };
  67. var heightFilter = { min: 0, max: 3000 };
  68. var filteredImgUrls = [];
  69. var zipFilteredImgUrls = [];
  70. var zipFolder = new JSZip();
  71. var zipSubFoler = zipFolder.folder('pics');
  72. try {
  73. let imgEles = document.getElementsByTagName("img");
  74. let canvasEles=document.getElementsByTagName("canvas");
  75. for (let i = 0; i < imgEles.length; i++) {
  76. ////console.log(imgEles[i].src);
  77. if (!imgUrls.includes(imgEles[i].src)) {
  78. imgUrls.push(imgEles[i].src);
  79. } else if (!imgUrls.includes(imgEles[i].srcset)) {
  80. imgUrls.push(imgEles[i].srcset);
  81. }
  82. }
  83. if(window.location.href.toString().includes("manga.bilibili.com/")){
  84. let iframeCanvas=`<iframe style="display:none;" id="tyc-insert-iframe"></iframe>`;
  85. if(document.getElementById("tyc-insert-iframe")==null){
  86. document.body.insertAdjacentHTML("afterbegin",iframeCanvas);
  87. document.getElementById("tyc-insert-iframe").contentDocument.body.insertAdjacentHTML("afterbegin",`<canvas id="tyc-insert-canvas"></canvas>`);
  88. document.body.getElementsByTagName('canvas')[0].__proto__.toDataURL=document.getElementById("tyc-insert-iframe").contentDocument.getElementById("tyc-insert-canvas").__proto__.toDataURL;
  89. }
  90. }
  91. for(let j=0;j<canvasEles.length;j++){
  92. let canvasImg=canvasEles[j].toDataURL();
  93. if (!imgUrls.includes(canvasImg)) {
  94. imgUrls.push(canvasImg);
  95. }
  96. }
  97. } catch {
  98. //alert("error");
  99. }
  100. try {
  101. let imgRegs = bodyStr.match(/(?<=background-image:\s*url\()(\S+)(?=\))/g);
  102. for (let i = 0; i < imgRegs.length; i++) {
  103. ////console.log(imgRegs[i]);
  104. if (!imgUrls.includes(imgRegs[i].replace(/&quot;/g, ""))) {
  105. imgUrls.push(imgRegs[i].replace(/&quot;/g, ""));
  106. }
  107. }
  108. } catch {
  109. //alert("error");
  110. }
  111. let imgContainer = `
  112. <div class="tyc-image-container" style="position:fixed;
  113. top:0px;right:0px;width:50vw;z-index:2147483645;
  114. background-color: #dedede;
  115. border: 1px solid #aaa;
  116. overflow:scroll;height:100%;
  117. ">
  118. <div class="control-section" style="width:46vw;z-index:2147483646;
  119. position:fixed;right:30px;
  120. top:0px;display:block;
  121. height:80px;line-height:40px;
  122. background:#eee;border:1px solid #aaa;border-radius:2px;">
  123. <input class="select-all" type="checkbox" name="select-all" value="select-all">${langSet.selectAll}
  124. <button class="btn-download" style="border:1px solid #aaa;border-radius:5px;
  125. height:32px;line-height:32px;
  126. margin:0px;padding:0 5px;
  127. ">${langSet.downloadBtn}</button>
  128. <button class="btn-zipDownload" style="border:1px solid #aaa;border-radius:5px;
  129. height:32px;line-height:32px;
  130. margin:0px;padding:0 5px;
  131. ">${langSet.zipDownloadBtn}</button>
  132. <span style="margin-left:10px;" class="num-tip">已选(0/${imgUrls.length})张图片</span>
  133. <button class="btn-close" style="font-size:20px;position:absolute;
  134. right:30px;top:4px;
  135. height:32px;line-height:32px;
  136. margin:0px;
  137. border-radius:10px;border:1px solid #aaa;
  138. width:30px;">X</button>
  139. <p style="line-height:12px;">
  140. <div style="float:left;">
  141. <input type="checkbox" class="width-check img-check" name="width-check" value="width-check">Width:
  142. <input type="text" class="width-value-min" size="1" style="height:15px;width:50px;"
  143. min="0" max="9999" value="0">-
  144. <input type="text" class="width-value-max" size="1" style="height:15px;width:50px;"
  145. min="0" max="9999" value="3000">
  146. </div>
  147. <div style="float:left;margin-left:30px;">
  148. <input type="checkbox" class="height-check img-check" name="height-check" value="height-check">Height:
  149. <input type="text" class="height-value-min" size="1" style="height:15px;width:50px;"
  150. min="0" max="9999" value="0">-
  151. <input type="text" class="height-value-max" size="1" style="height:15px;width:50px;"
  152. min="0" max="9999" value="3000">
  153. </div>
  154. </p>
  155. </div>
  156. <div class="tyc-image-wrapper" style="margin-top:82px;display:flex;justify-content:center;
  157. align-items:center;flex-wrap:wrap;">
  158. </div>
  159. </div>
  160. `
  161. let showBigImage = `
  162. <div class="show-big-image" style="position:fixed;left:30%;top:30%;z-index:2147483647;">
  163. </div>
  164. `
  165. document.body.insertAdjacentHTML("afterbegin", imgContainer);
  166. if (window.location.href.includes("hathitrust.org")) {
  167. //imgUrls=[];
  168. let imgs = document.querySelectorAll(".image img");
  169. if (imgs.length > 0) {
  170. let canvas = document.createElement("canvas");
  171. imgUrls = [];
  172. for (let pi = 0; pi < imgs.length; pi++) {
  173. canvas.width = imgs[pi].width;
  174. canvas.height = imgs[pi].height;
  175. canvas.getContext("2d").drawImage(imgs[pi], 0, 0);
  176. imgUrls.push(canvas.toDataURL("image/png"));
  177. }
  178. document.querySelector(".select-all").style = "position:relative;width:15px;height:15px;"
  179. } else {
  180. }
  181. }
  182. document.body.onclick = (e) => {
  183. //console.log(e);
  184. if ((e.target.nodeName == "IMG" && e.target.className === "tyc-image-preview")) {
  185. let imgContainer = e.path.find(
  186. (ele) => {
  187. try {
  188. //console.log(ele);
  189. return ele.className.includes("tyc-img-item-container");
  190. }
  191. catch {
  192. }
  193. }
  194. )
  195. let path = imgContainer.getElementsByTagName("img")[0].src;
  196. try {
  197. let container = document.querySelector(".show-big-image");
  198. if (container.getElementsByTagName("img")[0].src === path) {
  199. container.remove();
  200. return;
  201. } else {
  202. container.remove();
  203. }
  204. }
  205. catch {
  206. }
  207. document.body.insertAdjacentHTML("beforeend", showBigImage);
  208. let showItem = `<img src="${path}"/>`
  209. document.querySelector(".show-big-image").insertAdjacentHTML("beforeend", showItem);
  210. let tempImg = document.querySelector(".show-big-image img");
  211. let dWidth = (window.innerWidth - tempImg.width) / 2;
  212. let dHeight = (window.innerHeight - tempImg.height) / 2;
  213. document.querySelector(".show-big-image").style.left = dWidth + "px";
  214. document.querySelector(".show-big-image").style.top = dHeight + "px";
  215. } else if (e.target.parentElement.className === "show-big-image") {
  216. try {
  217. document.querySelector(".show-big-image").remove();
  218. }
  219. catch
  220. {
  221. }
  222. } else if (e.target.classList[1] == "bi-download" || e.path.find(isDownload) != undefined) {
  223. let imgContainer = e.path.find(
  224. (ele) => {
  225. try {
  226. //console.log(ele);
  227. return ele.className.includes("tyc-img-item-container");
  228. }
  229. catch {
  230. }
  231. }
  232. )
  233. let path = imgContainer.getElementsByTagName("img")[0].src;
  234. let filename;
  235. if (path.indexOf("/") > 0)//如果包含有"/"号 从最后一个"/"号+1的位置开始截取字符串
  236. {
  237. filename = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
  238. }
  239. else {
  240. filename = path;
  241. }
  242. //console.log("download start" + path + " " + filename);
  243. GM_download(path, "pic");
  244. } else if (e.target.classList[1] == "bi-check" || e.path.find(isSelect) != undefined) {
  245. let checkSvg = e.path.find((ele) => ele.classList[1] === "bi-check");
  246. let currentImgIndex = parseInt(checkSvg.dataset.value);
  247. let container = e.path.find((ele) => ele.className === `tyc-img-item-container-${currentImgIndex}`);
  248. if (imgSelected.includes(currentImgIndex)) {
  249. imgSelected.splice(imgSelected.indexOf(currentImgIndex), 1);
  250. checkSvg.style.color = "black";
  251. container.style.border = "1px solid #99d";
  252. } else {
  253. imgSelected.push(currentImgIndex);
  254. checkSvg.style.color = "white";
  255. container.style.border = "1px solid white";
  256. }
  257. zipImgSelected=imgSelected;
  258. document.querySelector(".num-tip").innerText = `已选(${imgSelected.length}/${imgUrls.length})张图片`;
  259. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  260. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  261. zipImgWaitDownload=cutoffNotBase64Img(zipImgWaitDownload);
  262. }
  263. }
  264. document.querySelector(".btn-close").onclick = (e) => {
  265. document.querySelector(".tyc-image-container").remove();
  266. }
  267. document.querySelector(".btn-download").onclick = (e) => {
  268. if (imgWaitDownload.length >= 1) {
  269. console.log(imgWaitDownload);
  270. imgWaitDownload.forEach(async (img, index) => {
  271. //let filename = `pic-${index}.jpg`;
  272. //filename=filename.replace(/\\/g, '/').replace(/\/{2,}/g, '/');
  273. await GM_download(img, `pic-${index}`);
  274. });
  275. } else {
  276. alert("请至少选中一张图片。");
  277. }
  278. }
  279. document.querySelector(".btn-zipDownload").onclick = (e) => {
  280. if (zipImgWaitDownload.length >= 1) {
  281. console.log(zipImgWaitDownload);
  282. zipImgWaitDownload.forEach(async (img, index) => {
  283. let fileExt = img.substring(img.indexOf("image/") + 6, img.indexOf(";"))
  284. fileExt=fileExt.includes("svg")?"svg":fileExt;
  285. let filename = `pic${index}.${fileExt}`;
  286. zipSubFoler.file(filename, img.split(",")[1], { base64: true });
  287. });
  288. zipFolder.generateAsync({ type: "blob" })
  289. .then(function (content) {
  290. // see FileSaver.js
  291. saveAs(content, "pics.zip");
  292. zipFolder.remove("pics");
  293. zipSubFoler = zipFolder.folder('pics');
  294. });
  295. } else {
  296. alert("请至少选中一张图片。");
  297. }
  298. }
  299. document.body.onchange = (e) => {
  300. if (e.target.className.includes("width-check")) {
  301. GM_setValue('width-check', e.target.checked);
  302. }
  303. if (e.target.className.includes("height-check")) {
  304. GM_setValue('height-check', e.target.checked);
  305. }
  306. if (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")) {
  307. GM_setValue(e.target.className, e.target.value);
  308. }
  309. (e.target.className.includes("width-check") || e.target.className.includes("height-check") ||
  310. (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")))
  311. && (clean(), init());
  312. }
  313. document.querySelector(".select-all").onchange = (e) => {
  314. if (document.querySelector(".select-all").checked) {
  315. imgWaitDownload = filteredImgUrls;
  316. zipImgWaitDownload=cutoffNotBase64Img(zipFilteredImgUrls);
  317. } else {
  318. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  319. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  320. }
  321. document.querySelector(".num-tip").innerText = `已选(${imgWaitDownload.length}/${filteredImgUrls.length})张图片`;
  322. }
  323. init();
  324. function init() {
  325. filteredImgUrls = imgUrls;
  326. getSavedValue();
  327. if (document.querySelector(".width-check").checked) {
  328. filteredImgUrls = filteredImgUrls.filter(filterByWidth);
  329. }
  330. if (document.querySelector(".height-check").checked) {
  331. filteredImgUrls = filteredImgUrls.filter(filterByHeight);
  332. }
  333. zipFilteredImgUrls = filteredImgUrls;
  334. fetchBase64ImgsThenPushToZipArray();
  335. showImage(filteredImgUrls);
  336. }
  337. function clean() {
  338. imgWaitDownload = [];
  339. imgSelected = [];
  340. document.querySelector(".num-tip").innerText = `已选(${imgSelected.length}/${imgUrls.length})张图片`;
  341. document.querySelector(".tyc-image-wrapper").innerHTML = "";
  342. }
  343. function isDownload(ele) {
  344. return ele.className == "download-direct";
  345. }
  346. function isSelect(ele) {
  347. return ele.className == "select-image";
  348. }
  349. function transIndexToLink(WholeImgs,selectedImgs) {
  350. let transedImgs=[];
  351. selectedImgs.forEach((imgIndex, index) => {
  352. transedImgs.push(WholeImgs[imgIndex]);
  353. });
  354. return transedImgs;
  355. }
  356. function showImage(filtedImgUrls) {
  357. filtedImgUrls.forEach((img, index) => {
  358. if (window.location.href.includes("huaban.com")) {
  359. if (img.includes("/webp")) {
  360. img = img.replace(/\/webp/g, "/png");
  361. }
  362. }
  363. let insertImg = `<div class="tyc-img-item-container-${index}" style="text-align:center;font-size:0px;
  364. margin:5px;border:1px solid #99d;border-radius:3px;
  365. ">
  366. <img class="tyc-image-preview" src="${img}"/ style="width:auto;height:200px;"></div>`
  367. document.querySelector(".tyc-image-wrapper").insertAdjacentHTML("beforeend", insertImg);
  368. let naturalW = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalWidth;
  369. let naturalH = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalHeight;
  370. let imgInfoContainer = `
  371. <div style="font-size:0px;background-color:rgba(100,100,100,0.6);height:30px;position:relative;">
  372. </div>
  373. `;
  374. let thisImgContainer = document.querySelector(`.tyc-img-item-container-${index}`);
  375. let imgContainerWidth = thisImgContainer.getBoundingClientRect().width;
  376. let imgInfo = `
  377. <span style="font-size:16px;position:absolute;left:calc(50% - 80px);top:7px;">${naturalW}X${naturalH}</span>
  378. `;
  379. /*
  380. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrows-fullscreen" viewBox="0 0 16 16" style="position:absolute;top:5px;right:5px;">
  381. <path fill-rule="evenodd" d="M5.828 10.172a.5.5 0 0 0-.707 0l-4.096 4.096V11.5a.5.5 0 0 0-1 0v3.975a.5.5 0 0 0 .5.5H4.5a.5.5 0 0 0 0-1H1.732l4.096-4.096a.5.5 0 0 0 0-.707zm4.344 0a.5.5 0 0 1 .707 0l4.096 4.096V11.5a.5.5 0 1 1 1 0v3.975a.5.5 0 0 1-.5.5H11.5a.5.5 0 0 1 0-1h2.768l-4.096-4.096a.5.5 0 0 1 0-.707zm0-4.344a.5.5 0 0 0 .707 0l4.096-4.096V4.5a.5.5 0 1 0 1 0V.525a.5.5 0 0 0-.5-.5H11.5a.5.5 0 0 0 0 1h2.768l-4.096 4.096a.5.5 0 0 0 0 .707zm-4.344 0a.5.5 0 0 1-.707 0L1.025 1.732V4.5a.5.5 0 0 1-1 0V.525a.5.5 0 0 1 .5-.5H4.5a.5.5 0 0 1 0 1H1.732l4.096 4.096a.5.5 0 0 1 0 .707z"/>
  382. </svg>*/
  383. let downAndFullBtn = `
  384. <span style="position:absolute;right:calc(50% - 30px);top:2px;border:1px solid #333;
  385. width:26px;height:26px;border-radius:20px;" class="select-image" data-value="${index}">
  386. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check" viewBox="0 0 16 16" style="position:absolute;top:-1px;right:-2px;width:30px;height:30px;" data-value="${index}">
  387. <path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z"/>
  388. </svg>
  389. </span>
  390. <span style="position:absolute;right:calc(50% - 60px);top:2px;border:1px solid #333;
  391. width:26px;height:26px;border-radius:20px;
  392. " class="download-direct">
  393. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16" style="position:absolute;top:5px;right:5px;">
  394. <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/>
  395. <path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/>
  396. </svg>
  397. </span>
  398. `;
  399. let downloadBtn = `
  400. <span style="position:absolute;right:calc(50% - 15px);top:2px;border:1px solid #333;
  401. width:26px;height:26px;border-radius:20px;
  402. " class="download-direct">
  403. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16" style="position:absolute;top:5px;right:5px;">
  404. <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/>
  405. <path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"/>
  406. </svg>
  407. </span>
  408. `
  409. thisImgContainer.insertAdjacentHTML("beforeend", imgInfoContainer);
  410. let thisImgInfoContainer = thisImgContainer.querySelector("div");
  411. let rectWidth = parseInt(thisImgContainer.getBoundingClientRect().width);
  412. if (rectWidth > 120) {
  413. thisImgInfoContainer.insertAdjacentHTML("beforeend", imgInfo);
  414. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  415. } else if (rectWidth <= 120 && rectWidth >= 50) {
  416. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  417. thisImgInfoContainer.getElementsByClassName("select-image")[0].style.right = "50%";
  418. thisImgInfoContainer.getElementsByClassName("download-direct")[0].style.right = "calc(50% - 30px)";
  419. } else {
  420. thisImgInfoContainer.insertAdjacentHTML("beforeend", downloadBtn);
  421. }
  422. ////console.log(img);
  423. });
  424. }
  425. function filterByWidth(src) {
  426. let tempImg = new Image();
  427. tempImg.src = src;
  428. if (tempImg.width >= parseInt(document.querySelector(".width-value-min").value)
  429. && tempImg.width <= parseInt(document.querySelector(".width-value-max").value)) {
  430. return src;
  431. }
  432. }
  433. function filterByHeight(src) {
  434. let tempImg = new Image();
  435. tempImg.src = src;
  436. if (tempImg.height >= parseInt(document.querySelector(".height-value-min").value)
  437. && tempImg.height <= parseInt(document.querySelector(".height-value-max").value)) {
  438. return src;
  439. }
  440. }
  441. function getSavedValue() {
  442. GM_getValue("width-check") && (document.querySelector(".width-check").checked = GM_getValue("width-check"));
  443. GM_getValue("height-check") && (document.querySelector(".height-check").checked = GM_getValue("height-check"));
  444. GM_getValue("width-value-min") && (document.querySelector(".width-value-min").value = GM_getValue("width-value-min"));
  445. GM_getValue("width-value-max") && (document.querySelector(".width-value-max").value = GM_getValue("width-value-max"));
  446. GM_getValue("height-value-min") && (document.querySelector(".height-value-min").value = GM_getValue("height-value-min"));
  447. GM_getValue("height-value-max") && (document.querySelector(".height-value-max").value = GM_getValue("height-value-max"));
  448. }
  449. function getImgAndChangeToBase64(currentImgIndex) {
  450. document.querySelector(".btn-zipDownload").disabled = true;
  451. document.querySelector(".btn-zipDownload").style.color = "grey";
  452. GM_xmlhttpRequest({
  453. method: "get",
  454. url: filteredImgUrls[currentImgIndex],
  455. responseType: "blob",
  456. onload: function (r) {
  457. var blob = r.response;
  458. let oFileReader = new FileReader();
  459. oFileReader.onloadend = function (e) {
  460. let base64 = e.target.result;
  461. //console.log("方式一》》》》》》》》》", base64)
  462. //将原来的图片地址替换为base64编码的地址
  463. filteredImgUrls[currentImgIndex] = base64;
  464. document.querySelector(".btn-zipDownload").disabled = false;
  465. document.querySelector(".btn-zipDownload").style.color = "";
  466. };
  467. oFileReader.readAsDataURL(blob);
  468. //imgZip.file(filename+".jpg",r.response);
  469. //console.log(r.response);
  470. }
  471. });
  472. }
  473. function fetchBase64ImgsThenPushToZipArray() {
  474. zipFilteredImgUrls.forEach((imgUrl, urlIndex) => {
  475. if (imgUrl.includes("data:image")) {
  476. return;
  477. }
  478. GM_xmlhttpRequest({
  479. method: "get",
  480. url: imgUrl,
  481. responseType: "blob",
  482. onload: function (r) {
  483. var blob = r.response;
  484. let oFileReader = new FileReader();
  485. oFileReader.onloadend = function (e) {
  486. let base64 = e.target.result;
  487. //console.log("》》", base64)
  488. if (base64.includes("data:image")) {
  489. zipFilteredImgUrls[urlIndex] = base64;
  490. //zipImgWaitDownload.push(base64);
  491. }
  492. };
  493. oFileReader.readAsDataURL(blob);
  494. }
  495. });
  496. })
  497. }
  498. function cutoffNotBase64Img(imgsUrlArray) {
  499. let resultArr = [];
  500. imgsUrlArray.forEach((imgUrl, urlIndex) => {
  501. if (imgUrl.includes("data:image")) {
  502. resultArr.push(imgUrl);
  503. }
  504. }
  505. );
  506. return resultArr;
  507. }
  508. }
  509. })();