图片下载器

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

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

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