图片下载器

可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,右键失效或者图片不能另存的网站,用脚本均可以提取并下载。额外功能:zip下载/自动大图。详细见脚本描述(目前只适合chrome+tampermonkey,其他组合多少有问题)

当前为 2022-02-13 提交的版本,查看 最新版本

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