图片下载器

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

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

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