图片下载器

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

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

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