图片下载器

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

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

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