图片下载器

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

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