图片下载器

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

当前为 2022-06-05 提交的版本,查看 最新版本

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