图片下载器

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

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

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