图片下载器

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

目前为 2022-04-27 提交的版本。查看 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址