图片下载器

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

当前为 2022-09-11 提交的版本,查看 最新版本

  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.25
  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. if(imgEles[i].srcset!==''){
  353. let srcArr=imgEles[i].srcset.split(",");
  354. let srcUrl=srcArr[0].match(/\S+/gi)[0];
  355. for(let k=0;k<srcArr.length-1;k++){
  356. //srcArr[k].match(/\S+/gi),正则的结果一个数组,0是url,1是清晰度
  357. //所以用清晰度,选出最清晰的那张
  358. if(parseInt(srcArr[k].match(/\S+/gi)[1])>parseInt(srcArr[k+1].match(/\S+/gi)[1])){
  359. srcUrl=srcArr[k].match(/\S+/gi)[0];
  360. break;
  361. }else{
  362. srcUrl=srcArr[k+1].match(/\S+/gi)[0];
  363. }
  364. }
  365. //将imgurls 中不包含的srcurl 加入到数组中
  366. if(!imgUrls.includes(srcUrl)){
  367. imgUrls.push(srcUrl);
  368. }
  369. }
  370. }
  371. let imgRegs = bodyStr.match(/(?<=background-image:\s*url\()(\S+)(?=\))/g);
  372. try{
  373. for (let i = 0; i < imgRegs.length; i++) {
  374. ////console.log(imgRegs[i]);
  375. if(imgRegs[i].includes('&quot;')){
  376. imgUrls.push(imgRegs[i].replace(/&quot;/g, ""));
  377. }else if(imgRegs[i].includes("'")){
  378. imgUrls.push(imgRegs[i].replace(/'/g, ""));
  379. }
  380. }
  381. }catch(e){
  382. console.log(e);
  383. }
  384. if (window.location.href.includes("hathitrust.org")) {
  385. let imgs = document.querySelectorAll(".image img");
  386. if (imgs.length > 0) {
  387. let canvas = document.createElement("canvas");
  388. imgUrls = [];
  389. for (let pi = 0; pi < imgs.length; pi++) {
  390. canvas.width = imgs[pi].width;
  391. canvas.height = imgs[pi].height;
  392. canvas.getContext("2d").drawImage(imgs[pi], 0, 0);
  393. imgUrls.push(canvas.toDataURL("image/png"));
  394. }
  395. document.querySelector(".select-all").style = "position:relative;width:15px;height:15px;"
  396. } else {
  397. }
  398. }
  399. if(window.location.href.toString().includes("manga.bilibili.com/")){
  400. let iframeCanvas=`<iframe style="display:none;" id="tyc-insert-iframe"></iframe>`;
  401. if(document.getElementById("tyc-insert-iframe")==null){
  402. document.body.insertAdjacentHTML("afterbegin",iframeCanvas);
  403. document.getElementById("tyc-insert-iframe").contentDocument.body.insertAdjacentHTML("afterbegin",`<canvas id="tyc-insert-canvas"></canvas>`);
  404. document.body.getElementsByTagName('canvas')[0].__proto__.toBlob=document.getElementById("tyc-insert-iframe").contentDocument.getElementById("tyc-insert-canvas").__proto__.toBlob;
  405. }
  406. }
  407. let oldLength=imgUrls.length;
  408. if(canvasEles.length>0){
  409. //console.log(canvasEles);
  410. fetchTip=langSet.fetchTip;
  411. var completeFlag=0;
  412. for(let j=0;j<canvasEles.length;j++){
  413. canvasEles[j].toBlob(blobCallback);
  414. function blobCallback(blob){
  415. //console.log(blob);
  416. let oFileReader = new FileReader();
  417. oFileReader.onloadend = function (e) {
  418. let base64 = e.target.result;
  419. if (base64.includes("data:image")) {
  420. if (!imgUrls.includes(base64)) {
  421. //imgUrls.push(base64);
  422. imgUrls[oldLength+j]=base64;
  423. //console.log(base64);
  424. }
  425. completeFlag++;
  426. document.querySelector(".num-tip").innerText=`${langSet.fetchCount1} ${completeFlag}/${canvasEles.length} ${langSet.fetchCount2}`;
  427. if(completeFlag===canvasEles.length){
  428. clean();
  429. init();
  430. }
  431. }
  432. };
  433. oFileReader.readAsDataURL(blob);
  434. }
  435. }
  436. }else{
  437. fetchTip=`${langSet.fetchDoneTip1}${imgUrls.length}${langSet.fetchDoneTip2}`;
  438. }
  439. } catch(e) {
  440. //alert("error");
  441. console.log(e);
  442. }
  443. let imgContainer = `<style>
  444. .tyc-image-container{
  445. position:fixed;
  446. top:0px;
  447. left:10%;
  448. width:80vw;
  449. z-index:2147483645;
  450. background-color: #dedede;
  451. border: 1px solid #aaa;
  452. overflow:scroll;height:100%;
  453. }
  454. .tyc-image-container button{
  455. border:1px solid #aaa;
  456. border-radius:5px;
  457. height:32px;line-height:32px;
  458. margin:0px;padding:0 5px;
  459. }
  460. .tyc-image-container button:hover{
  461. background-color: #f50;
  462. color: #fff;
  463. }
  464. .control-section{
  465. width:80vw;
  466. z-index:2147483646;
  467. position:fixed;
  468. top:0px;
  469. left:10%;
  470. display: flex;
  471. flex-direction: column;
  472. justify-content: center;
  473. line-height:40px;
  474. background:#eee;border:1px solid #aaa;border-radius:2px;
  475. }
  476. .control-section-sub{
  477. display: flex;
  478. margin-bottom: 5px;
  479. }
  480. .tyc-normal-section{
  481. display: flex;
  482. align-items: center;
  483. flex-direction: row;
  484. flex-wrap: wrap;
  485. align-content: normal;
  486. justify-content: flex-start;
  487. font-size:10px;
  488. }
  489. .tyc-normal-section *{
  490. padding-top:2px;
  491. }
  492. .btn-download{
  493. border:1px solid #aaa;border-radius:5px;
  494. height:32px;line-height:32px;
  495. margin:0px;padding:0 5px;
  496. }
  497. .btn-zipDownload{
  498. border:1px solid #aaa;border-radius:5px;
  499. height:32px;line-height:32px;
  500. margin:0px;padding:0 5px;
  501. }
  502. .btn-close{
  503. font-size:20px;position:absolute;
  504. right:30px;top:4px;
  505. height:32px;line-height:32px;
  506. margin:0px;
  507. border-radius:10px;border:1px solid #aaa;
  508. width:30px;
  509. }
  510. .tyc-image-wrapper{
  511. margin-top:82px;display:flex;justify-content:center;
  512. align-items:center;flex-wrap:wrap;
  513. }
  514. .tyc-input-checkbox{
  515. background-color: initial;
  516. cursor: default;
  517. appearance: auto;
  518. box-sizing: border-box;
  519. margin: 3px 3px 3px 4px;
  520. padding: initial;
  521. border: initial;
  522. }
  523. .tyc-extend-set{
  524. padding: 10px;
  525. border-top: 1px solid rgba(100,100,100,0.1);
  526. }
  527. .tyc-extend-set{
  528. display: none;
  529. align-items: stretch;
  530. flex-direction: column;
  531. justify-content: flex-start;
  532. flex-wrap: nowrap;
  533. padding: 5px;
  534. width: auto;
  535. }
  536. .tyc-extend-set-container{
  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. margin-bottom: 5px;
  546. }
  547. .tyc-autobigimg-set{
  548. display: flex;
  549. align-items: flex-start;
  550. flex-direction: column;
  551. justify-content: flex-start;
  552. flex-wrap: nowrap;
  553. align-content: normal;
  554. border: 1px solid rgba(100,100,100,0.5);
  555. padding: 5px;
  556. }
  557. .tyc-set-domain{
  558. display: flex;
  559. align-items: flex-start;
  560. flex-direction: column;
  561. justify-content: flex-start;
  562. flex-wrap: nowrap;
  563. align-content: normal;
  564. margin: 5px;
  565. padding: 5px;
  566. border: 1px solid rgba(100,100,100,0.3);
  567. width: 95%;
  568. max-height: 150px;
  569. overflow: scroll;
  570. }
  571. .tyc-abi-title{
  572. display: flex;
  573. flex-direction: row;
  574. align-items: center;
  575. justify-content: space-around;
  576. width: 100%;
  577. }
  578. .tyc-abi-domain-title{
  579. display: flex;
  580. flex-direction: row;
  581. align-items: center;
  582. justify-content: space-between;
  583. width: 95%;
  584. border-bottom: 1px solid #ddd;
  585. }
  586. .tyc-set-replacerule{
  587. display: flex;
  588. flex-direction: row;
  589. justify-content: flex-start;
  590. align-items: center;
  591. margin-bottom: 3px;
  592. flex-wrap: wrap;
  593. }
  594. .tyc-set-replacerule *,.tyc-set-replacerule button{
  595. margin-left: 5px;
  596. }
  597. .tyc-set-domain-default{
  598. height: 200px;
  599. overflow: scroll;
  600. display: none;
  601. }
  602. </style>
  603. <div class="tyc-image-container">
  604. <div class="control-section">
  605. <div class="control-section-sub tyc-normal-section">
  606. <input class="select-all tyc-input-checkbox" type="checkbox" name="select-all" value="select-all">${langSet.selectAll}
  607. <button class="btn-download" style="margin-left:5px;">${langSet.downloadBtn}</button>
  608. <button class="btn-zipDownload" style="margin-left:5px;">${langSet.zipDownloadBtn}</button>
  609. <span style="margin-left:10px;" class="num-tip">${langSet.fetchDoneTip1}${imgUrls.length}${langSet.fetchDoneTip2}</span>
  610. <input type="text" class="tyc-file-name" style="height:15px;width:80px;margin-left:25px;font-size:10px;" value="${downloadFileName}">
  611. <input type="text" class="shortCutString" style="height:15px;width:80px;margin-left:25px;font-size:10px;" value="${shortCutString}">-ShortCut
  612. <button cstyle="margin-left:10px;" class="btn-close" >X</button>
  613. </div>
  614. <div style="line-height:12px;" class="control-section-sub tyc-normal-section">
  615. <div style="float:left;display:block;">
  616. <input type="checkbox" class="width-check img-check tyc-input-checkbox" name="width-check" value="width-check">Width:
  617. <input type="text" class="width-value-min" size="1" style="height:15px;width:50px;"
  618. min="0" max="9999" value="0">-
  619. <input type="text" class="width-value-max" size="1" style="height:15px;width:50px;"
  620. min="0" max="9999" value="3000">
  621. </div>
  622. <div style="float:left;margin-left:30px;display:block;">
  623. <input type="checkbox" class="height-check img-check tyc-input-checkbox" name="height-check" value="height-check">Height:
  624. <input type="text" class="height-value-min" size="1" style="height:15px;width:50px;"
  625. min="0" max="9999" value="0">-
  626. <input type="text" class="height-value-max" size="1" style="height:15px;width:50px;"
  627. min="0" max="9999" value="3000">
  628. </div>
  629. <div style="float:left;margin-left:30px;display:block;" class="tyc-cors">
  630. <span class="tyc-tip" style="display: none;
  631. position: absolute;
  632. top: 5px;
  633. left: 50px;
  634. white-space: nowrap;
  635. background: rgb(204, 204, 204);
  636. border: 1px solid rgb(150, 150, 150);
  637. border-radius: 3px;
  638. padding: 5px;">${langSet.zipOptionDesc}
  639. </span>
  640. <input type="checkbox" class="cors-check img-check tyc-input-checkbox" name="cors-check" value="cors-check">
  641. <span>${langSet.zipCheckText}</span>
  642. </div>
  643. <div style="float:left;margin-left:30px;display:block;" class="tyc-download-url">
  644. <button class="tyc-download-url-btn">${langSet.downloadUrlFile}</button>
  645. </div>
  646. <div style="float:left;margin-left:30px;display:block;" class="tyc-extend-btn">
  647. <span>${langSet.moreSetting} </span>
  648. <span style="top: 3px;position: relative;">
  649. <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">
  650. <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"/>
  651. <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"/>
  652. </svg>
  653. </span>
  654. </div>
  655. </div>
  656. <div class="tyc-extend-set control-section-sub">
  657. <div class="tyc-autobigimg-set tyc-extend-set-container">
  658. <div class="tyc-abi-title">
  659. <div>
  660. ${langSet.autoBitImgModule}
  661. </div>
  662. <div>
  663. <button class="tyc-default-rule-show">${langSet.defaultSettingRule}</button>
  664. </div>
  665. <div>
  666. <button>${langSet.exportCustomRule}</button>
  667. </div>
  668. <div>
  669. <input type="file" id="tycfileElem" multiple accept="text/plain" style="display:none">
  670. <button id="tyc-file-select">${langSet.importCustomRule}</button>
  671. </div>
  672. </div>
  673. <div class="tyc-set-domain tyc-set-domain-custom">
  674. </div>
  675. <div class="tyc-set-domain tyc-set-domain-default">
  676. </div>
  677. </div>
  678. </div>
  679. </div>
  680. <div class="tyc-image-wrapper" >
  681. </div>
  682. </div>`
  683. let showBigImage = `
  684. <div class="show-big-image" style="position:fixed;left:30%;top:30%;z-index:2147483647;">
  685. </div>
  686. `
  687. 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">
  688. <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"/>
  689. </svg>`;
  690. document.body.insertAdjacentHTML("afterbegin", imgContainer);
  691. autoBigImage.showDefaultRules();
  692. autoBigImage.showRules("tyc-set-domain-custom","userRules","userRulesChecked","tyc-custom-active");
  693. document.querySelector(".tyc-image-wrapper").style=`margin-top:${document.querySelector(".control-section").clientHeight}px`;
  694. document.body.onclick = (e) => {
  695. //console.log(e);
  696. let ePath=e.path || (e.composedPath && e.composedPath());
  697. if ((e.target.nodeName == "IMG" && e.target.className === "tyc-image-preview")) {
  698. let imgContainer = ePath.find(
  699. (ele) => {
  700. try {
  701. //console.log(ele);
  702. return ele.className.includes("tyc-img-item-container");
  703. }
  704. catch {
  705. }
  706. }
  707. )
  708. let path = imgContainer.getElementsByTagName("img")[0].src;
  709. try {
  710. let container = document.querySelector(".show-big-image");
  711. if (container.getElementsByTagName("img")[0].src === path) {
  712. container.remove();
  713. return;
  714. } else {
  715. container.remove();
  716. }
  717. }
  718. catch {
  719. }
  720. document.body.insertAdjacentHTML("beforeend", showBigImage);
  721. let showItem = `<img src="${path}"/>`
  722. document.querySelector(".show-big-image").insertAdjacentHTML("beforeend", showItem);
  723. let tempImg = document.querySelector(".show-big-image img");
  724. let dWidth = (window.innerWidth - tempImg.width) / 2;
  725. let dHeight = (window.innerHeight - tempImg.height) / 2;
  726. document.querySelector(".show-big-image").style.left = dWidth + "px";
  727. document.querySelector(".show-big-image").style.top = dHeight + "px";
  728.  
  729. if(tempImg.width>window.innerWidth || tempImg.height>window.innerHeight){
  730. document.querySelector(".show-big-image").style.overflow="scroll";
  731. if(tempImg.width>window.innerWidth){
  732. document.querySelector(".show-big-image").style.left="0px";
  733. document.querySelector(".show-big-image").style.width=window.innerWidth+"px";
  734. }
  735. if(tempImg.height>window.innerHeight){
  736. document.querySelector(".show-big-image").style.top="0px";
  737. document.querySelector(".show-big-image").style.height=window.innerHeight+"px";
  738. }
  739. }
  740. } else if (e.target.parentElement.className === "show-big-image") {
  741. try {
  742. document.querySelector(".show-big-image").remove();
  743. }
  744. catch
  745. {
  746. }
  747. } else if (e.target.classList[1] == "bi-download" || ePath.find(isDownload) != undefined) {
  748. let imgContainer = ePath.find(
  749. (ele) => {
  750. try {
  751. //console.log(ele);
  752. return ele.className.includes("tyc-img-item-container");
  753. }
  754. catch {
  755. }
  756. }
  757. )
  758. let path = imgContainer.getElementsByTagName("img")[0].src;
  759. let filename;
  760. if (path.indexOf("/") > 0)//如果包含有"/"号 从最后一个"/"号+1的位置开始截取字符串
  761. {
  762. filename = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
  763. }
  764. else {
  765. filename = path;
  766. }
  767. //console.log("download start" + path + " " + filename);
  768. //GM_download(path, "pic");
  769. let saveFileName=document.querySelector(".tyc-file-name").value||"pic";
  770. saveAs(path,saveFileName);
  771. } else if (e.target.classList[1] == "bi-check" || ePath.find(isSelect) != undefined) {
  772. let checkSvg = ePath.find((ele) => ele.classList[1] === "bi-check");
  773. let currentImgIndex = parseInt(checkSvg.dataset.value);
  774. let container = ePath.find((ele) => ele.className === `tyc-img-item-container-${currentImgIndex}`);
  775. if (imgSelected.includes(currentImgIndex)) {
  776. imgSelected.splice(imgSelected.indexOf(currentImgIndex), 1);
  777. checkSvg.style.color = "black";
  778. container.style.border = "1px solid #99d";
  779. } else {
  780. imgSelected.push(currentImgIndex);
  781. checkSvg.style.color = "white";
  782. container.style.border = "1px solid white";
  783. }
  784. zipImgSelected=imgSelected;
  785. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgSelected.length}/${imgUrls.length}${langSet.fetchDoneTip2}`;
  786. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  787. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  788. zipImgWaitDownload=cutoffNotBase64Img(zipImgWaitDownload);
  789. }
  790. }
  791. document.querySelector(".btn-close").onclick = (e) => {
  792. document.querySelector(".tyc-image-container").remove();
  793. }
  794. document.querySelector(".btn-download").onclick = async (e) => {
  795. if (imgWaitDownload.length >= 1) {
  796. //console.log(imgWaitDownload);
  797. /* imgWaitDownload.forEach(async (img, index) => {
  798. //let filename = `pic-${index}.jpg`;
  799. //filename=filename.replace(/\\/g, '/').replace(/\/{2,}/g, '/');
  800. //await GM_download(img, `pic-${index}`);
  801. }); */
  802. function sleep(){
  803. return new Promise((resolve,reject)=>{
  804. setTimeout(() => {
  805. resolve(1);
  806. }, 200);
  807. })
  808. }
  809. for(let i=0;i<imgWaitDownload.length;i++){
  810. await sleep();
  811. let saveFileName=document.querySelector(".tyc-file-name").value||"pic";
  812. console.log(`${saveFileName}-${i}`);
  813. saveAs(imgWaitDownload[i],`${saveFileName}-${i}`);
  814. }
  815. } else {
  816. alert(`${langSet.selectAlert}`);
  817. }
  818. }
  819. document.querySelector(".btn-zipDownload").onclick = (e) => {
  820. //console.log(zipImgWaitDownload);
  821. try {
  822. if (zipImgWaitDownload.length >= 1) {
  823. //console.log(zipImgWaitDownload);
  824. zipImgWaitDownload.forEach(async (img, index) => {
  825. let fileExt = img.substring(img.indexOf("image/") + 6, img.indexOf(";"))
  826. fileExt=fileExt.includes("svg")?"svg":fileExt;
  827. let saveFileName=document.querySelector(".tyc-file-name").value||"pic";
  828. let filename = `${saveFileName}-${index}.${fileExt}`;
  829. zipSubFoler.file(filename, img.split(",")[1], { base64: true });
  830. });
  831. zipFolder.generateAsync({ type: "blob" })
  832. .then(function (content) {
  833. // see FileSaver.js
  834. let saveFileName=document.querySelector(".tyc-file-name").value||"pic";
  835. saveAs(content, `${saveFileName}s.zip`);
  836. zipFolder.remove("pics");
  837. zipSubFoler = zipFolder.folder('pics');
  838. });
  839. } else {
  840. alert(`${langSet.selectAlert}`);
  841. }
  842. } catch (error) {
  843. //console.log(error);
  844. }
  845. }
  846. document.querySelector(".tyc-cors").onmouseover=e=>{
  847. e.preventDefault();
  848. document.querySelector(".tyc-tip").style.display="block";
  849. }
  850. document.querySelector(".tyc-cors").onmouseout=e=>{
  851. e.preventDefault();
  852. document.querySelector(".tyc-tip").style.display="none";
  853. }
  854. document.body.onchange = (e) => {
  855. if (e.target.className.includes("width-check")) {
  856. GM_setValue('width-check', e.target.checked);
  857. }
  858. if (e.target.className.includes("height-check")) {
  859. GM_setValue('height-check', e.target.checked);
  860. }
  861. if (e.target.className.includes("cors-check")) {
  862. GM_setValue('cors-check', e.target.checked);
  863. if (document.querySelector(".cors-check").checked) {
  864. fetchBase64ImgsThenPushToZipArray();
  865. }
  866. }
  867. if(e.target.className.includes("tyc-default-active")){
  868. autoBigImage.oncheckChange();
  869. }
  870. if(e.target.className.includes("tyc-custom-active")){
  871. autoBigImage.oncheckChangeCustom();
  872. }
  873. if (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")) {
  874. GM_setValue(e.target.className, e.target.value);
  875. }
  876. if (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("shortCutString")) {
  877. GM_setValue(e.target.className, e.target.value);
  878. hotkeys(e.target.value, wrapper);
  879. }
  880. (e.target.className.includes("width-check") || e.target.className.includes("height-check") ||
  881. (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")))
  882. && (clean(), init());
  883. }
  884. document.querySelector(".select-all").onchange = (e) => {
  885. if (document.querySelector(".select-all").checked) {
  886. imgWaitDownload = filteredImgUrls;
  887. zipImgWaitDownload=cutoffNotBase64Img(zipFilteredImgUrls);
  888. } else {
  889. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  890. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  891. }
  892. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgWaitDownload.length}/${filteredImgUrls.length}${langSet.fetchDoneTip2}`;
  893. }
  894. document.querySelector(".tyc-extend-btn").onclick=e=>{
  895. if(document.querySelector(".tyc-extend-btn").classList.contains("extend-open")){
  896. document.querySelector(".tyc-extend-btn").classList.remove("extend-open");
  897. document.querySelector(".tyc-extend-set").style.display="none";
  898. document.querySelector(".tyc-extend-btn").style.color="black";
  899. document.querySelector(".tyc-extend-btn").innerHTML=`<span>${langSet.moreSetting}</span>
  900. <span style="top: 3px;position: relative;">
  901. <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">
  902. <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"/>
  903. <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"/>
  904. </svg>
  905. </span> `
  906. ;
  907. }else{
  908. document.querySelector(".tyc-extend-btn").classList.add("extend-open");
  909. document.querySelector(".tyc-extend-set").style.display="flex";
  910. document.querySelector(".tyc-extend-btn").style.color="#f50";
  911. document.querySelector(".tyc-extend-btn").innerHTML=`<span>${langSet.fold} </span>
  912. <span style="top: 3px;position: relative;">
  913. <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">
  914. <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"/>
  915. <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"/>
  916. </svg>
  917. </span> `
  918. }
  919. }
  920. document.querySelector(".tyc-default-rule-show").onclick=autoBigImage.onclickShowDefaultBtn;
  921. document.querySelector("#tyc-file-select").onclick=e=>{
  922. document.querySelector("#tycfileElem").click();
  923. }
  924. document.querySelector("#tycfileElem").onchange=autoBigImage.getCustomRules;
  925. document.querySelector(".tyc-download-url-btn").onclick=e=>{
  926. let blob=new Blob([imgWaitDownload.join("\n")],{ type: "text/plain", endings: "native" });
  927. saveAs(blob,"urls.txt");
  928. }
  929. init();
  930. function init() {
  931. filteredImgUrls = imgUrls;
  932. filteredImgUrls=autoBigImage.getBigImageArray(filteredImgUrls);
  933. getSavedValue();
  934. if (document.querySelector(".width-check").checked) {
  935. filteredImgUrls = filteredImgUrls.filter(filterByWidth);
  936. }
  937. if (document.querySelector(".height-check").checked) {
  938. filteredImgUrls = filteredImgUrls.filter(filterByHeight);
  939. }
  940. zipFilteredImgUrls = filteredImgUrls;
  941. if (document.querySelector(".cors-check").checked) {
  942. fetchBase64ImgsThenPushToZipArray();
  943. }
  944. showImage(filteredImgUrls);
  945. }
  946. function clean() {
  947. imgWaitDownload = [];
  948. imgSelected = [];
  949. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgSelected.length}/${imgUrls.length}${langSet.fetchDoneTip2}`;
  950. document.querySelector(".tyc-image-wrapper").innerHTML = "";
  951. }
  952. function isDownload(ele) {
  953. return ele.className == "download-direct";
  954. }
  955. function isSelect(ele) {
  956. return ele.className == "select-image";
  957. }
  958. function transIndexToLink(WholeImgs,selectedImgs) {
  959. let transedImgs=[];
  960. selectedImgs.forEach((imgIndex, index) => {
  961. transedImgs.push(WholeImgs[imgIndex]);
  962. });
  963. return transedImgs;
  964. }
  965. function showImage(filtedImgUrls) {
  966. filtedImgUrls.forEach((img, index) => {
  967. if (window.location.href.includes("huaban.com")) {
  968. if (img.includes("/webp")) {
  969. img = img.replace(/\/webp/g, "/png");
  970. }
  971. }
  972. let insertImg = `<div class="tyc-img-item-container-${index}" style="text-align:center;font-size:0px;
  973. margin:5px;border:1px solid #99d;border-radius:3px;
  974. ">
  975. <img class="tyc-image-preview" src="${img}"/ style="width:auto;height:200px;"></div>`
  976. document.querySelector(".tyc-image-wrapper").insertAdjacentHTML("beforeend", insertImg);
  977. let naturalW = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalWidth;
  978. let naturalH = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalHeight;
  979. let imgInfoContainer = `
  980. <div style="font-size:0px;background-color:rgba(100,100,100,0.6);height:30px;position:relative;">
  981. </div>
  982. `;
  983. let thisImgContainer = document.querySelector(`.tyc-img-item-container-${index}`);
  984. let imgContainerWidth = thisImgContainer.getBoundingClientRect().width;
  985. let imgInfo = `
  986. <span style="font-size:16px;position:absolute;left:calc(50% - 80px);top:7px;">${naturalW}X${naturalH}</span>
  987. `;
  988. /*
  989. <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;">
  990. <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"/>
  991. </svg>*/
  992. let downAndFullBtn = `
  993. <span style="position:absolute;right:calc(50% - 30px);top:2px;border:1px solid #333;
  994. width:26px;height:26px;border-radius:20px;" class="select-image" data-value="${index}">
  995. <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}">
  996. <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"/>
  997. </svg>
  998. </span>
  999. <span style="position:absolute;right:calc(50% - 60px);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. let downloadBtn = `
  1009. <span style="position:absolute;right:calc(50% - 15px);top:2px;border:1px solid #333;
  1010. width:26px;height:26px;border-radius:20px;
  1011. " class="download-direct">
  1012. <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;">
  1013. <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"/>
  1014. <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"/>
  1015. </svg>
  1016. </span>
  1017. `
  1018. thisImgContainer.insertAdjacentHTML("beforeend", imgInfoContainer);
  1019. let thisImgInfoContainer = thisImgContainer.querySelector("div");
  1020. let rectWidth = parseInt(thisImgContainer.getBoundingClientRect().width);
  1021. if (rectWidth > 120) {
  1022. thisImgInfoContainer.insertAdjacentHTML("beforeend", imgInfo);
  1023. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  1024. } else if (rectWidth <= 120 && rectWidth >= 50) {
  1025. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  1026. thisImgInfoContainer.getElementsByClassName("select-image")[0].style.right = "50%";
  1027. thisImgInfoContainer.getElementsByClassName("download-direct")[0].style.right = "calc(50% - 30px)";
  1028. } else {
  1029. thisImgInfoContainer.insertAdjacentHTML("beforeend", downloadBtn);
  1030. }
  1031. ////console.log(img);
  1032. });
  1033. }
  1034. function filterByWidth(src) {
  1035. let tempImg = new Image();
  1036. tempImg.src = src;
  1037. if (tempImg.width >= parseInt(document.querySelector(".width-value-min").value)
  1038. && tempImg.width <= parseInt(document.querySelector(".width-value-max").value)) {
  1039. return src;
  1040. }
  1041. }
  1042. function filterByHeight(src) {
  1043. let tempImg = new Image();
  1044. tempImg.src = src;
  1045. if (tempImg.height >= parseInt(document.querySelector(".height-value-min").value)
  1046. && tempImg.height <= parseInt(document.querySelector(".height-value-max").value)) {
  1047. return src;
  1048. }
  1049. }
  1050. function getSavedValue() {
  1051. if(GM_getValue("width-check")!=undefined){
  1052. //console.log(GM_getValue("width-check"));
  1053. (document.querySelector(".width-check").checked = GM_getValue("width-check"));
  1054. }
  1055. if(GM_getValue("height-check")!=undefined){
  1056. (document.querySelector(".height-check").checked = GM_getValue("height-check"));
  1057. }
  1058. if(GM_getValue("cors-check")!=undefined){
  1059. (document.querySelector(".cors-check").checked = GM_getValue("cors-check"));
  1060. }
  1061. GM_getValue("width-value-min") && (document.querySelector(".width-value-min").value = GM_getValue("width-value-min"));
  1062. GM_getValue("width-value-max") && (document.querySelector(".width-value-max").value = GM_getValue("width-value-max"));
  1063. GM_getValue("height-value-min") && (document.querySelector(".height-value-min").value = GM_getValue("height-value-min"));
  1064. GM_getValue("height-value-max") && (document.querySelector(".height-value-max").value = GM_getValue("height-value-max"));
  1065. GM_getValue("shortCutString") && (document.querySelector(".shortCutString").value = GM_getValue("shortCutString"));
  1066. }
  1067. function fetchBase64ImgsThenPushToZipArray() {
  1068. zipFilteredImgUrls.forEach((imgUrl, urlIndex) => {
  1069. if (imgUrl.includes("data:image")) {
  1070. return;
  1071. }
  1072. /* fetch(imgUrl,{
  1073. method: "get",
  1074. mode: 'cors'
  1075. }).then(response=>{
  1076. if (!response.ok) {
  1077. throw new Error('Network response was not OK');
  1078. }
  1079. return response.blob();
  1080. }).then(myBlob=>{
  1081. var blob = myBlob
  1082. let oFileReader = new FileReader();
  1083. oFileReader.onloadend = function (e) {
  1084. let base64 = e.target.result;
  1085. //console.log("》》", base64)
  1086. if (base64.includes("data:image")) {
  1087. zipFilteredImgUrls[urlIndex] = base64;
  1088. //zipImgWaitDownload.push(base64);
  1089. }
  1090. };
  1091. oFileReader.readAsDataURL(blob);
  1092. })
  1093. .catch((error)=>{ */
  1094. try {
  1095. let host=window.location.origin+"/";
  1096. GM_xmlhttpRequest({
  1097. method: "get",
  1098. url: imgUrl,
  1099. headers: {referer: host},
  1100. responseType: "blob",
  1101. onload: function (r) {
  1102. var blob = r.response;
  1103. let oFileReader = new FileReader();
  1104. oFileReader.onloadend = function (e) {
  1105. let base64 = e.target.result;
  1106. if (base64.startsWith("data:image")) {
  1107. zipFilteredImgUrls[urlIndex] = base64;
  1108. //zipImgWaitDownload.push(base64);
  1109. }
  1110. };
  1111. oFileReader.readAsDataURL(blob);
  1112. }
  1113. });
  1114. } catch (error) {
  1115. }
  1116. //})
  1117. })
  1118. }
  1119. function cutoffNotBase64Img(imgsUrlArray) {
  1120. let resultArr = [];
  1121. imgsUrlArray.forEach((imgUrl, urlIndex) => {
  1122. if (imgUrl.startsWith("data:image")&&imgUrl.includes("base64")) {
  1123. resultArr.push(imgUrl);
  1124. }
  1125. }
  1126. );
  1127. return resultArr;
  1128. }
  1129. //下面这个括号是wrapper的括号
  1130. }
  1131. })();