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)

2022-01-23 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name Image Downloader
  3. // @name:zh-CN 图片下载器
  4. // @name:zh-TW 图片下载器
  5. // @name:ja 画像ダウンローダー
  6. // @name:ko 이미지 다운로더
  7. // @name:de Image Downloader
  8. // @name:es Image Downloader
  9. // @name:eo Image Downloader
  10. // @name:fr Image Downloader
  11. // @name:it Image Downloader
  12. // @name:ru Image Downloader
  13. // @name:vi Image Downloader
  14. // @name:pt-BR Image Downloader
  15. // @name:id Image Downloader
  16. // @name:ar Image Downloader
  17. // @name:bg Image Downloader
  18. // @name:cs Image Downloader
  19. // @name:tr Image Downloader
  20. // @name:el Image Downloader
  21. // @name:hu Image Downloader
  22. // @name:th Image Downloader
  23. // @namespace http://tampermonkey.net/
  24. // @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)
  25. // @description:zh-CN 可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,不能右键保存图片或者保存的图片文件格式无法识别,均可以用脚本提取,然后用脚本提供的下载按钮,就可以下载到正确格式的图片文件。点击右键-tampermonkey-图片下载器-打开脚本(或快捷键alt+w),按这个顺序使用。(目前只适合chrome+tampermonkey,其他组合多少有问题)
  26. // @description:zh-TW 可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,不能右键保存图片或者保存的图片文件格式无法识别,均可以用脚本提取,然后用脚本提供的下载按钮,就可以下载到正确格式的图片文件。点击右键-tampermonkey-图片下载器-打开脚本(或快捷键alt+w),按这个顺序使用。(目前只适合chrome+tampermonkey,其他组合多少有问题)
  27. // @description:ja 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)
  28. // @description:ko 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)
  29. // @description:de 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)
  30. // @description:es 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)
  31. // @description:eo 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)
  32. // @description:fr 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)
  33. // @description:it 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)
  34. // @description:ru 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)
  35. // @description:vi 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)
  36. // @description:pt-BR 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)
  37. // @description:id 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)
  38. // @description:ar 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)
  39. // @description:bg 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)
  40. // @description:cs 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)
  41. // @description:tr 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)
  42. // @description:el 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)
  43. // @description:hu 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)
  44. // @description:th 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)
  45. // @version 1.96
  46. // @author 桃源隐叟
  47. // @include *
  48. // @connect *
  49. // @grant GM_openInTab
  50. // @grant GM_registerMenuCommand
  51. // @grant GM_setValue
  52. // @grant GM_getValue
  53. // @grant GM_deleteValue
  54. // @grant GM_xmlhttpRequest
  55. // @grant GM_download
  56. // @require https://cdn.jsdelivr.net/npm/hotkeys-js@3.7.2/dist/hotkeys.min.js
  57. // @require https://cdn.bootcss.com/jszip/3.7.1/jszip.min.js
  58. // @require https://cdn.bootcss.com/FileSaver.js/1.3.8/FileSaver.min.js
  59. // @run-at document-end
  60. // @match *
  61. // @match https://www.bilibili.com/
  62. // @match https://588ku.com/
  63. // @homepageURL https://github.com/taoyuancun123/modifyText/blob/master/modifyText.js
  64. // @supportURL https://greatest.deepsurf.us/zh-CN/scripts/419894/feedback
  65. // @license GPLv3
  66. // ==/UserScript==
  67. (function () {
  68. 'use strict';
  69. var lang = navigator.appName == "Netscape" ? navigator.language : navigator.userLanguage;
  70. var langSet;
  71. var localization = {
  72. zh: {
  73. selectAll: "全选",
  74. downloadBtn: "下载",
  75. downloadMenuText: "打开脚本(Alt+w)",
  76. zipDownloadBtn: "zip下载",
  77. selectAlert:"请至少选中一张图片。",
  78. fetchTip:"准备抓取canvas图片",
  79. fetchCount1:`抓取canvas图片第`,
  80. fetchCount2:'张',
  81. fetchDoneTip1:"已选(0/",
  82. fetchDoneTip1Type2:"已选(",
  83. fetchDoneTip2:")张图片",
  84. },
  85. en: {
  86. selectAll: "selectAll",
  87. downloadBtn: "download",
  88. downloadMenuText: "Open(Alt+w)",
  89. zipDownloadBtn: "zip Download",
  90. selectAlert:"Please at last select one image.",
  91. fetchTip:"Ready to fetch canvas image.",
  92. fetchCount1:`Fetch the`,
  93. fetchCount2:' canvas image.',
  94. fetchDoneTip1:"(0/",
  95. fetchDoneTip1Type2:"(",
  96. fetchDoneTip2:") Images selected",
  97. }
  98. }
  99. if (lang.toLowerCase().includes("zh-")) {
  100. langSet = localization.zh;
  101. } else {
  102. langSet = localization.en;
  103. }
  104.  
  105. const autoBigImage={
  106. bigImageArray:[],
  107. defaultRules:[
  108. {originReg:/(?<=(.+sinaimg\.(?:cn|com)\/))([\w\.]+)(?=(\/.+))/i,replacement:"large",tip:"用于新浪微博"},
  109. {originReg:/(?<=(.+alicdn\.(?:cn|com)\/.+\.(jpg|jpeg|gif|png|bmp|webp)))_.+/i,replacement:"",tip:"用于淘宝系网站"},
  110. {originReg:/(.+alicdn\.(?:cn|com)\/.+)(\.\d+x\d+)(\.(jpg|jpeg|gif|png|bmp|webp)).*/i,replacement:(match,p1,p2,p3)=>p1+p3,tip:"用于1688"},
  111. {originReg:/(?<=(.+360buyimg\.(?:cn|com)\/))(\w+\/)(?=(.+\.(jpg|jpeg|gif|png|bmp|webp)))/i,replacement:"n0/",tip:"用于京东"},
  112. {originReg:/(?<=(.+hdslb\.(?:cn|com)\/.+\.(jpg|jpeg|gif|png|bmp|webp)))@.+/i,replacement:"",tip:"用于B站"},
  113. ],
  114. defaultRulesChecked:[
  115. ],
  116. userRules:[],
  117. userRulesChecked:[],
  118. replace(originImgUrls){
  119. let that=this;
  120. that.bigImageArray=[];
  121. let tempArray=Array.from(new Set(originImgUrls)).filter(item=>item&&item);
  122. that.setRulesChecked();
  123. //console.log(that.bigImageArray);
  124. tempArray.forEach(replaceByReg);
  125. function replaceByReg(urlStr,urlIndex){
  126. //if(!urlStr)return;
  127. if(urlStr.includes("data:image/"))return;
  128. that.defaultRules.forEach((rule,ruleIndex)=>{
  129. if(that.defaultRulesChecked[ruleIndex]!=="checked"){
  130. that.bigImageArray.push(urlStr);
  131. return;
  132. }
  133.  
  134. let bigImage=urlStr.replace(rule.originReg,rule.replacement);
  135. if(bigImage!==urlStr){
  136. that.bigImageArray.push(urlStr);
  137. that.bigImageArray.push(bigImage);
  138. }else{
  139. that.bigImageArray.push(urlStr);
  140. }
  141. })
  142. that.userRules.forEach((rule,ruleIndex)=>{
  143. if(that.userRulesChecked[ruleIndex]!=="checked"){
  144. that.bigImageArray.push(urlStr);
  145. return;
  146. }
  147.  
  148. let bigImage=urlStr.replace(rule.originReg,rule.replacement);
  149. if(bigImage!==urlStr){
  150. that.bigImageArray.push(urlStr);
  151. that.bigImageArray.push(bigImage);
  152. }else{
  153. that.bigImageArray.push(urlStr);
  154. }
  155. })
  156. }
  157. },
  158. getBigImageArray(originImgUrls){
  159. this.replace(originImgUrls);
  160. let uniqueArray=Array.from(new Set(this.bigImageArray));
  161. return uniqueArray;
  162. },
  163. showDefaultRules(){
  164. let that=this;
  165. let defaultContainer=document.body.querySelector(".tyc-set-domain-default");
  166. that.setRulesChecked();
  167.  
  168. this.defaultRules.forEach((v,i)=>{
  169. let rulesHtml=`<div class="tyc-set-replacerule">
  170. <input type="checkbox" name="active" class="tyc-default-active" ${that.defaultRulesChecked[i]}>
  171. <input type="text" name="regrule" placeholder="输入待替换正则" class="tyc-search-title" value="${v.originReg}">
  172. <input type="text" name="replace" placeholder="输入替换它的字符串或者函数" class="tyc-search-url" value="${v.replacement}">
  173. <span class="tyc-default-tip">${v.tip}</span>
  174. </div>
  175. `
  176. defaultContainer.insertAdjacentHTML("beforeend",rulesHtml);
  177. })
  178. },//showDefaultRules
  179. showRules(containerName,rulesType,checkType,checkClassName){
  180. let that=this;
  181. let Container=document.body.querySelector("."+containerName);
  182. that.setRulesChecked();
  183. that.setCustomRules();
  184. //console.log(that.userRules);
  185. //console.log(that);
  186.  
  187. that[rulesType].forEach((v,i)=>{
  188. //console.log(that[checkType])
  189. let rulesHtml=`<div class="tyc-set-replacerule">
  190. <input type="checkbox" name="active" class="${checkClassName}" ${that[checkType][i]}>
  191. <input type="text" name="regrule" placeholder="输入待替换正则" class="tyc-search-title" value="${v.originReg}">
  192. <input type="text" name="replace" placeholder="输入替换它的字符串或者函数" class="tyc-search-url" value="${v.replacement}">
  193. <span class="tyc-default-tip">${v.tip}</span>
  194. </div>
  195. `
  196. Container.insertAdjacentHTML("beforeend",rulesHtml);
  197. })
  198. },
  199. onclickShowDefaultBtn(){
  200. let defaultContainer=document.body.querySelector(".tyc-set-domain-default");
  201. if(defaultContainer.style.display==="none"||defaultContainer.style.display===''){
  202. defaultContainer.style.display="flex";
  203. }else{
  204. defaultContainer.style.display="none";
  205. }
  206. },
  207. oncheckChange(){
  208. let checks=document.body.querySelectorAll(".tyc-default-active");
  209. this.defaultRulesChecked=[];
  210.  
  211. checks.forEach((v,i)=>{
  212. if(v.checked){
  213. this.defaultRulesChecked.push("checked");
  214. }else{
  215. this.defaultRulesChecked.push("");
  216. }
  217. })
  218.  
  219. GM_setValue("defaultRulesChecked",this.defaultRulesChecked);
  220. },
  221. oncheckChangeCustom(){
  222. let checks=document.body.querySelectorAll(".tyc-custom-active");
  223. this.userRulesChecked=[];
  224.  
  225. checks.forEach((v,i)=>{
  226. if(v.checked){
  227. this.userRulesChecked.push("checked");
  228. }else{
  229. this.userRulesChecked.push("");
  230. }
  231. })
  232.  
  233. GM_setValue("userRulesChecked",this.userRulesChecked);
  234. },
  235. setRulesChecked(){
  236. if(GM_getValue("defaultRulesChecked")){
  237. this.defaultRulesChecked=GM_getValue("defaultRulesChecked");
  238. }else{
  239. this.defaultRules.forEach(v=>{
  240. this.defaultRulesChecked.push("checked");
  241. })
  242. GM_setValue("defaultRulesChecked",this.defaultRulesChecked);
  243. }
  244.  
  245. if(GM_getValue("userRulesChecked")&&GM_getValue("userRulesChecked").length>0){
  246. this.userRulesChecked=GM_getValue("userRulesChecked");
  247. }else{
  248. this.userRules.forEach(v=>{
  249. this.userRulesChecked.push("checked");
  250. })
  251. GM_setValue("userRulesChecked",this.userRulesChecked);
  252. }
  253. },
  254. getCustomRules(event){
  255. let that=autoBigImage;
  256. let file=document.querySelector("#tycfileElem").files[0];
  257. let fileReader=new FileReader();
  258. fileReader.onload=(e)=>{
  259. let result=e.target.result;
  260. that.userRules=eval(result);
  261.  
  262. GM_deleteValue("userRulesChecked")
  263. that.setRulesChecked();
  264. GM_setValue("userRules",result);
  265. //console.log(GM_getValue('userRules'));
  266. document.body.querySelector(".tyc-set-domain-custom").innerHTML="";
  267. that.showRules("tyc-set-domain-custom","userRules","userRulesChecked","tyc-custom-active");
  268. }
  269. fileReader.readAsText(file,'GB2312');
  270. },
  271. setCustomRules(){
  272. if(GM_getValue("userRules")){
  273. try {
  274. this.userRules=eval(GM_getValue("userRules"));
  275. } catch (error) {
  276. GM_setValue("userRules","");
  277. }
  278. }
  279. }
  280. }
  281. GM_registerMenuCommand(langSet.downloadMenuText, wrapper);
  282. hotkeys('alt+w', wrapper);
  283. function wrapper() {
  284. try {
  285. document.querySelector(".tyc-image-container").remove();
  286. } catch {
  287. }
  288. var imgUrls = [];
  289. var bodyStr = document.body.innerHTML;
  290. var imgSelected = [];
  291. var zipImgSelected = [];
  292. var imgWaitDownload = [];
  293. var zipImgWaitDownload = [];
  294. var widthFilter = { min: 0, max: 3000 };
  295. var heightFilter = { min: 0, max: 3000 };
  296. var filteredImgUrls = [];
  297. var zipFilteredImgUrls = [];
  298. try{
  299. var zipFolder = new JSZip();
  300. var zipSubFoler = zipFolder.folder('pics');
  301. }
  302. catch{
  303. }
  304. var fetchTip='';
  305. try {
  306. let imgEles = document.getElementsByTagName("img");
  307. let canvasEles=document.getElementsByTagName("canvas");
  308. for (let i = 0; i < imgEles.length; i++) {
  309. ////console.log(imgEles[i].src);
  310. if (!imgUrls.includes(imgEles[i].src)) {
  311. imgUrls.push(imgEles[i].src);
  312. } else if (!imgUrls.includes(imgEles[i].srcset)) {
  313. imgUrls.push(imgEles[i].srcset);
  314. }
  315. }
  316. let imgRegs = bodyStr.match(/(?<=background-image:\s*url\()(\S+)(?=\))/g);
  317. for (let i = 0; i < imgRegs.length; i++) {
  318. ////console.log(imgRegs[i]);
  319. if (!imgUrls.includes(imgRegs[i].replace(/&quot;/g, ""))) {
  320. imgUrls.push(imgRegs[i].replace(/&quot;/g, ""));
  321. }
  322. }
  323. if (window.location.href.includes("hathitrust.org")) {
  324. let imgs = document.querySelectorAll(".image img");
  325. if (imgs.length > 0) {
  326. let canvas = document.createElement("canvas");
  327. imgUrls = [];
  328. for (let pi = 0; pi < imgs.length; pi++) {
  329. canvas.width = imgs[pi].width;
  330. canvas.height = imgs[pi].height;
  331. canvas.getContext("2d").drawImage(imgs[pi], 0, 0);
  332. imgUrls.push(canvas.toDataURL("image/png"));
  333. }
  334. document.querySelector(".select-all").style = "position:relative;width:15px;height:15px;"
  335. } else {
  336. }
  337. }
  338. if(window.location.href.toString().includes("manga.bilibili.com/")){
  339. let iframeCanvas=`<iframe style="display:none;" id="tyc-insert-iframe"></iframe>`;
  340. if(document.getElementById("tyc-insert-iframe")==null){
  341. document.body.insertAdjacentHTML("afterbegin",iframeCanvas);
  342. document.getElementById("tyc-insert-iframe").contentDocument.body.insertAdjacentHTML("afterbegin",`<canvas id="tyc-insert-canvas"></canvas>`);
  343. document.body.getElementsByTagName('canvas')[0].__proto__.toBlob=document.getElementById("tyc-insert-iframe").contentDocument.getElementById("tyc-insert-canvas").__proto__.toBlob;
  344. }
  345. }
  346. let oldLength=imgUrls.length;
  347. if(canvasEles.length>0){
  348. fetchTip=langSet.fetchTip;
  349. var completeFlag=0;
  350. for(let j=0;j<canvasEles.length;j++){
  351. canvasEles[j].toBlob(blobCallback);
  352. function blobCallback(blob){
  353. let oFileReader = new FileReader();
  354. oFileReader.onloadend = function (e) {
  355. let base64 = e.target.result;
  356. if (base64.includes("data:image")) {
  357. if (!imgUrls.includes(base64)) {
  358. //imgUrls.push(base64);
  359. imgUrls[oldLength+j]=base64;
  360. }
  361. completeFlag++;
  362. document.querySelector(".num-tip").innerText=`${langSet.fetchCount1} ${completeFlag}/${canvasEles.length} ${langSet.fetchCount2}`;
  363. if(completeFlag===canvasEles.length){
  364. clean();
  365. init();
  366. }
  367. }
  368. };
  369. oFileReader.readAsDataURL(blob);
  370. }
  371. }
  372. }else{
  373. fetchTip=`${langSet.fetchDoneTip1}${imgUrls.length}${langSet.fetchDoneTip2}`;
  374. }
  375. } catch {
  376. //alert("error");
  377. }
  378. let imgContainer = `
  379. <style>
  380. .tyc-image-container{
  381. position:fixed;
  382. top:0px;
  383. left:10%;
  384. width:80vw;
  385. z-index:2147483645;
  386. background-color: #dedede;
  387. border: 1px solid #aaa;
  388. overflow:scroll;height:100%;
  389. }
  390. .tyc-image-container button{
  391. border:1px solid #aaa;
  392. border-radius:5px;
  393. height:32px;line-height:32px;
  394. margin:0px;padding:0 5px;
  395. }
  396. .tyc-image-container button:hover{
  397. background-color: #f50;
  398. color: #fff;
  399. }
  400. .control-section{
  401. width:80vw;
  402. z-index:2147483646;
  403. position:fixed;
  404. top:0px;
  405. left:10%;
  406. display: flex;
  407. flex-direction: column;
  408. justify-content: center;
  409. line-height:40px;
  410. background:#eee;border:1px solid #aaa;border-radius:2px;
  411. }
  412. .control-section-sub{
  413. display: flex;
  414. margin-bottom: 5px;
  415. }
  416. .tyc-normal-section{
  417. display: flex;
  418. align-items: center;
  419. flex-direction: row;
  420. justify-content: flex-start;
  421. flex-wrap: nowrap;
  422. align-content: normal;
  423. }
  424. .btn-download{
  425. border:1px solid #aaa;border-radius:5px;
  426. height:32px;line-height:32px;
  427. margin:0px;padding:0 5px;
  428. }
  429. .btn-zipDownload{
  430. border:1px solid #aaa;border-radius:5px;
  431. height:32px;line-height:32px;
  432. margin:0px;padding:0 5px;
  433. }
  434. .btn-close{
  435. font-size:20px;position:absolute;
  436. right:30px;top:4px;
  437. height:32px;line-height:32px;
  438. margin:0px;
  439. border-radius:10px;border:1px solid #aaa;
  440. width:30px;
  441. }
  442. .tyc-image-wrapper{
  443. margin-top:82px;display:flex;justify-content:center;
  444. align-items:center;flex-wrap:wrap;
  445. }
  446. .tyc-input-checkbox{
  447. background-color: initial;
  448. cursor: default;
  449. appearance: auto;
  450. box-sizing: border-box;
  451. margin: 3px 3px 3px 4px;
  452. padding: initial;
  453. border: initial;
  454. }
  455. .tyc-extend-set{
  456. padding: 10px;
  457. border-top: 1px solid rgba(100,100,100,0.1);
  458. }
  459. .tyc-extend-set{
  460. display: none;
  461. align-items: stretch;
  462. flex-direction: column;
  463. justify-content: flex-start;
  464. flex-wrap: nowrap;
  465. padding: 5px;
  466. width: auto;
  467. }
  468. .tyc-extend-set-container{
  469. display: flex;
  470. align-items: flex-start;
  471. flex-direction: column;
  472. justify-content: flex-start;
  473. flex-wrap: nowrap;
  474. align-content: normal;
  475. border: 1px solid rgba(100,100,100,0.5);
  476. padding: 5px;
  477. margin-bottom: 5px;
  478. }
  479. .tyc-autobigimg-set{
  480. display: flex;
  481. align-items: flex-start;
  482. flex-direction: column;
  483. justify-content: flex-start;
  484. flex-wrap: nowrap;
  485. align-content: normal;
  486. border: 1px solid rgba(100,100,100,0.5);
  487. padding: 5px;
  488. }
  489. .tyc-set-domain{
  490. display: flex;
  491. align-items: flex-start;
  492. flex-direction: column;
  493. justify-content: flex-start;
  494. flex-wrap: nowrap;
  495. align-content: normal;
  496. margin: 5px;
  497. padding: 5px;
  498. border: 1px solid rgba(100,100,100,0.3);
  499. width: 95%;
  500. max-height: 150px;
  501. overflow: scroll;
  502. }
  503. .tyc-abi-title{
  504. display: flex;
  505. flex-direction: row;
  506. align-items: center;
  507. justify-content: space-around;
  508. width: 100%;
  509. }
  510. .tyc-abi-domain-title{
  511. display: flex;
  512. flex-direction: row;
  513. align-items: center;
  514. justify-content: space-between;
  515. width: 95%;
  516. border-bottom: 1px solid #ddd;
  517. }
  518. .tyc-set-replacerule{
  519. display: flex;
  520. flex-direction: row;
  521. justify-content: flex-start;
  522. align-items: center;
  523. margin-bottom: 3px;
  524. flex-wrap: wrap;
  525. }
  526. .tyc-set-replacerule *,.tyc-set-replacerule button{
  527. margin-left: 5px;
  528. }
  529. .tyc-set-domain-default{
  530. height: 200px;
  531. overflow: scroll;
  532. display: none;
  533. }
  534. </style>
  535. <div class="tyc-image-container">
  536. <div class="control-section">
  537. <div class="control-section-sub tyc-normal-section">
  538. <input class="select-all tyc-input-checkbox" type="checkbox" name="select-all" value="select-all">${langSet.selectAll}
  539. <button class="btn-download" style="margin-left:5px;">${langSet.downloadBtn}</button>
  540. <button class="btn-zipDownload" style="margin-left:5px;">${langSet.zipDownloadBtn}</button>
  541. <span style="margin-left:10px;" class="num-tip">${langSet.fetchDoneTip1}${imgUrls.length}${langSet.fetchDoneTip2}</span>
  542. <button cstyle="margin-left:10px;" class="btn-close" >X</button>
  543. </div>
  544. <div style="line-height:12px;" class="control-section-sub tyc-normal-section">
  545. <div style="float:left;display:block;">
  546. <input type="checkbox" class="width-check img-check tyc-input-checkbox" name="width-check" value="width-check">Width:
  547. <input type="text" class="width-value-min" size="1" style="height:15px;width:50px;"
  548. min="0" max="9999" value="0">-
  549. <input type="text" class="width-value-max" size="1" style="height:15px;width:50px;"
  550. min="0" max="9999" value="3000">
  551. </div>
  552. <div style="float:left;margin-left:30px;display:block;">
  553. <input type="checkbox" class="height-check img-check tyc-input-checkbox" name="height-check" value="height-check">Height:
  554. <input type="text" class="height-value-min" size="1" style="height:15px;width:50px;"
  555. min="0" max="9999" value="0">-
  556. <input type="text" class="height-value-max" size="1" style="height:15px;width:50px;"
  557. min="0" max="9999" value="3000">
  558. </div>
  559. <div style="float:left;margin-left:30px;display:block;" class="tyc-cors">
  560. <span class="tyc-tip" style="display: none;
  561. position: absolute;
  562. top: 5px;
  563. left: 50px;
  564. white-space: nowrap;
  565. background: rgb(204, 204, 204);
  566. border: 1px solid rgb(150, 150, 150);
  567. border-radius: 3px;
  568. padding: 5px;">勾选使用zip下载后,会请求跨域权限,否则zip下载基本下载不到图片。
  569. </span>
  570. <input type="checkbox" class="cors-check img-check tyc-input-checkbox" name="cors-check" value="cors-check">
  571. <span>使用zip下载</span>
  572. </div>
  573. <div style="float:left;margin-left:30px;display:block;" class="tyc-extend-btn">
  574. <span>更多设置 </span>
  575. <span style="top: 3px;position: relative;">
  576. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-double-down" viewBox="0 0 16 16">
  577. <path fill-rule="evenodd" d="M1.646 6.646a.5.5 0 0 1 .708 0L8 12.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/>
  578. <path fill-rule="evenodd" d="M1.646 2.646a.5.5 0 0 1 .708 0L8 8.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/>
  579. </svg>
  580. </span>
  581. </div>
  582. </div>
  583. <div class="tyc-extend-set control-section-sub">
  584. <div class="tyc-autobigimg-set tyc-extend-set-container">
  585. <div class="tyc-abi-title">
  586. <div>
  587. 自动大图设置模块
  588. </div>
  589. <div>
  590. <button class="tyc-default-rule-show">设置默认规则</button>
  591. </div>
  592. <div>
  593. <button>导出自定规则</button>
  594. </div>
  595. <div>
  596. <input type="file" id="tycfileElem" multiple accept="text/plain" style="display:none">
  597. <button id="tyc-file-select">导入自定规则</button>
  598. </div>
  599. </div>
  600. <div class="tyc-set-domain tyc-set-domain-custom">
  601. </div>
  602. <div class="tyc-set-domain tyc-set-domain-default">
  603. </div>
  604. </div>
  605. </div>
  606. </div>
  607. <div class="tyc-image-wrapper" >
  608. </div>
  609. </div>
  610. `
  611. let showBigImage = `
  612. <div class="show-big-image" style="position:fixed;left:30%;top:30%;z-index:2147483647;">
  613. </div>
  614. `
  615. document.body.insertAdjacentHTML("afterbegin", imgContainer);
  616. autoBigImage.showDefaultRules();
  617. autoBigImage.showRules("tyc-set-domain-custom","userRules","userRulesChecked","tyc-custom-active");
  618. document.body.onclick = (e) => {
  619. //console.log(e);
  620. if ((e.target.nodeName == "IMG" && e.target.className === "tyc-image-preview")) {
  621. let imgContainer = e.path.find(
  622. (ele) => {
  623. try {
  624. //console.log(ele);
  625. return ele.className.includes("tyc-img-item-container");
  626. }
  627. catch {
  628. }
  629. }
  630. )
  631. let path = imgContainer.getElementsByTagName("img")[0].src;
  632. try {
  633. let container = document.querySelector(".show-big-image");
  634. if (container.getElementsByTagName("img")[0].src === path) {
  635. container.remove();
  636. return;
  637. } else {
  638. container.remove();
  639. }
  640. }
  641. catch {
  642. }
  643. document.body.insertAdjacentHTML("beforeend", showBigImage);
  644. let showItem = `<img src="${path}"/>`
  645. document.querySelector(".show-big-image").insertAdjacentHTML("beforeend", showItem);
  646. let tempImg = document.querySelector(".show-big-image img");
  647. let dWidth = (window.innerWidth - tempImg.width) / 2;
  648. let dHeight = (window.innerHeight - tempImg.height) / 2;
  649. document.querySelector(".show-big-image").style.left = dWidth + "px";
  650. document.querySelector(".show-big-image").style.top = dHeight + "px";
  651. } else if (e.target.parentElement.className === "show-big-image") {
  652. try {
  653. document.querySelector(".show-big-image").remove();
  654. }
  655. catch
  656. {
  657. }
  658. } else if (e.target.classList[1] == "bi-download" || e.path.find(isDownload) != undefined) {
  659. let imgContainer = e.path.find(
  660. (ele) => {
  661. try {
  662. //console.log(ele);
  663. return ele.className.includes("tyc-img-item-container");
  664. }
  665. catch {
  666. }
  667. }
  668. )
  669. let path = imgContainer.getElementsByTagName("img")[0].src;
  670. let filename;
  671. if (path.indexOf("/") > 0)//如果包含有"/"号 从最后一个"/"号+1的位置开始截取字符串
  672. {
  673. filename = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
  674. }
  675. else {
  676. filename = path;
  677. }
  678. //console.log("download start" + path + " " + filename);
  679. GM_download(path, "pic");
  680. } else if (e.target.classList[1] == "bi-check" || e.path.find(isSelect) != undefined) {
  681. let checkSvg = e.path.find((ele) => ele.classList[1] === "bi-check");
  682. let currentImgIndex = parseInt(checkSvg.dataset.value);
  683. let container = e.path.find((ele) => ele.className === `tyc-img-item-container-${currentImgIndex}`);
  684. if (imgSelected.includes(currentImgIndex)) {
  685. imgSelected.splice(imgSelected.indexOf(currentImgIndex), 1);
  686. checkSvg.style.color = "black";
  687. container.style.border = "1px solid #99d";
  688. } else {
  689. imgSelected.push(currentImgIndex);
  690. checkSvg.style.color = "white";
  691. container.style.border = "1px solid white";
  692. }
  693. zipImgSelected=imgSelected;
  694. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgSelected.length}/${imgUrls.length}${langSet.fetchDoneTip2}`;
  695. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  696. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  697. zipImgWaitDownload=cutoffNotBase64Img(zipImgWaitDownload);
  698. }
  699. }
  700. document.querySelector(".btn-close").onclick = (e) => {
  701. document.querySelector(".tyc-image-container").remove();
  702. }
  703. document.querySelector(".btn-download").onclick = (e) => {
  704. if (imgWaitDownload.length >= 1) {
  705. //console.log(imgWaitDownload);
  706. imgWaitDownload.forEach(async (img, index) => {
  707. //let filename = `pic-${index}.jpg`;
  708. //filename=filename.replace(/\\/g, '/').replace(/\/{2,}/g, '/');
  709. await GM_download(img, `pic-${index}`);
  710. });
  711. } else {
  712. alert(`${langSet.selectAlert}`);
  713. }
  714. }
  715. document.querySelector(".btn-zipDownload").onclick = (e) => {
  716. //console.log(zipImgWaitDownload);
  717. try {
  718. if (zipImgWaitDownload.length >= 1) {
  719. //console.log(zipImgWaitDownload);
  720. zipImgWaitDownload.forEach(async (img, index) => {
  721. let fileExt = img.substring(img.indexOf("image/") + 6, img.indexOf(";"))
  722. fileExt=fileExt.includes("svg")?"svg":fileExt;
  723. let filename = `pic${index}.${fileExt}`;
  724. zipSubFoler.file(filename, img.split(",")[1], { base64: true });
  725. });
  726. zipFolder.generateAsync({ type: "blob" })
  727. .then(function (content) {
  728. // see FileSaver.js
  729. saveAs(content, "pics.zip");
  730. zipFolder.remove("pics");
  731. zipSubFoler = zipFolder.folder('pics');
  732. });
  733. } else {
  734. alert(`${langSet.selectAlert}`);
  735. }
  736. } catch (error) {
  737. //console.log(error);
  738. }
  739.  
  740. }
  741. document.querySelector(".tyc-cors").onmouseover=e=>{
  742. e.preventDefault();
  743. document.querySelector(".tyc-tip").style.display="block";
  744. }
  745. document.querySelector(".tyc-cors").onmouseout=e=>{
  746. e.preventDefault();
  747. document.querySelector(".tyc-tip").style.display="none";
  748. }
  749. document.body.onchange = (e) => {
  750. if (e.target.className.includes("width-check")) {
  751. GM_setValue('width-check', e.target.checked);
  752. }
  753. if (e.target.className.includes("height-check")) {
  754. GM_setValue('height-check', e.target.checked);
  755. }
  756. if (e.target.className.includes("cors-check")) {
  757. GM_setValue('cors-check', e.target.checked);
  758. if (document.querySelector(".cors-check").checked) {
  759. fetchBase64ImgsThenPushToZipArray();
  760. }
  761. }
  762.  
  763. if(e.target.className.includes("tyc-default-active")){
  764. autoBigImage.oncheckChange();
  765. }
  766.  
  767. if(e.target.className.includes("tyc-custom-active")){
  768. autoBigImage.oncheckChangeCustom();
  769. }
  770. if (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")) {
  771. GM_setValue(e.target.className, e.target.value);
  772. }
  773. (e.target.className.includes("width-check") || e.target.className.includes("height-check") ||
  774. (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")))
  775. && (clean(), init());
  776. }
  777. document.querySelector(".select-all").onchange = (e) => {
  778. if (document.querySelector(".select-all").checked) {
  779. imgWaitDownload = filteredImgUrls;
  780. zipImgWaitDownload=cutoffNotBase64Img(zipFilteredImgUrls);
  781. } else {
  782. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  783. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  784. }
  785. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgWaitDownload.length}/${filteredImgUrls.length}${langSet.fetchDoneTip2}`;
  786. }
  787.  
  788. document.querySelector(".tyc-extend-btn").onclick=e=>{
  789. if(document.querySelector(".tyc-extend-btn").classList.contains("extend-open")){
  790. document.querySelector(".tyc-extend-btn").classList.remove("extend-open");
  791. document.querySelector(".tyc-extend-set").style.display="none";
  792. document.querySelector(".tyc-extend-btn").style.color="black";
  793. document.querySelector(".tyc-extend-btn").innerHTML=`<span>更多设置 </span>
  794. <span style="top: 3px;position: relative;">
  795. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-double-down" viewBox="0 0 16 16">
  796. <path fill-rule="evenodd" d="M1.646 6.646a.5.5 0 0 1 .708 0L8 12.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/>
  797. <path fill-rule="evenodd" d="M1.646 2.646a.5.5 0 0 1 .708 0L8 8.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/>
  798. </svg>
  799. </span> `
  800. ;
  801. }else{
  802. document.querySelector(".tyc-extend-btn").classList.add("extend-open");
  803. document.querySelector(".tyc-extend-set").style.display="flex";
  804. document.querySelector(".tyc-extend-btn").style.color="#f50";
  805. document.querySelector(".tyc-extend-btn").innerHTML=`<span>收起 </span>
  806. <span style="top: 3px;position: relative;">
  807. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-double-up" viewBox="0 0 16 16">
  808. <path fill-rule="evenodd" d="M7.646 2.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1-.708.708L8 3.707 2.354 9.354a.5.5 0 1 1-.708-.708l6-6z"/>
  809. <path fill-rule="evenodd" d="M7.646 6.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1-.708.708L8 7.707l-5.646 5.647a.5.5 0 0 1-.708-.708l6-6z"/>
  810. </svg>
  811. </span> `
  812. }
  813. }
  814.  
  815. document.querySelector(".tyc-default-rule-show").onclick=autoBigImage.onclickShowDefaultBtn;
  816.  
  817. document.querySelector("#tyc-file-select").onclick=e=>{
  818. document.querySelector("#tycfileElem").click();
  819. }
  820.  
  821. document.querySelector("#tycfileElem").onchange=autoBigImage.getCustomRules;
  822.  
  823. init();
  824. function init() {
  825. filteredImgUrls = imgUrls;
  826. filteredImgUrls=autoBigImage.getBigImageArray(filteredImgUrls);
  827. getSavedValue();
  828. if (document.querySelector(".width-check").checked) {
  829. filteredImgUrls = filteredImgUrls.filter(filterByWidth);
  830. }
  831. if (document.querySelector(".height-check").checked) {
  832. filteredImgUrls = filteredImgUrls.filter(filterByHeight);
  833. }
  834. zipFilteredImgUrls = filteredImgUrls;
  835. if (document.querySelector(".cors-check").checked) {
  836. fetchBase64ImgsThenPushToZipArray();
  837. }
  838. showImage(filteredImgUrls);
  839. }
  840. function clean() {
  841. imgWaitDownload = [];
  842. imgSelected = [];
  843. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgSelected.length}/${imgUrls.length}${langSet.fetchDoneTip2}`;
  844. document.querySelector(".tyc-image-wrapper").innerHTML = "";
  845. }
  846. function isDownload(ele) {
  847. return ele.className == "download-direct";
  848. }
  849. function isSelect(ele) {
  850. return ele.className == "select-image";
  851. }
  852. function transIndexToLink(WholeImgs,selectedImgs) {
  853. let transedImgs=[];
  854. selectedImgs.forEach((imgIndex, index) => {
  855. transedImgs.push(WholeImgs[imgIndex]);
  856. });
  857. return transedImgs;
  858. }
  859. function showImage(filtedImgUrls) {
  860. filtedImgUrls.forEach((img, index) => {
  861. if (window.location.href.includes("huaban.com")) {
  862. if (img.includes("/webp")) {
  863. img = img.replace(/\/webp/g, "/png");
  864. }
  865. }
  866. let insertImg = `<div class="tyc-img-item-container-${index}" style="text-align:center;font-size:0px;
  867. margin:5px;border:1px solid #99d;border-radius:3px;
  868. ">
  869. <img class="tyc-image-preview" src="${img}"/ style="width:auto;height:200px;"></div>`
  870. document.querySelector(".tyc-image-wrapper").insertAdjacentHTML("beforeend", insertImg);
  871. let naturalW = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalWidth;
  872. let naturalH = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalHeight;
  873. let imgInfoContainer = `
  874. <div style="font-size:0px;background-color:rgba(100,100,100,0.6);height:30px;position:relative;">
  875. </div>
  876. `;
  877. let thisImgContainer = document.querySelector(`.tyc-img-item-container-${index}`);
  878. let imgContainerWidth = thisImgContainer.getBoundingClientRect().width;
  879. let imgInfo = `
  880. <span style="font-size:16px;position:absolute;left:calc(50% - 80px);top:7px;">${naturalW}X${naturalH}</span>
  881. `;
  882. /*
  883. <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;">
  884. <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"/>
  885. </svg>*/
  886. let downAndFullBtn = `
  887. <span style="position:absolute;right:calc(50% - 30px);top:2px;border:1px solid #333;
  888. width:26px;height:26px;border-radius:20px;" class="select-image" data-value="${index}">
  889. <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}">
  890. <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"/>
  891. </svg>
  892. </span>
  893. <span style="position:absolute;right:calc(50% - 60px);top:2px;border:1px solid #333;
  894. width:26px;height:26px;border-radius:20px;
  895. " class="download-direct">
  896. <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;">
  897. <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"/>
  898. <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"/>
  899. </svg>
  900. </span>
  901. `;
  902. let downloadBtn = `
  903. <span style="position:absolute;right:calc(50% - 15px);top:2px;border:1px solid #333;
  904. width:26px;height:26px;border-radius:20px;
  905. " class="download-direct">
  906. <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;">
  907. <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"/>
  908. <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"/>
  909. </svg>
  910. </span>
  911. `
  912. thisImgContainer.insertAdjacentHTML("beforeend", imgInfoContainer);
  913. let thisImgInfoContainer = thisImgContainer.querySelector("div");
  914. let rectWidth = parseInt(thisImgContainer.getBoundingClientRect().width);
  915. if (rectWidth > 120) {
  916. thisImgInfoContainer.insertAdjacentHTML("beforeend", imgInfo);
  917. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  918. } else if (rectWidth <= 120 && rectWidth >= 50) {
  919. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  920. thisImgInfoContainer.getElementsByClassName("select-image")[0].style.right = "50%";
  921. thisImgInfoContainer.getElementsByClassName("download-direct")[0].style.right = "calc(50% - 30px)";
  922. } else {
  923. thisImgInfoContainer.insertAdjacentHTML("beforeend", downloadBtn);
  924. }
  925. ////console.log(img);
  926. });
  927. }
  928. function filterByWidth(src) {
  929. let tempImg = new Image();
  930. tempImg.src = src;
  931. if (tempImg.width >= parseInt(document.querySelector(".width-value-min").value)
  932. && tempImg.width <= parseInt(document.querySelector(".width-value-max").value)) {
  933. return src;
  934. }
  935. }
  936. function filterByHeight(src) {
  937. let tempImg = new Image();
  938. tempImg.src = src;
  939. if (tempImg.height >= parseInt(document.querySelector(".height-value-min").value)
  940. && tempImg.height <= parseInt(document.querySelector(".height-value-max").value)) {
  941. return src;
  942. }
  943. }
  944. function getSavedValue() {
  945. if(GM_getValue("width-check")!=undefined){
  946. //console.log(GM_getValue("width-check"));
  947. (document.querySelector(".width-check").checked = GM_getValue("width-check"));
  948. }
  949. if(GM_getValue("height-check")!=undefined){
  950. (document.querySelector(".height-check").checked = GM_getValue("height-check"));
  951. }
  952. if(GM_getValue("cors-check")!=undefined){
  953. (document.querySelector(".cors-check").checked = GM_getValue("cors-check"));
  954. }
  955. GM_getValue("width-value-min") && (document.querySelector(".width-value-min").value = GM_getValue("width-value-min"));
  956. GM_getValue("width-value-max") && (document.querySelector(".width-value-max").value = GM_getValue("width-value-max"));
  957. GM_getValue("height-value-min") && (document.querySelector(".height-value-min").value = GM_getValue("height-value-min"));
  958. GM_getValue("height-value-max") && (document.querySelector(".height-value-max").value = GM_getValue("height-value-max"));
  959. }
  960. function fetchBase64ImgsThenPushToZipArray() {
  961. zipFilteredImgUrls.forEach((imgUrl, urlIndex) => {
  962. if (imgUrl.includes("data:image")) {
  963. return;
  964. }
  965. /* fetch(imgUrl,{
  966. method: "get",
  967. mode: 'cors'
  968. }).then(response=>{
  969. if (!response.ok) {
  970. throw new Error('Network response was not OK');
  971. }
  972. return response.blob();
  973. }).then(myBlob=>{
  974. var blob = myBlob
  975. let oFileReader = new FileReader();
  976. oFileReader.onloadend = function (e) {
  977. let base64 = e.target.result;
  978. //console.log("》》", base64)
  979. if (base64.includes("data:image")) {
  980. zipFilteredImgUrls[urlIndex] = base64;
  981. //zipImgWaitDownload.push(base64);
  982. }
  983. };
  984. oFileReader.readAsDataURL(blob);
  985. })
  986. .catch((error)=>{ */
  987. try {
  988. GM_xmlhttpRequest({
  989. method: "get",
  990. url: imgUrl,
  991. responseType: "blob",
  992. onload: function (r) {
  993. var blob = r.response;
  994. let oFileReader = new FileReader();
  995. oFileReader.onloadend = function (e) {
  996. let base64 = e.target.result;
  997. if (base64.startsWith("data:image")) {
  998. zipFilteredImgUrls[urlIndex] = base64;
  999. //zipImgWaitDownload.push(base64);
  1000. }
  1001. };
  1002. oFileReader.readAsDataURL(blob);
  1003. }
  1004. });
  1005. } catch (error) {
  1006. }
  1007.  
  1008. //})
  1009. })
  1010. }
  1011. function cutoffNotBase64Img(imgsUrlArray) {
  1012. let resultArr = [];
  1013. imgsUrlArray.forEach((imgUrl, urlIndex) => {
  1014. if (imgUrl.startsWith("data:image")&&imgUrl.includes("base64")) {
  1015. resultArr.push(imgUrl);
  1016. }
  1017. }
  1018. );
  1019. return resultArr;
  1020. }
  1021. //下面这个括号是wrapper的括号
  1022. }
  1023. })();