图片下载器

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

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

QingJ © 2025

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