图片下载器

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

当前为 2021-12-13 提交的版本,查看 最新版本

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