图片下载器

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

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

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