图片下载器

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

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

  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.98
  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://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. }
  273. GM_registerMenuCommand(langSet.downloadMenuText, wrapper);
  274. hotkeys('alt+w', wrapper);
  275. function wrapper() {
  276. try {
  277. document.querySelector(".tyc-image-container").remove();
  278. } catch {
  279. }
  280. var imgUrls = [];
  281. var bodyStr = document.body.innerHTML;
  282. var imgSelected = [];
  283. var zipImgSelected = [];
  284. var imgWaitDownload = [];
  285. var zipImgWaitDownload = [];
  286. var widthFilter = { min: 0, max: 3000 };
  287. var heightFilter = { min: 0, max: 3000 };
  288. var filteredImgUrls = [];
  289. var zipFilteredImgUrls = [];
  290. try{
  291. var zipFolder = new JSZip();
  292. var zipSubFoler = zipFolder.folder('pics');
  293. }
  294. catch{
  295. }
  296. var fetchTip='';
  297. try {
  298. let imgEles = document.getElementsByTagName("img");
  299. let canvasEles=document.getElementsByTagName("canvas");
  300. for (let i = 0; i < imgEles.length; i++) {
  301. ////console.log(imgEles[i].src);
  302. if (!imgUrls.includes(imgEles[i].src)) {
  303. imgUrls.push(imgEles[i].src);
  304. } else if (!imgUrls.includes(imgEles[i].srcset)) {
  305. imgUrls.push(imgEles[i].srcset);
  306. }
  307. }
  308. let imgRegs = bodyStr.match(/(?<=background-image:\s*url\()(\S+)(?=\))/g);
  309. for (let i = 0; i < imgRegs.length; i++) {
  310. ////console.log(imgRegs[i]);
  311. if (!imgUrls.includes(imgRegs[i].replace(/&quot;/g, ""))) {
  312. imgUrls.push(imgRegs[i].replace(/&quot;/g, ""));
  313. }
  314. }
  315. if (window.location.href.includes("hathitrust.org")) {
  316. let imgs = document.querySelectorAll(".image img");
  317. if (imgs.length > 0) {
  318. let canvas = document.createElement("canvas");
  319. imgUrls = [];
  320. for (let pi = 0; pi < imgs.length; pi++) {
  321. canvas.width = imgs[pi].width;
  322. canvas.height = imgs[pi].height;
  323. canvas.getContext("2d").drawImage(imgs[pi], 0, 0);
  324. imgUrls.push(canvas.toDataURL("image/png"));
  325. }
  326. document.querySelector(".select-all").style = "position:relative;width:15px;height:15px;"
  327. } else {
  328. }
  329. }
  330. if(window.location.href.toString().includes("manga.bilibili.com/")){
  331. let iframeCanvas=`<iframe style="display:none;" id="tyc-insert-iframe"></iframe>`;
  332. if(document.getElementById("tyc-insert-iframe")==null){
  333. document.body.insertAdjacentHTML("afterbegin",iframeCanvas);
  334. document.getElementById("tyc-insert-iframe").contentDocument.body.insertAdjacentHTML("afterbegin",`<canvas id="tyc-insert-canvas"></canvas>`);
  335. document.body.getElementsByTagName('canvas')[0].__proto__.toBlob=document.getElementById("tyc-insert-iframe").contentDocument.getElementById("tyc-insert-canvas").__proto__.toBlob;
  336. }
  337. }
  338. let oldLength=imgUrls.length;
  339. if(canvasEles.length>0){
  340. fetchTip=langSet.fetchTip;
  341. var completeFlag=0;
  342. for(let j=0;j<canvasEles.length;j++){
  343. canvasEles[j].toBlob(blobCallback);
  344. function blobCallback(blob){
  345. let oFileReader = new FileReader();
  346. oFileReader.onloadend = function (e) {
  347. let base64 = e.target.result;
  348. if (base64.includes("data:image")) {
  349. if (!imgUrls.includes(base64)) {
  350. //imgUrls.push(base64);
  351. imgUrls[oldLength+j]=base64;
  352. }
  353. completeFlag++;
  354. document.querySelector(".num-tip").innerText=`${langSet.fetchCount1} ${completeFlag}/${canvasEles.length} ${langSet.fetchCount2}`;
  355. if(completeFlag===canvasEles.length){
  356. clean();
  357. init();
  358. }
  359. }
  360. };
  361. oFileReader.readAsDataURL(blob);
  362. }
  363. }
  364. }else{
  365. fetchTip=`${langSet.fetchDoneTip1}${imgUrls.length}${langSet.fetchDoneTip2}`;
  366. }
  367. } catch {
  368. //alert("error");
  369. }
  370. let imgContainer = `<style>
  371. .tyc-image-container{
  372. position:fixed;
  373. top:0px;
  374. left:10%;
  375. width:80vw;
  376. z-index:2147483645;
  377. background-color: #dedede;
  378. border: 1px solid #aaa;
  379. overflow:scroll;height:100%;
  380. }
  381. .tyc-image-container button{
  382. border:1px solid #aaa;
  383. border-radius:5px;
  384. height:32px;line-height:32px;
  385. margin:0px;padding:0 5px;
  386. }
  387. .tyc-image-container button:hover{
  388. background-color: #f50;
  389. color: #fff;
  390. }
  391. .control-section{
  392. width:80vw;
  393. z-index:2147483646;
  394. position:fixed;
  395. top:0px;
  396. left:10%;
  397. display: flex;
  398. flex-direction: column;
  399. justify-content: center;
  400. line-height:40px;
  401. background:#eee;border:1px solid #aaa;border-radius:2px;
  402. }
  403. .control-section-sub{
  404. display: flex;
  405. margin-bottom: 5px;
  406. }
  407. .tyc-normal-section{
  408. display: flex;
  409. align-items: center;
  410. flex-direction: row;
  411. justify-content: flex-start;
  412. flex-wrap: nowrap;
  413. align-content: normal;
  414. }
  415. .btn-download{
  416. border:1px solid #aaa;border-radius:5px;
  417. height:32px;line-height:32px;
  418. margin:0px;padding:0 5px;
  419. }
  420. .btn-zipDownload{
  421. border:1px solid #aaa;border-radius:5px;
  422. height:32px;line-height:32px;
  423. margin:0px;padding:0 5px;
  424. }
  425. .btn-close{
  426. font-size:20px;position:absolute;
  427. right:30px;top:4px;
  428. height:32px;line-height:32px;
  429. margin:0px;
  430. border-radius:10px;border:1px solid #aaa;
  431. width:30px;
  432. }
  433. .tyc-image-wrapper{
  434. margin-top:82px;display:flex;justify-content:center;
  435. align-items:center;flex-wrap:wrap;
  436. }
  437. .tyc-input-checkbox{
  438. background-color: initial;
  439. cursor: default;
  440. appearance: auto;
  441. box-sizing: border-box;
  442. margin: 3px 3px 3px 4px;
  443. padding: initial;
  444. border: initial;
  445. }
  446. .tyc-extend-set{
  447. padding: 10px;
  448. border-top: 1px solid rgba(100,100,100,0.1);
  449. }
  450. .tyc-extend-set{
  451. display: none;
  452. align-items: stretch;
  453. flex-direction: column;
  454. justify-content: flex-start;
  455. flex-wrap: nowrap;
  456. padding: 5px;
  457. width: auto;
  458. }
  459. .tyc-extend-set-container{
  460. display: flex;
  461. align-items: flex-start;
  462. flex-direction: column;
  463. justify-content: flex-start;
  464. flex-wrap: nowrap;
  465. align-content: normal;
  466. border: 1px solid rgba(100,100,100,0.5);
  467. padding: 5px;
  468. margin-bottom: 5px;
  469. }
  470. .tyc-autobigimg-set{
  471. display: flex;
  472. align-items: flex-start;
  473. flex-direction: column;
  474. justify-content: flex-start;
  475. flex-wrap: nowrap;
  476. align-content: normal;
  477. border: 1px solid rgba(100,100,100,0.5);
  478. padding: 5px;
  479. }
  480. .tyc-set-domain{
  481. display: flex;
  482. align-items: flex-start;
  483. flex-direction: column;
  484. justify-content: flex-start;
  485. flex-wrap: nowrap;
  486. align-content: normal;
  487. margin: 5px;
  488. padding: 5px;
  489. border: 1px solid rgba(100,100,100,0.3);
  490. width: 95%;
  491. max-height: 150px;
  492. overflow: scroll;
  493. }
  494. .tyc-abi-title{
  495. display: flex;
  496. flex-direction: row;
  497. align-items: center;
  498. justify-content: space-around;
  499. width: 100%;
  500. }
  501. .tyc-abi-domain-title{
  502. display: flex;
  503. flex-direction: row;
  504. align-items: center;
  505. justify-content: space-between;
  506. width: 95%;
  507. border-bottom: 1px solid #ddd;
  508. }
  509. .tyc-set-replacerule{
  510. display: flex;
  511. flex-direction: row;
  512. justify-content: flex-start;
  513. align-items: center;
  514. margin-bottom: 3px;
  515. flex-wrap: wrap;
  516. }
  517. .tyc-set-replacerule *,.tyc-set-replacerule button{
  518. margin-left: 5px;
  519. }
  520. .tyc-set-domain-default{
  521. height: 200px;
  522. overflow: scroll;
  523. display: none;
  524. }
  525. </style>
  526. <div class="tyc-image-container">
  527. <div class="control-section">
  528. <div class="control-section-sub tyc-normal-section">
  529. <input class="select-all tyc-input-checkbox" type="checkbox" name="select-all" value="select-all">${langSet.selectAll}
  530. <button class="btn-download" style="margin-left:5px;">${langSet.downloadBtn}</button>
  531. <button class="btn-zipDownload" style="margin-left:5px;">${langSet.zipDownloadBtn}</button>
  532. <span style="margin-left:10px;" class="num-tip">${langSet.fetchDoneTip1}${imgUrls.length}${langSet.fetchDoneTip2}</span>
  533. <button cstyle="margin-left:10px;" class="btn-close" >X</button>
  534. </div>
  535. <div style="line-height:12px;" class="control-section-sub tyc-normal-section">
  536. <div style="float:left;display:block;">
  537. <input type="checkbox" class="width-check img-check tyc-input-checkbox" name="width-check" value="width-check">Width:
  538. <input type="text" class="width-value-min" size="1" style="height:15px;width:50px;"
  539. min="0" max="9999" value="0">-
  540. <input type="text" class="width-value-max" size="1" style="height:15px;width:50px;"
  541. min="0" max="9999" value="3000">
  542. </div>
  543. <div style="float:left;margin-left:30px;display:block;">
  544. <input type="checkbox" class="height-check img-check tyc-input-checkbox" name="height-check" value="height-check">Height:
  545. <input type="text" class="height-value-min" size="1" style="height:15px;width:50px;"
  546. min="0" max="9999" value="0">-
  547. <input type="text" class="height-value-max" size="1" style="height:15px;width:50px;"
  548. min="0" max="9999" value="3000">
  549. </div>
  550. <div style="float:left;margin-left:30px;display:block;" class="tyc-cors">
  551. <span class="tyc-tip" style="display: none;
  552. position: absolute;
  553. top: 5px;
  554. left: 50px;
  555. white-space: nowrap;
  556. background: rgb(204, 204, 204);
  557. border: 1px solid rgb(150, 150, 150);
  558. border-radius: 3px;
  559. padding: 5px;">勾选使用zip下载后,会请求跨域权限,否则zip下载基本下载不到图片。
  560. </span>
  561. <input type="checkbox" class="cors-check img-check tyc-input-checkbox" name="cors-check" value="cors-check">
  562. <span>使用zip下载</span>
  563. </div>
  564. <div style="float:left;margin-left:30px;display:block;" class="tyc-download-url">
  565. <button class="tyc-download-url-btn">下载地址文件</button>
  566. </div>
  567. <div style="float:left;margin-left:30px;display:block;" class="tyc-extend-btn">
  568. <span>更多设置 </span>
  569. <span style="top: 3px;position: relative;">
  570. <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">
  571. <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"/>
  572. <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"/>
  573. </svg>
  574. </span>
  575. </div>
  576. </div>
  577. <div class="tyc-extend-set control-section-sub">
  578. <div class="tyc-autobigimg-set tyc-extend-set-container">
  579. <div class="tyc-abi-title">
  580. <div>
  581. 自动大图设置模块
  582. </div>
  583. <div>
  584. <button class="tyc-default-rule-show">设置默认规则</button>
  585. </div>
  586.  
  587. <div>
  588. <button>导出自定规则</button>
  589. </div>
  590.  
  591. <div>
  592. <input type="file" id="tycfileElem" multiple accept="text/plain" style="display:none">
  593. <button id="tyc-file-select">导入自定规则</button>
  594. </div>
  595. </div>
  596. <div class="tyc-set-domain tyc-set-domain-custom">
  597. </div>
  598. <div class="tyc-set-domain tyc-set-domain-default">
  599. </div>
  600. </div>
  601. </div>
  602. </div>
  603. <div class="tyc-image-wrapper" >
  604. </div>
  605. </div>`
  606. let showBigImage = `
  607. <div class="show-big-image" style="position:fixed;left:30%;top:30%;z-index:2147483647;">
  608. </div>
  609. `
  610. document.body.insertAdjacentHTML("afterbegin", imgContainer);
  611. autoBigImage.showDefaultRules();
  612. autoBigImage.showRules("tyc-set-domain-custom","userRules","userRulesChecked","tyc-custom-active");
  613. document.body.onclick = (e) => {
  614. //console.log(e);
  615. if ((e.target.nodeName == "IMG" && e.target.className === "tyc-image-preview")) {
  616. let imgContainer = e.path.find(
  617. (ele) => {
  618. try {
  619. //console.log(ele);
  620. return ele.className.includes("tyc-img-item-container");
  621. }
  622. catch {
  623. }
  624. }
  625. )
  626. let path = imgContainer.getElementsByTagName("img")[0].src;
  627. try {
  628. let container = document.querySelector(".show-big-image");
  629. if (container.getElementsByTagName("img")[0].src === path) {
  630. container.remove();
  631. return;
  632. } else {
  633. container.remove();
  634. }
  635. }
  636. catch {
  637. }
  638. document.body.insertAdjacentHTML("beforeend", showBigImage);
  639. let showItem = `<img src="${path}"/>`
  640. document.querySelector(".show-big-image").insertAdjacentHTML("beforeend", showItem);
  641. let tempImg = document.querySelector(".show-big-image img");
  642. let dWidth = (window.innerWidth - tempImg.width) / 2;
  643. let dHeight = (window.innerHeight - tempImg.height) / 2;
  644. document.querySelector(".show-big-image").style.left = dWidth + "px";
  645. document.querySelector(".show-big-image").style.top = dHeight + "px";
  646. } else if (e.target.parentElement.className === "show-big-image") {
  647. try {
  648. document.querySelector(".show-big-image").remove();
  649. }
  650. catch
  651. {
  652. }
  653. } else if (e.target.classList[1] == "bi-download" || e.path.find(isDownload) != undefined) {
  654. let imgContainer = e.path.find(
  655. (ele) => {
  656. try {
  657. //console.log(ele);
  658. return ele.className.includes("tyc-img-item-container");
  659. }
  660. catch {
  661. }
  662. }
  663. )
  664. let path = imgContainer.getElementsByTagName("img")[0].src;
  665. let filename;
  666. if (path.indexOf("/") > 0)//如果包含有"/"号 从最后一个"/"号+1的位置开始截取字符串
  667. {
  668. filename = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
  669. }
  670. else {
  671. filename = path;
  672. }
  673. //console.log("download start" + path + " " + filename);
  674. GM_download(path, "pic");
  675. } else if (e.target.classList[1] == "bi-check" || e.path.find(isSelect) != undefined) {
  676. let checkSvg = e.path.find((ele) => ele.classList[1] === "bi-check");
  677. let currentImgIndex = parseInt(checkSvg.dataset.value);
  678. let container = e.path.find((ele) => ele.className === `tyc-img-item-container-${currentImgIndex}`);
  679. if (imgSelected.includes(currentImgIndex)) {
  680. imgSelected.splice(imgSelected.indexOf(currentImgIndex), 1);
  681. checkSvg.style.color = "black";
  682. container.style.border = "1px solid #99d";
  683. } else {
  684. imgSelected.push(currentImgIndex);
  685. checkSvg.style.color = "white";
  686. container.style.border = "1px solid white";
  687. }
  688. zipImgSelected=imgSelected;
  689. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgSelected.length}/${imgUrls.length}${langSet.fetchDoneTip2}`;
  690. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  691. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  692. zipImgWaitDownload=cutoffNotBase64Img(zipImgWaitDownload);
  693. }
  694. }
  695. document.querySelector(".btn-close").onclick = (e) => {
  696. document.querySelector(".tyc-image-container").remove();
  697. }
  698. document.querySelector(".btn-download").onclick = (e) => {
  699. if (imgWaitDownload.length >= 1) {
  700. //console.log(imgWaitDownload);
  701. imgWaitDownload.forEach(async (img, index) => {
  702. //let filename = `pic-${index}.jpg`;
  703. //filename=filename.replace(/\\/g, '/').replace(/\/{2,}/g, '/');
  704. await GM_download(img, `pic-${index}`);
  705. });
  706. } else {
  707. alert(`${langSet.selectAlert}`);
  708. }
  709. }
  710. document.querySelector(".btn-zipDownload").onclick = (e) => {
  711. //console.log(zipImgWaitDownload);
  712. try {
  713. if (zipImgWaitDownload.length >= 1) {
  714. //console.log(zipImgWaitDownload);
  715. zipImgWaitDownload.forEach(async (img, index) => {
  716. let fileExt = img.substring(img.indexOf("image/") + 6, img.indexOf(";"))
  717. fileExt=fileExt.includes("svg")?"svg":fileExt;
  718. let filename = `pic${index}.${fileExt}`;
  719. zipSubFoler.file(filename, img.split(",")[1], { base64: true });
  720. });
  721. zipFolder.generateAsync({ type: "blob" })
  722. .then(function (content) {
  723. // see FileSaver.js
  724. saveAs(content, "pics.zip");
  725. zipFolder.remove("pics");
  726. zipSubFoler = zipFolder.folder('pics');
  727. });
  728. } else {
  729. alert(`${langSet.selectAlert}`);
  730. }
  731. } catch (error) {
  732. //console.log(error);
  733. }
  734. }
  735. document.querySelector(".tyc-cors").onmouseover=e=>{
  736. e.preventDefault();
  737. document.querySelector(".tyc-tip").style.display="block";
  738. }
  739. document.querySelector(".tyc-cors").onmouseout=e=>{
  740. e.preventDefault();
  741. document.querySelector(".tyc-tip").style.display="none";
  742. }
  743. document.body.onchange = (e) => {
  744. if (e.target.className.includes("width-check")) {
  745. GM_setValue('width-check', e.target.checked);
  746. }
  747. if (e.target.className.includes("height-check")) {
  748. GM_setValue('height-check', e.target.checked);
  749. }
  750. if (e.target.className.includes("cors-check")) {
  751. GM_setValue('cors-check', e.target.checked);
  752. if (document.querySelector(".cors-check").checked) {
  753. fetchBase64ImgsThenPushToZipArray();
  754. }
  755. }
  756. if(e.target.className.includes("tyc-default-active")){
  757. autoBigImage.oncheckChange();
  758. }
  759. if(e.target.className.includes("tyc-custom-active")){
  760. autoBigImage.oncheckChangeCustom();
  761. }
  762. if (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")) {
  763. GM_setValue(e.target.className, e.target.value);
  764. }
  765. (e.target.className.includes("width-check") || e.target.className.includes("height-check") ||
  766. (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")))
  767. && (clean(), init());
  768. }
  769. document.querySelector(".select-all").onchange = (e) => {
  770. if (document.querySelector(".select-all").checked) {
  771. imgWaitDownload = filteredImgUrls;
  772. zipImgWaitDownload=cutoffNotBase64Img(zipFilteredImgUrls);
  773. } else {
  774. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  775. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  776. }
  777. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgWaitDownload.length}/${filteredImgUrls.length}${langSet.fetchDoneTip2}`;
  778. }
  779. document.querySelector(".tyc-extend-btn").onclick=e=>{
  780. if(document.querySelector(".tyc-extend-btn").classList.contains("extend-open")){
  781. document.querySelector(".tyc-extend-btn").classList.remove("extend-open");
  782. document.querySelector(".tyc-extend-set").style.display="none";
  783. document.querySelector(".tyc-extend-btn").style.color="black";
  784. document.querySelector(".tyc-extend-btn").innerHTML=`<span>更多设置 </span>
  785. <span style="top: 3px;position: relative;">
  786. <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">
  787. <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"/>
  788. <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"/>
  789. </svg>
  790. </span> `
  791. ;
  792. }else{
  793. document.querySelector(".tyc-extend-btn").classList.add("extend-open");
  794. document.querySelector(".tyc-extend-set").style.display="flex";
  795. document.querySelector(".tyc-extend-btn").style.color="#f50";
  796. document.querySelector(".tyc-extend-btn").innerHTML=`<span>收起 </span>
  797. <span style="top: 3px;position: relative;">
  798. <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">
  799. <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"/>
  800. <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"/>
  801. </svg>
  802. </span> `
  803. }
  804. }
  805. document.querySelector(".tyc-default-rule-show").onclick=autoBigImage.onclickShowDefaultBtn;
  806. document.querySelector("#tyc-file-select").onclick=e=>{
  807. document.querySelector("#tycfileElem").click();
  808. }
  809. document.querySelector("#tycfileElem").onchange=autoBigImage.getCustomRules;
  810.  
  811. document.querySelector(".tyc-download-url-btn").onclick=e=>{
  812. let blob=new Blob([imgUrls.join("\n")],{ type: "text/plain", endings: "native" });
  813. saveAs(blob,"urls.txt");
  814. }
  815. init();
  816. function init() {
  817. filteredImgUrls = imgUrls;
  818. filteredImgUrls=autoBigImage.getBigImageArray(filteredImgUrls);
  819. getSavedValue();
  820. if (document.querySelector(".width-check").checked) {
  821. filteredImgUrls = filteredImgUrls.filter(filterByWidth);
  822. }
  823. if (document.querySelector(".height-check").checked) {
  824. filteredImgUrls = filteredImgUrls.filter(filterByHeight);
  825. }
  826. zipFilteredImgUrls = filteredImgUrls;
  827. if (document.querySelector(".cors-check").checked) {
  828. fetchBase64ImgsThenPushToZipArray();
  829. }
  830. showImage(filteredImgUrls);
  831. }
  832. function clean() {
  833. imgWaitDownload = [];
  834. imgSelected = [];
  835. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgSelected.length}/${imgUrls.length}${langSet.fetchDoneTip2}`;
  836. document.querySelector(".tyc-image-wrapper").innerHTML = "";
  837. }
  838. function isDownload(ele) {
  839. return ele.className == "download-direct";
  840. }
  841. function isSelect(ele) {
  842. return ele.className == "select-image";
  843. }
  844. function transIndexToLink(WholeImgs,selectedImgs) {
  845. let transedImgs=[];
  846. selectedImgs.forEach((imgIndex, index) => {
  847. transedImgs.push(WholeImgs[imgIndex]);
  848. });
  849. return transedImgs;
  850. }
  851. function showImage(filtedImgUrls) {
  852. filtedImgUrls.forEach((img, index) => {
  853. if (window.location.href.includes("huaban.com")) {
  854. if (img.includes("/webp")) {
  855. img = img.replace(/\/webp/g, "/png");
  856. }
  857. }
  858. let insertImg = `<div class="tyc-img-item-container-${index}" style="text-align:center;font-size:0px;
  859. margin:5px;border:1px solid #99d;border-radius:3px;
  860. ">
  861. <img class="tyc-image-preview" src="${img}"/ style="width:auto;height:200px;"></div>`
  862. document.querySelector(".tyc-image-wrapper").insertAdjacentHTML("beforeend", insertImg);
  863. let naturalW = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalWidth;
  864. let naturalH = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalHeight;
  865. let imgInfoContainer = `
  866. <div style="font-size:0px;background-color:rgba(100,100,100,0.6);height:30px;position:relative;">
  867. </div>
  868. `;
  869. let thisImgContainer = document.querySelector(`.tyc-img-item-container-${index}`);
  870. let imgContainerWidth = thisImgContainer.getBoundingClientRect().width;
  871. let imgInfo = `
  872. <span style="font-size:16px;position:absolute;left:calc(50% - 80px);top:7px;">${naturalW}X${naturalH}</span>
  873. `;
  874. /*
  875. <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;">
  876. <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"/>
  877. </svg>*/
  878. let downAndFullBtn = `
  879. <span style="position:absolute;right:calc(50% - 30px);top:2px;border:1px solid #333;
  880. width:26px;height:26px;border-radius:20px;" class="select-image" data-value="${index}">
  881. <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}">
  882. <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"/>
  883. </svg>
  884. </span>
  885. <span style="position:absolute;right:calc(50% - 60px);top:2px;border:1px solid #333;
  886. width:26px;height:26px;border-radius:20px;
  887. " class="download-direct">
  888. <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;">
  889. <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"/>
  890. <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"/>
  891. </svg>
  892. </span>
  893. `;
  894. let downloadBtn = `
  895. <span style="position:absolute;right:calc(50% - 15px);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. thisImgContainer.insertAdjacentHTML("beforeend", imgInfoContainer);
  905. let thisImgInfoContainer = thisImgContainer.querySelector("div");
  906. let rectWidth = parseInt(thisImgContainer.getBoundingClientRect().width);
  907. if (rectWidth > 120) {
  908. thisImgInfoContainer.insertAdjacentHTML("beforeend", imgInfo);
  909. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  910. } else if (rectWidth <= 120 && rectWidth >= 50) {
  911. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  912. thisImgInfoContainer.getElementsByClassName("select-image")[0].style.right = "50%";
  913. thisImgInfoContainer.getElementsByClassName("download-direct")[0].style.right = "calc(50% - 30px)";
  914. } else {
  915. thisImgInfoContainer.insertAdjacentHTML("beforeend", downloadBtn);
  916. }
  917. ////console.log(img);
  918. });
  919. }
  920. function filterByWidth(src) {
  921. let tempImg = new Image();
  922. tempImg.src = src;
  923. if (tempImg.width >= parseInt(document.querySelector(".width-value-min").value)
  924. && tempImg.width <= parseInt(document.querySelector(".width-value-max").value)) {
  925. return src;
  926. }
  927. }
  928. function filterByHeight(src) {
  929. let tempImg = new Image();
  930. tempImg.src = src;
  931. if (tempImg.height >= parseInt(document.querySelector(".height-value-min").value)
  932. && tempImg.height <= parseInt(document.querySelector(".height-value-max").value)) {
  933. return src;
  934. }
  935. }
  936. function getSavedValue() {
  937. if(GM_getValue("width-check")!=undefined){
  938. //console.log(GM_getValue("width-check"));
  939. (document.querySelector(".width-check").checked = GM_getValue("width-check"));
  940. }
  941. if(GM_getValue("height-check")!=undefined){
  942. (document.querySelector(".height-check").checked = GM_getValue("height-check"));
  943. }
  944. if(GM_getValue("cors-check")!=undefined){
  945. (document.querySelector(".cors-check").checked = GM_getValue("cors-check"));
  946. }
  947. GM_getValue("width-value-min") && (document.querySelector(".width-value-min").value = GM_getValue("width-value-min"));
  948. GM_getValue("width-value-max") && (document.querySelector(".width-value-max").value = GM_getValue("width-value-max"));
  949. GM_getValue("height-value-min") && (document.querySelector(".height-value-min").value = GM_getValue("height-value-min"));
  950. GM_getValue("height-value-max") && (document.querySelector(".height-value-max").value = GM_getValue("height-value-max"));
  951. }
  952. function fetchBase64ImgsThenPushToZipArray() {
  953. zipFilteredImgUrls.forEach((imgUrl, urlIndex) => {
  954. if (imgUrl.includes("data:image")) {
  955. return;
  956. }
  957. /* fetch(imgUrl,{
  958. method: "get",
  959. mode: 'cors'
  960. }).then(response=>{
  961. if (!response.ok) {
  962. throw new Error('Network response was not OK');
  963. }
  964. return response.blob();
  965. }).then(myBlob=>{
  966. var blob = myBlob
  967. let oFileReader = new FileReader();
  968. oFileReader.onloadend = function (e) {
  969. let base64 = e.target.result;
  970. //console.log("》》", base64)
  971. if (base64.includes("data:image")) {
  972. zipFilteredImgUrls[urlIndex] = base64;
  973. //zipImgWaitDownload.push(base64);
  974. }
  975. };
  976. oFileReader.readAsDataURL(blob);
  977. })
  978. .catch((error)=>{ */
  979. try {
  980. GM_xmlhttpRequest({
  981. method: "get",
  982. url: imgUrl,
  983. responseType: "blob",
  984. onload: function (r) {
  985. var blob = r.response;
  986. let oFileReader = new FileReader();
  987. oFileReader.onloadend = function (e) {
  988. let base64 = e.target.result;
  989. if (base64.startsWith("data:image")) {
  990. zipFilteredImgUrls[urlIndex] = base64;
  991. //zipImgWaitDownload.push(base64);
  992. }
  993. };
  994. oFileReader.readAsDataURL(blob);
  995. }
  996. });
  997. } catch (error) {
  998. }
  999. //})
  1000. })
  1001. }
  1002. function cutoffNotBase64Img(imgsUrlArray) {
  1003. let resultArr = [];
  1004. imgsUrlArray.forEach((imgUrl, urlIndex) => {
  1005. if (imgUrl.startsWith("data:image")&&imgUrl.includes("base64")) {
  1006. resultArr.push(imgUrl);
  1007. }
  1008. }
  1009. );
  1010. return resultArr;
  1011. }
  1012. //下面这个括号是wrapper的括号
  1013. }
  1014. })();