图片下载器

可以在绝大多数网站提取并批量下载图片。抓取能力大提升!现在可以抓取,H5游戏素材(4399),图库网站(千库网、包图网),漫画网站(腾讯漫画、b站漫画),文库网站(道客巴巴、豆丁),以及其他右键失效或者图片不能另存的网站,用脚本均可以提取并下载。额外功能:zip下载/自动大图。详细见脚本描述(目前适合chrome/firefox+tampermonkey,其他组合多少有问题)

当前为 2023-12-13 提交的版本,查看 最新版本

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