图片下载器

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

当前为 2022-05-08 提交的版本,查看 最新版本

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