图片下载器

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

当前为 2022-03-20 提交的版本,查看 最新版本

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