图片下载器

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

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

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

QingJ © 2025

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