图片下载器

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

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

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