图片下载器

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

当前为 2023-02-03 提交的版本,查看 最新版本

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

QingJ © 2025

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