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)

As of 2022-01-06. See the latest version.

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