Image Downloader

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)

Stan na 22-12-2021. Zobacz najnowsza wersja.

  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.82
  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://greatest.deepsurf.us/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. try{
  71. var zipFolder = new JSZip();
  72. var zipSubFoler = zipFolder.folder('pics');
  73. }
  74. catch{
  75. }
  76. var fetchTip='';
  77. try {
  78. let imgEles = document.getElementsByTagName("img");
  79. let canvasEles=document.getElementsByTagName("canvas");
  80. for (let i = 0; i < imgEles.length; i++) {
  81. ////console.log(imgEles[i].src);
  82. if (!imgUrls.includes(imgEles[i].src)) {
  83. imgUrls.push(imgEles[i].src);
  84. } else if (!imgUrls.includes(imgEles[i].srcset)) {
  85. imgUrls.push(imgEles[i].srcset);
  86. }
  87. }
  88. if (window.location.href.includes("hathitrust.org")) {
  89. let imgs = document.querySelectorAll(".image img");
  90. if (imgs.length > 0) {
  91. let canvas = document.createElement("canvas");
  92. imgUrls = [];
  93. for (let pi = 0; pi < imgs.length; pi++) {
  94. canvas.width = imgs[pi].width;
  95. canvas.height = imgs[pi].height;
  96. canvas.getContext("2d").drawImage(imgs[pi], 0, 0);
  97. imgUrls.push(canvas.toDataURL("image/png"));
  98. }
  99. document.querySelector(".select-all").style = "position:relative;width:15px;height:15px;"
  100. } else {
  101. }
  102. }
  103. if(window.location.href.toString().includes("manga.bilibili.com/")){
  104. let iframeCanvas=`<iframe style="display:none;" id="tyc-insert-iframe"></iframe>`;
  105. if(document.getElementById("tyc-insert-iframe")==null){
  106. document.body.insertAdjacentHTML("afterbegin",iframeCanvas);
  107. document.getElementById("tyc-insert-iframe").contentDocument.body.insertAdjacentHTML("afterbegin",`<canvas id="tyc-insert-canvas"></canvas>`);
  108. document.body.getElementsByTagName('canvas')[0].__proto__.toBlob=document.getElementById("tyc-insert-iframe").contentDocument.getElementById("tyc-insert-canvas").__proto__.toBlob;
  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. } catch {
  139. //alert("error");
  140. }
  141. try {
  142. let imgRegs = bodyStr.match(/(?<=background-image:\s*url\()(\S+)(?=\))/g);
  143. for (let i = 0; i < imgRegs.length; i++) {
  144. ////console.log(imgRegs[i]);
  145. if (!imgUrls.includes(imgRegs[i].replace(/&quot;/g, ""))) {
  146. imgUrls.push(imgRegs[i].replace(/&quot;/g, ""));
  147. }
  148. }
  149. } catch {
  150. //alert("error");
  151. }
  152. let imgContainer = `
  153. <style>
  154. .tyc-image-container{
  155. position:fixed;
  156. top:0px;right:0px;width:50vw;z-index:2147483645;
  157. background-color: #dedede;
  158. border: 1px solid #aaa;
  159. overflow:scroll;height:100%;
  160. }
  161. .control-section{
  162. width:46vw;z-index:2147483646;
  163. position:fixed;right:30px;
  164. top:0px;display:block;
  165. height:80px;line-height:40px;
  166. background:#eee;border:1px solid #aaa;border-radius:2px;
  167. }
  168. .btn-download{
  169. border:1px solid #aaa;border-radius:5px;
  170. height:32px;line-height:32px;
  171. margin:0px;padding:0 5px;
  172. }
  173. .btn-zipDownload{
  174. border:1px solid #aaa;border-radius:5px;
  175. height:32px;line-height:32px;
  176. margin:0px;padding:0 5px;
  177. }
  178. .btn-close{
  179. font-size:20px;position:absolute;
  180. right:30px;top:4px;
  181. height:32px;line-height:32px;
  182. margin:0px;
  183. border-radius:10px;border:1px solid #aaa;
  184. width:30px;
  185. }
  186. .tyc-image-wrapper{
  187. margin-top:82px;display:flex;justify-content:center;
  188. align-items:center;flex-wrap:wrap;
  189. }
  190. .tyc-input-checkbox{
  191. background-color: initial;
  192. cursor: default;
  193. appearance: auto;
  194. box-sizing: border-box;
  195. margin: 3px 3px 3px 4px;
  196. padding: initial;
  197. border: initial;
  198. }
  199. </style>
  200. <div class="tyc-image-container">
  201. <div class="control-section">
  202. <input class="select-all tyc-input-checkbox" type="checkbox" name="select-all" value="select-all">${langSet.selectAll}
  203. <button class="btn-download" >${langSet.downloadBtn}</button>
  204. <button class="btn-zipDownload" >${langSet.zipDownloadBtn}</button>
  205. <span style="margin-left:10px;" class="num-tip">${fetchTip}</span>
  206. <button class="btn-close" >X</button>
  207. <p style="line-height:12px;">
  208. <div style="float:left;display:block;">
  209. <input type="checkbox" class="width-check img-check tyc-input-checkbox" name="width-check" value="width-check">Width:
  210. <input type="text" class="width-value-min" size="1" style="height:15px;width:50px;"
  211. min="0" max="9999" value="0">-
  212. <input type="text" class="width-value-max" size="1" style="height:15px;width:50px;"
  213. min="0" max="9999" value="3000">
  214. </div>
  215. <div style="float:left;margin-left:30px;display:block;">
  216. <input type="checkbox" class="height-check img-check tyc-input-checkbox" name="height-check" value="height-check">Height:
  217. <input type="text" class="height-value-min" size="1" style="height:15px;width:50px;"
  218. min="0" max="9999" value="0">-
  219. <input type="text" class="height-value-max" size="1" style="height:15px;width:50px;"
  220. min="0" max="9999" value="3000">
  221. </div>
  222. </p>
  223. </div>
  224. <div class="tyc-image-wrapper" >
  225. </div>
  226. </div>
  227. `
  228. let showBigImage = `
  229. <div class="show-big-image" style="position:fixed;left:30%;top:30%;z-index:2147483647;">
  230. </div>
  231. `
  232. document.body.insertAdjacentHTML("afterbegin", imgContainer);
  233. document.body.onclick = (e) => {
  234. //console.log(e);
  235. if ((e.target.nodeName == "IMG" && e.target.className === "tyc-image-preview")) {
  236. let imgContainer = e.path.find(
  237. (ele) => {
  238. try {
  239. //console.log(ele);
  240. return ele.className.includes("tyc-img-item-container");
  241. }
  242. catch {
  243. }
  244. }
  245. )
  246. let path = imgContainer.getElementsByTagName("img")[0].src;
  247. try {
  248. let container = document.querySelector(".show-big-image");
  249. if (container.getElementsByTagName("img")[0].src === path) {
  250. container.remove();
  251. return;
  252. } else {
  253. container.remove();
  254. }
  255. }
  256. catch {
  257. }
  258. document.body.insertAdjacentHTML("beforeend", showBigImage);
  259. let showItem = `<img src="${path}"/>`
  260. document.querySelector(".show-big-image").insertAdjacentHTML("beforeend", showItem);
  261. let tempImg = document.querySelector(".show-big-image img");
  262. let dWidth = (window.innerWidth - tempImg.width) / 2;
  263. let dHeight = (window.innerHeight - tempImg.height) / 2;
  264. document.querySelector(".show-big-image").style.left = dWidth + "px";
  265. document.querySelector(".show-big-image").style.top = dHeight + "px";
  266. } else if (e.target.parentElement.className === "show-big-image") {
  267. try {
  268. document.querySelector(".show-big-image").remove();
  269. }
  270. catch
  271. {
  272. }
  273. } else if (e.target.classList[1] == "bi-download" || e.path.find(isDownload) != undefined) {
  274. let imgContainer = e.path.find(
  275. (ele) => {
  276. try {
  277. //console.log(ele);
  278. return ele.className.includes("tyc-img-item-container");
  279. }
  280. catch {
  281. }
  282. }
  283. )
  284. let path = imgContainer.getElementsByTagName("img")[0].src;
  285. let filename;
  286. if (path.indexOf("/") > 0)//如果包含有"/"号 从最后一个"/"号+1的位置开始截取字符串
  287. {
  288. filename = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
  289. }
  290. else {
  291. filename = path;
  292. }
  293. //console.log("download start" + path + " " + filename);
  294. GM_download(path, "pic");
  295. } else if (e.target.classList[1] == "bi-check" || e.path.find(isSelect) != undefined) {
  296. let checkSvg = e.path.find((ele) => ele.classList[1] === "bi-check");
  297. let currentImgIndex = parseInt(checkSvg.dataset.value);
  298. let container = e.path.find((ele) => ele.className === `tyc-img-item-container-${currentImgIndex}`);
  299. if (imgSelected.includes(currentImgIndex)) {
  300. imgSelected.splice(imgSelected.indexOf(currentImgIndex), 1);
  301. checkSvg.style.color = "black";
  302. container.style.border = "1px solid #99d";
  303. } else {
  304. imgSelected.push(currentImgIndex);
  305. checkSvg.style.color = "white";
  306. container.style.border = "1px solid white";
  307. }
  308. zipImgSelected=imgSelected;
  309. document.querySelector(".num-tip").innerText = `已选(${imgSelected.length}/${imgUrls.length})张图片`;
  310. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  311. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  312. zipImgWaitDownload=cutoffNotBase64Img(zipImgWaitDownload);
  313. }
  314. }
  315. document.querySelector(".btn-close").onclick = (e) => {
  316. document.querySelector(".tyc-image-container").remove();
  317. }
  318. document.querySelector(".btn-download").onclick = (e) => {
  319. if (imgWaitDownload.length >= 1) {
  320. console.log(imgWaitDownload);
  321. imgWaitDownload.forEach(async (img, index) => {
  322. //let filename = `pic-${index}.jpg`;
  323. //filename=filename.replace(/\\/g, '/').replace(/\/{2,}/g, '/');
  324. await GM_download(img, `pic-${index}`);
  325. });
  326. } else {
  327. alert("请至少选中一张图片。");
  328. }
  329. }
  330. document.querySelector(".btn-zipDownload").onclick = (e) => {
  331. if (zipImgWaitDownload.length >= 1) {
  332. //console.log(zipImgWaitDownload);
  333. zipImgWaitDownload.forEach(async (img, index) => {
  334. let fileExt = img.substring(img.indexOf("image/") + 6, img.indexOf(";"))
  335. fileExt=fileExt.includes("svg")?"svg":fileExt;
  336. let filename = `pic${index}.${fileExt}`;
  337. zipSubFoler.file(filename, img.split(",")[1], { base64: true });
  338. });
  339. zipFolder.generateAsync({ type: "blob" })
  340. .then(function (content) {
  341. // see FileSaver.js
  342. saveAs(content, "pics.zip");
  343. zipFolder.remove("pics");
  344. zipSubFoler = zipFolder.folder('pics');
  345. });
  346. } else {
  347. alert("请至少选中一张图片。");
  348. }
  349. }
  350. document.body.onchange = (e) => {
  351. if (e.target.className.includes("width-check")) {
  352. GM_setValue('width-check', e.target.checked);
  353. }
  354. if (e.target.className.includes("height-check")) {
  355. GM_setValue('height-check', e.target.checked);
  356. }
  357. if (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")) {
  358. GM_setValue(e.target.className, e.target.value);
  359. }
  360. (e.target.className.includes("width-check") || e.target.className.includes("height-check") ||
  361. (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")))
  362. && (clean(), init());
  363. }
  364. document.querySelector(".select-all").onchange = (e) => {
  365. if (document.querySelector(".select-all").checked) {
  366. imgWaitDownload = filteredImgUrls;
  367. zipImgWaitDownload=cutoffNotBase64Img(zipFilteredImgUrls);
  368. } else {
  369. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  370. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  371. }
  372. document.querySelector(".num-tip").innerText = `已选(${imgWaitDownload.length}/${filteredImgUrls.length})张图片`;
  373. }
  374. init();
  375. function init() {
  376. filteredImgUrls = imgUrls;
  377. getSavedValue();
  378. if (document.querySelector(".width-check").checked) {
  379. filteredImgUrls = filteredImgUrls.filter(filterByWidth);
  380. }
  381. if (document.querySelector(".height-check").checked) {
  382. filteredImgUrls = filteredImgUrls.filter(filterByHeight);
  383. }
  384. zipFilteredImgUrls = filteredImgUrls;
  385. fetchBase64ImgsThenPushToZipArray();
  386. showImage(filteredImgUrls);
  387. }
  388. function clean() {
  389. imgWaitDownload = [];
  390. imgSelected = [];
  391. document.querySelector(".num-tip").innerText = `已选(${imgSelected.length}/${imgUrls.length})张图片`;
  392. document.querySelector(".tyc-image-wrapper").innerHTML = "";
  393. }
  394. function isDownload(ele) {
  395. return ele.className == "download-direct";
  396. }
  397. function isSelect(ele) {
  398. return ele.className == "select-image";
  399. }
  400. function transIndexToLink(WholeImgs,selectedImgs) {
  401. let transedImgs=[];
  402. selectedImgs.forEach((imgIndex, index) => {
  403. transedImgs.push(WholeImgs[imgIndex]);
  404. });
  405. return transedImgs;
  406. }
  407. function showImage(filtedImgUrls) {
  408. filtedImgUrls.forEach((img, index) => {
  409. if (window.location.href.includes("huaban.com")) {
  410. if (img.includes("/webp")) {
  411. img = img.replace(/\/webp/g, "/png");
  412. }
  413. }
  414. let insertImg = `<div class="tyc-img-item-container-${index}" style="text-align:center;font-size:0px;
  415. margin:5px;border:1px solid #99d;border-radius:3px;
  416. ">
  417. <img class="tyc-image-preview" src="${img}"/ style="width:auto;height:200px;"></div>`
  418. document.querySelector(".tyc-image-wrapper").insertAdjacentHTML("beforeend", insertImg);
  419. let naturalW = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalWidth;
  420. let naturalH = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalHeight;
  421. let imgInfoContainer = `
  422. <div style="font-size:0px;background-color:rgba(100,100,100,0.6);height:30px;position:relative;">
  423. </div>
  424. `;
  425. let thisImgContainer = document.querySelector(`.tyc-img-item-container-${index}`);
  426. let imgContainerWidth = thisImgContainer.getBoundingClientRect().width;
  427. let imgInfo = `
  428. <span style="font-size:16px;position:absolute;left:calc(50% - 80px);top:7px;">${naturalW}X${naturalH}</span>
  429. `;
  430. /*
  431. <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;">
  432. <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"/>
  433. </svg>*/
  434. let downAndFullBtn = `
  435. <span style="position:absolute;right:calc(50% - 30px);top:2px;border:1px solid #333;
  436. width:26px;height:26px;border-radius:20px;" class="select-image" data-value="${index}">
  437. <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}">
  438. <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"/>
  439. </svg>
  440. </span>
  441. <span style="position:absolute;right:calc(50% - 60px);top:2px;border:1px solid #333;
  442. width:26px;height:26px;border-radius:20px;
  443. " class="download-direct">
  444. <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;">
  445. <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"/>
  446. <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"/>
  447. </svg>
  448. </span>
  449. `;
  450. let downloadBtn = `
  451. <span style="position:absolute;right:calc(50% - 15px);top:2px;border:1px solid #333;
  452. width:26px;height:26px;border-radius:20px;
  453. " class="download-direct">
  454. <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;">
  455. <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"/>
  456. <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"/>
  457. </svg>
  458. </span>
  459. `
  460. thisImgContainer.insertAdjacentHTML("beforeend", imgInfoContainer);
  461. let thisImgInfoContainer = thisImgContainer.querySelector("div");
  462. let rectWidth = parseInt(thisImgContainer.getBoundingClientRect().width);
  463. if (rectWidth > 120) {
  464. thisImgInfoContainer.insertAdjacentHTML("beforeend", imgInfo);
  465. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  466. } else if (rectWidth <= 120 && rectWidth >= 50) {
  467. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  468. thisImgInfoContainer.getElementsByClassName("select-image")[0].style.right = "50%";
  469. thisImgInfoContainer.getElementsByClassName("download-direct")[0].style.right = "calc(50% - 30px)";
  470. } else {
  471. thisImgInfoContainer.insertAdjacentHTML("beforeend", downloadBtn);
  472. }
  473. ////console.log(img);
  474. });
  475. }
  476. function filterByWidth(src) {
  477. let tempImg = new Image();
  478. tempImg.src = src;
  479. if (tempImg.width >= parseInt(document.querySelector(".width-value-min").value)
  480. && tempImg.width <= parseInt(document.querySelector(".width-value-max").value)) {
  481. return src;
  482. }
  483. }
  484. function filterByHeight(src) {
  485. let tempImg = new Image();
  486. tempImg.src = src;
  487. if (tempImg.height >= parseInt(document.querySelector(".height-value-min").value)
  488. && tempImg.height <= parseInt(document.querySelector(".height-value-max").value)) {
  489. return src;
  490. }
  491. }
  492. function getSavedValue() {
  493. GM_getValue("width-check") && (document.querySelector(".width-check").checked = GM_getValue("width-check"));
  494. GM_getValue("height-check") && (document.querySelector(".height-check").checked = GM_getValue("height-check"));
  495. GM_getValue("width-value-min") && (document.querySelector(".width-value-min").value = GM_getValue("width-value-min"));
  496. GM_getValue("width-value-max") && (document.querySelector(".width-value-max").value = GM_getValue("width-value-max"));
  497. GM_getValue("height-value-min") && (document.querySelector(".height-value-min").value = GM_getValue("height-value-min"));
  498. GM_getValue("height-value-max") && (document.querySelector(".height-value-max").value = GM_getValue("height-value-max"));
  499. }
  500. function fetchBase64ImgsThenPushToZipArray() {
  501. zipFilteredImgUrls.forEach((imgUrl, urlIndex) => {
  502. if (imgUrl.includes("data:image")) {
  503. return;
  504. }
  505.  
  506. fetch(imgUrl,{
  507. method: "get",
  508. mode: 'cors'
  509. }).then(response=>{
  510. if (!response.ok) {
  511. throw new Error('Network response was not OK');
  512. }
  513. return response.blob();
  514. }).then(myBlob=>{
  515. var blob = myBlob
  516. let oFileReader = new FileReader();
  517. oFileReader.onloadend = function (e) {
  518. let base64 = e.target.result;
  519. //console.log("》》", base64)
  520. if (base64.includes("data:image")) {
  521. zipFilteredImgUrls[urlIndex] = base64;
  522. //zipImgWaitDownload.push(base64);
  523. }
  524. };
  525. oFileReader.readAsDataURL(blob);
  526. })
  527. .catch((error)=>{
  528. GM_xmlhttpRequest({
  529. method: "get",
  530. url: imgUrl,
  531. responseType: "blob",
  532. onload: function (r) {
  533. var blob = r.response;
  534. let oFileReader = new FileReader();
  535. oFileReader.onloadend = function (e) {
  536. let base64 = e.target.result;
  537. if (base64.includes("data:image")) {
  538. zipFilteredImgUrls[urlIndex] = base64;
  539. //zipImgWaitDownload.push(base64);
  540. }
  541. };
  542. oFileReader.readAsDataURL(blob);
  543. }
  544. });
  545. })
  546. })
  547. }
  548. function cutoffNotBase64Img(imgsUrlArray) {
  549. let resultArr = [];
  550. imgsUrlArray.forEach((imgUrl, urlIndex) => {
  551. if (imgUrl.includes("data:image")) {
  552. resultArr.push(imgUrl);
  553. }
  554. }
  555. );
  556. return resultArr;
  557. }
  558. }
  559. })();