图片下载器

可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,不能右键保存图片或者保存的图片文件格式无法识别,均可以用脚本提取,然后用脚本提供的下载按钮,就可以下载到正确格式的图片文件。点击右键-tampermonkey-图片下载器-打开脚本(或快捷键alt+w),按这个顺序使用。(目前只适合chrome+tampermonkey,其他组合多少有问题)

当前为 2022-01-22 提交的版本,查看 最新版本

  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 You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  25. // @description:zh-CN 可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,不能右键保存图片或者保存的图片文件格式无法识别,均可以用脚本提取,然后用脚本提供的下载按钮,就可以下载到正确格式的图片文件。点击右键-tampermonkey-图片下载器-打开脚本(或快捷键alt+w),按这个顺序使用。(目前只适合chrome+tampermonkey,其他组合多少有问题)
  26. // @description:zh-TW 可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网、包图网或者有妖气、腾讯漫画、b站漫画这种,不能右键保存图片或者保存的图片文件格式无法识别,均可以用脚本提取,然后用脚本提供的下载按钮,就可以下载到正确格式的图片文件。点击右键-tampermonkey-图片下载器-打开脚本(或快捷键alt+w),按这个顺序使用。(目前只适合chrome+tampermonkey,其他组合多少有问题)
  27. // @description:ja You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  28. // @description:ko You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  29. // @description:de You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  30. // @description:es You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  31. // @description:eo You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  32. // @description:fr You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  33. // @description:it You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  34. // @description:ru You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  35. // @description:vi You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  36. // @description:pt-BR You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  37. // @description:id You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  38. // @description:ar You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  39. // @description:bg You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  40. // @description:cs You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  41. // @description:tr You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  42. // @description:el You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  43. // @description:hu You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  44. // @description:th You can extract and download pictures in batches on most websites(e.g.instagram).Right Click-tampermonkey-Image Downloader(or alt+w),use in this order.(currently only suitable for tampermonkey and chrome,others have not tried it)
  45. // @version 1.92
  46. // @author 桃源隐叟
  47. // @include *
  48. // @connect *
  49. // @grant GM_openInTab
  50. // @grant GM_registerMenuCommand
  51. // @grant GM_setValue
  52. // @grant GM_getValue
  53. // @grant GM_xmlhttpRequest
  54. // @grant GM_download
  55. // @require https://cdn.jsdelivr.net/npm/hotkeys-js@3.7.2/dist/hotkeys.min.js
  56. // @require https://cdn.bootcss.com/jszip/3.7.1/jszip.min.js
  57. // @require https://cdn.bootcss.com/FileSaver.js/1.3.8/FileSaver.min.js
  58. // @run-at document-end
  59. // @match *
  60. // @match https://www.bilibili.com/
  61. // @match https://588ku.com/
  62. // @homepageURL https://github.com/taoyuancun123/modifyText/blob/master/modifyText.js
  63. // @supportURL https://greasyfork.org/zh-CN/scripts/419894/feedback
  64. // @license GPLv3
  65. // ==/UserScript==
  66. (function () {
  67. 'use strict';
  68. var lang = navigator.appName == "Netscape" ? navigator.language : navigator.userLanguage;
  69. var langSet;
  70. var localization = {
  71. zh: {
  72. selectAll: "全选",
  73. downloadBtn: "下载",
  74. downloadMenuText: "打开脚本(Alt+w)",
  75. zipDownloadBtn: "zip下载",
  76. selectAlert:"请至少选中一张图片。",
  77. fetchTip:"准备抓取canvas图片",
  78. fetchCount1:`抓取canvas图片第`,
  79. fetchCount2:'张',
  80. fetchDoneTip1:"已选(0/",
  81. fetchDoneTip1Type2:"已选(",
  82. fetchDoneTip2:")张图片",
  83. },
  84. en: {
  85. selectAll: "selectAll",
  86. downloadBtn: "download",
  87. downloadMenuText: "Open(Alt+w)",
  88. zipDownloadBtn: "zip Download",
  89. selectAlert:"Please at last select one image.",
  90. fetchTip:"Ready to fetch canvas image.",
  91. fetchCount1:`Fetch the`,
  92. fetchCount2:' canvas image.',
  93. fetchDoneTip1:"(0/",
  94. fetchDoneTip1Type2:"(",
  95. fetchDoneTip2:") Images selected",
  96. }
  97. }
  98. if (lang.toLowerCase().includes("zh-")) {
  99. langSet = localization.zh;
  100. } else {
  101. langSet = localization.en;
  102. }
  103.  
  104. const autoBigImage={
  105. bigImageArray:[],
  106. defaultRules:[
  107. {originReg:/(?<=(.+sinaimg\.(?:cn|com)\/))([\w\.]+)(?=(\/.+))/i,replacement:"large"},
  108. {originReg:/(?<=(.+alicdn\.(?:cn|com)\/.+\.(jpg|jpeg|gif|png|bmp|webp)))_.+/i,replacement:""},
  109. {originReg:/(?<=(.+alicdn\.(?:cn|com)\/.+))(\.\w+)(?=(\.(jpg|jpeg|gif|png|bmp|webp)))/i,replacement:""},
  110. {originReg:/(?<=(.+360buyimg\.(?:cn|com)\/))(\w+\/)(?=(.+\.(jpg|jpeg|gif|png|bmp|webp)))/i,replacement:"n0/"},
  111. {originReg:/(?<=(.+hdslb\.(?:cn|com)\/.+\.(jpg|jpeg|gif|png|bmp|webp)))@.+/i,replacement:""},
  112. ],
  113. replace(originImgUrls){
  114. let that=this;
  115. that.bigImageArray=Array.from(new Set(originImgUrls));
  116. //console.log(that.bigImageArray);
  117. that.bigImageArray.forEach(replaceByReg);
  118. function replaceByReg(urlStr,urlIndex){
  119. if(urlStr.includes("data:image/"))return;
  120. that.defaultRules.forEach((rule,ruleIndex)=>{
  121. let bigImage=urlStr.replace(rule.originReg,rule.replacement);
  122. bigImage&&that.bigImageArray.push(bigImage);
  123. })
  124. }
  125. },
  126. getBigImageArray(originImgUrls){
  127. this.replace(originImgUrls);
  128. let uniqueArray=Array.from(new Set(this.bigImageArray));
  129. return uniqueArray;
  130. },
  131. showRules(){
  132.  
  133. }
  134. }
  135. GM_registerMenuCommand(langSet.downloadMenuText, wrapper);
  136. hotkeys('alt+w', wrapper);
  137. function wrapper() {
  138. try {
  139. document.querySelector(".tyc-image-container").remove();
  140. } catch {
  141. }
  142. var imgUrls = [];
  143. var bodyStr = document.body.innerHTML;
  144. var imgSelected = [];
  145. var zipImgSelected = [];
  146. var imgWaitDownload = [];
  147. var zipImgWaitDownload = [];
  148. var widthFilter = { min: 0, max: 3000 };
  149. var heightFilter = { min: 0, max: 3000 };
  150. var filteredImgUrls = [];
  151. var zipFilteredImgUrls = [];
  152. try{
  153. var zipFolder = new JSZip();
  154. var zipSubFoler = zipFolder.folder('pics');
  155. }
  156. catch{
  157. }
  158. var fetchTip='';
  159. try {
  160. let imgEles = document.getElementsByTagName("img");
  161. let canvasEles=document.getElementsByTagName("canvas");
  162. for (let i = 0; i < imgEles.length; i++) {
  163. ////console.log(imgEles[i].src);
  164. if (!imgUrls.includes(imgEles[i].src)) {
  165. imgUrls.push(imgEles[i].src);
  166. } else if (!imgUrls.includes(imgEles[i].srcset)) {
  167. imgUrls.push(imgEles[i].srcset);
  168. }
  169. }
  170. let imgRegs = bodyStr.match(/(?<=background-image:\s*url\()(\S+)(?=\))/g);
  171. for (let i = 0; i < imgRegs.length; i++) {
  172. ////console.log(imgRegs[i]);
  173. if (!imgUrls.includes(imgRegs[i].replace(/&quot;/g, ""))) {
  174. imgUrls.push(imgRegs[i].replace(/&quot;/g, ""));
  175. }
  176. }
  177. if (window.location.href.includes("hathitrust.org")) {
  178. let imgs = document.querySelectorAll(".image img");
  179. if (imgs.length > 0) {
  180. let canvas = document.createElement("canvas");
  181. imgUrls = [];
  182. for (let pi = 0; pi < imgs.length; pi++) {
  183. canvas.width = imgs[pi].width;
  184. canvas.height = imgs[pi].height;
  185. canvas.getContext("2d").drawImage(imgs[pi], 0, 0);
  186. imgUrls.push(canvas.toDataURL("image/png"));
  187. }
  188. document.querySelector(".select-all").style = "position:relative;width:15px;height:15px;"
  189. } else {
  190. }
  191. }
  192. if(window.location.href.toString().includes("manga.bilibili.com/")){
  193. let iframeCanvas=`<iframe style="display:none;" id="tyc-insert-iframe"></iframe>`;
  194. if(document.getElementById("tyc-insert-iframe")==null){
  195. document.body.insertAdjacentHTML("afterbegin",iframeCanvas);
  196. document.getElementById("tyc-insert-iframe").contentDocument.body.insertAdjacentHTML("afterbegin",`<canvas id="tyc-insert-canvas"></canvas>`);
  197. document.body.getElementsByTagName('canvas')[0].__proto__.toBlob=document.getElementById("tyc-insert-iframe").contentDocument.getElementById("tyc-insert-canvas").__proto__.toBlob;
  198. }
  199. }
  200. let oldLength=imgUrls.length;
  201. if(canvasEles.length>0){
  202. fetchTip=langSet.fetchTip;
  203. var completeFlag=0;
  204. for(let j=0;j<canvasEles.length;j++){
  205. canvasEles[j].toBlob(blobCallback);
  206. function blobCallback(blob){
  207. let oFileReader = new FileReader();
  208. oFileReader.onloadend = function (e) {
  209. let base64 = e.target.result;
  210. if (base64.includes("data:image")) {
  211. if (!imgUrls.includes(base64)) {
  212. //imgUrls.push(base64);
  213. imgUrls[oldLength+j]=base64;
  214. }
  215. completeFlag++;
  216. document.querySelector(".num-tip").innerText=`${langSet.fetchCount1} ${completeFlag}/${canvasEles.length} ${langSet.fetchCount2}`;
  217. if(completeFlag===canvasEles.length){
  218. clean();
  219. init();
  220. }
  221. }
  222. };
  223. oFileReader.readAsDataURL(blob);
  224. }
  225. }
  226. }else{
  227. fetchTip=`${langSet.fetchDoneTip1}${imgUrls.length}${langSet.fetchDoneTip2}`;
  228. }
  229. } catch {
  230. //alert("error");
  231. }
  232. let imgContainer = `
  233. <style>
  234. .tyc-image-container{
  235. position:fixed;
  236. top:0px;
  237. left:10%;
  238. width:80vw;
  239. z-index:2147483645;
  240. background-color: #dedede;
  241. border: 1px solid #aaa;
  242. overflow:scroll;height:100%;
  243. }
  244. .tyc-image-container button{
  245. border:1px solid #aaa;
  246. border-radius:5px;
  247. height:32px;line-height:32px;
  248. margin:0px;padding:0 5px;
  249. }
  250. .tyc-image-container button:hover{
  251. background-color: #f50;
  252. color: #fff;
  253. }
  254. .control-section{
  255. width:80vw;
  256. z-index:2147483646;
  257. position:fixed;
  258. top:0px;
  259. left:10%;
  260. display: flex;
  261. flex-direction: column;
  262. justify-content: center;
  263. line-height:40px;
  264. background:#eee;border:1px solid #aaa;border-radius:2px;
  265. }
  266. .control-section-sub{
  267. display: flex;
  268. margin-bottom: 5px;
  269. }
  270. .tyc-normal-section{
  271. display: flex;
  272. align-items: center;
  273. flex-direction: row;
  274. justify-content: flex-start;
  275. flex-wrap: nowrap;
  276. align-content: normal;
  277. }
  278. .btn-download{
  279. border:1px solid #aaa;border-radius:5px;
  280. height:32px;line-height:32px;
  281. margin:0px;padding:0 5px;
  282. }
  283. .btn-zipDownload{
  284. border:1px solid #aaa;border-radius:5px;
  285. height:32px;line-height:32px;
  286. margin:0px;padding:0 5px;
  287. }
  288. .btn-close{
  289. font-size:20px;position:absolute;
  290. right:30px;top:4px;
  291. height:32px;line-height:32px;
  292. margin:0px;
  293. border-radius:10px;border:1px solid #aaa;
  294. width:30px;
  295. }
  296. .tyc-image-wrapper{
  297. margin-top:82px;display:flex;justify-content:center;
  298. align-items:center;flex-wrap:wrap;
  299. }
  300. .tyc-input-checkbox{
  301. background-color: initial;
  302. cursor: default;
  303. appearance: auto;
  304. box-sizing: border-box;
  305. margin: 3px 3px 3px 4px;
  306. padding: initial;
  307. border: initial;
  308. }
  309. .tyc-extend-set{
  310. padding: 10px;
  311. border-top: 1px solid rgba(100,100,100,0.1);
  312. }
  313. .tyc-extend-set{
  314. display: none;
  315. align-items: stretch;
  316. flex-direction: column;
  317. justify-content: flex-start;
  318. flex-wrap: nowrap;
  319. padding: 5px;
  320. width: auto;
  321. }
  322. .tyc-extend-set-container{
  323. display: flex;
  324. align-items: flex-start;
  325. flex-direction: column;
  326. justify-content: flex-start;
  327. flex-wrap: nowrap;
  328. align-content: normal;
  329. border: 1px solid rgba(100,100,100,0.5);
  330. padding: 5px;
  331. margin-bottom: 5px;
  332. }
  333. .tyc-autobigimg-set{
  334. display: flex;
  335. align-items: flex-start;
  336. flex-direction: column;
  337. justify-content: flex-start;
  338. flex-wrap: nowrap;
  339. align-content: normal;
  340. border: 1px solid rgba(100,100,100,0.5);
  341. padding: 5px;
  342. }
  343. .tyc-set-domain{
  344. display: flex;
  345. align-items: flex-start;
  346. flex-direction: column;
  347. justify-content: flex-start;
  348. flex-wrap: nowrap;
  349. align-content: normal;
  350. margin: 5px;
  351. padding: 5px;
  352. border: 1px solid rgba(100,100,100,0.3);
  353. width: 95%;
  354. }
  355. .tyc-abi-title{
  356. display: flex;
  357. flex-direction: row;
  358. align-items: center;
  359. justify-content: space-between;
  360. width: 100%;
  361. }
  362. .tyc-abi-domain-title{
  363. display: flex;
  364. flex-direction: row;
  365. align-items: center;
  366. justify-content: space-between;
  367. width: 95%;
  368. border-bottom: 1px solid #ddd;
  369. }
  370. .tyc-set-replacerule{
  371. display: flex;
  372. flex-direction: row;
  373. justify-content: flex-start;
  374. align-items: center;
  375. margin-bottom: 3px;
  376. flex-wrap: wrap;
  377. }
  378. .tyc-set-replacerule *,.tyc-set-replacerule button{
  379. margin-left: 5px;
  380. }
  381. </style>
  382. <div class="tyc-image-container">
  383. <div class="control-section">
  384. <div class="control-section-sub tyc-normal-section">
  385. <input class="select-all tyc-input-checkbox" type="checkbox" name="select-all" value="select-all">${langSet.selectAll}
  386. <button class="btn-download" style="margin-left:5px;">${langSet.downloadBtn}</button>
  387. <button class="btn-zipDownload" style="margin-left:5px;">${langSet.zipDownloadBtn}</button>
  388. <span style="margin-left:10px;" class="num-tip">${langSet.fetchDoneTip1}${imgUrls.length}${langSet.fetchDoneTip2}</span>
  389. <button cstyle="margin-left:10px;" class="btn-close" >X</button>
  390. </div>
  391. <div style="line-height:12px;" class="control-section-sub tyc-normal-section">
  392. <div style="float:left;display:block;">
  393. <input type="checkbox" class="width-check img-check tyc-input-checkbox" name="width-check" value="width-check">Width:
  394. <input type="text" class="width-value-min" size="1" style="height:15px;width:50px;"
  395. min="0" max="9999" value="0">-
  396. <input type="text" class="width-value-max" size="1" style="height:15px;width:50px;"
  397. min="0" max="9999" value="3000">
  398. </div>
  399. <div style="float:left;margin-left:30px;display:block;">
  400. <input type="checkbox" class="height-check img-check tyc-input-checkbox" name="height-check" value="height-check">Height:
  401. <input type="text" class="height-value-min" size="1" style="height:15px;width:50px;"
  402. min="0" max="9999" value="0">-
  403. <input type="text" class="height-value-max" size="1" style="height:15px;width:50px;"
  404. min="0" max="9999" value="3000">
  405. </div>
  406. <div style="float:left;margin-left:30px;display:block;" class="tyc-cors">
  407. <span class="tyc-tip" style="display: none;
  408. position: absolute;
  409. top: 5px;
  410. left: 50px;
  411. white-space: nowrap;
  412. background: rgb(204, 204, 204);
  413. border: 1px solid rgb(150, 150, 150);
  414. border-radius: 3px;
  415. padding: 5px;">勾选使用zip下载后,会请求跨域权限,否则zip下载基本下载不到图片。
  416. </span>
  417. <input type="checkbox" class="cors-check img-check tyc-input-checkbox" name="cors-check" value="cors-check">
  418. <span>使用zip下载</span>
  419. </div>
  420. <div style="float:left;margin-left:30px;display:block;" class="tyc-extend-btn">
  421. <span>更多设置 </span>
  422. <span style="top: 3px;position: relative;">
  423. <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">
  424. <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"/>
  425. <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"/>
  426. </svg>
  427. </span>
  428. </div>
  429. </div>
  430. <div class="tyc-extend-set control-section-sub">
  431. <div class="tyc-autobigimg-set tyc-extend-set-container">
  432. <div class="tyc-abi-title">
  433. <div>
  434. <input type="checkbox" name="sites" class="tyc-show-in-menu">开启自动大图
  435. </div>
  436. <div>
  437. <button>新增规则</button>
  438. </div>
  439. </div>
  440. <div class="tyc-set-domain">
  441. <div class="tyc-set-replacerule">
  442. <input type="checkbox" name="sites" class="tyc-show-in-menu">
  443. <input type="text" name="title" placeholder="输入待替换正则" class="tyc-search-title">
  444. <input type="text" name="urls" placeholder="输入替换它的字符串或者函数" class="tyc-search-url">
  445. <button class="tyc-delete">删除</button>
  446. </div>
  447. <div class="tyc-set-replacerule">
  448. <input type="checkbox" name="sites" class="tyc-show-in-menu">
  449. <input type="text" name="title" placeholder="输入将显示在菜单中的提示名" class="tyc-search-title">
  450. <input type="text" name="urls" placeholder="参考其他例子,输入除关键词外的网址部分" class="tyc-search-url">
  451. <button class="tyc-delete">删除</button>
  452. </div>
  453. </div>
  454. </div>
  455. </div>
  456. </div>
  457. <div class="tyc-image-wrapper" >
  458. </div>
  459. </div>`
  460. let showBigImage = `
  461. <div class="show-big-image" style="position:fixed;left:30%;top:30%;z-index:2147483647;">
  462. </div>
  463. `
  464. document.body.insertAdjacentHTML("afterbegin", imgContainer);
  465. document.body.onclick = (e) => {
  466. //console.log(e);
  467. if ((e.target.nodeName == "IMG" && e.target.className === "tyc-image-preview")) {
  468. let imgContainer = e.path.find(
  469. (ele) => {
  470. try {
  471. //console.log(ele);
  472. return ele.className.includes("tyc-img-item-container");
  473. }
  474. catch {
  475. }
  476. }
  477. )
  478. let path = imgContainer.getElementsByTagName("img")[0].src;
  479. try {
  480. let container = document.querySelector(".show-big-image");
  481. if (container.getElementsByTagName("img")[0].src === path) {
  482. container.remove();
  483. return;
  484. } else {
  485. container.remove();
  486. }
  487. }
  488. catch {
  489. }
  490. document.body.insertAdjacentHTML("beforeend", showBigImage);
  491. let showItem = `<img src="${path}"/>`
  492. document.querySelector(".show-big-image").insertAdjacentHTML("beforeend", showItem);
  493. let tempImg = document.querySelector(".show-big-image img");
  494. let dWidth = (window.innerWidth - tempImg.width) / 2;
  495. let dHeight = (window.innerHeight - tempImg.height) / 2;
  496. document.querySelector(".show-big-image").style.left = dWidth + "px";
  497. document.querySelector(".show-big-image").style.top = dHeight + "px";
  498. } else if (e.target.parentElement.className === "show-big-image") {
  499. try {
  500. document.querySelector(".show-big-image").remove();
  501. }
  502. catch
  503. {
  504. }
  505. } else if (e.target.classList[1] == "bi-download" || e.path.find(isDownload) != undefined) {
  506. let imgContainer = e.path.find(
  507. (ele) => {
  508. try {
  509. //console.log(ele);
  510. return ele.className.includes("tyc-img-item-container");
  511. }
  512. catch {
  513. }
  514. }
  515. )
  516. let path = imgContainer.getElementsByTagName("img")[0].src;
  517. let filename;
  518. if (path.indexOf("/") > 0)//如果包含有"/"号 从最后一个"/"号+1的位置开始截取字符串
  519. {
  520. filename = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
  521. }
  522. else {
  523. filename = path;
  524. }
  525. //console.log("download start" + path + " " + filename);
  526. GM_download(path, "pic");
  527. } else if (e.target.classList[1] == "bi-check" || e.path.find(isSelect) != undefined) {
  528. let checkSvg = e.path.find((ele) => ele.classList[1] === "bi-check");
  529. let currentImgIndex = parseInt(checkSvg.dataset.value);
  530. let container = e.path.find((ele) => ele.className === `tyc-img-item-container-${currentImgIndex}`);
  531. if (imgSelected.includes(currentImgIndex)) {
  532. imgSelected.splice(imgSelected.indexOf(currentImgIndex), 1);
  533. checkSvg.style.color = "black";
  534. container.style.border = "1px solid #99d";
  535. } else {
  536. imgSelected.push(currentImgIndex);
  537. checkSvg.style.color = "white";
  538. container.style.border = "1px solid white";
  539. }
  540. zipImgSelected=imgSelected;
  541. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgSelected.length}/${imgUrls.length}${langSet.fetchDoneTip2}`;
  542. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  543. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  544. zipImgWaitDownload=cutoffNotBase64Img(zipImgWaitDownload);
  545. }
  546. }
  547. document.querySelector(".btn-close").onclick = (e) => {
  548. document.querySelector(".tyc-image-container").remove();
  549. }
  550. document.querySelector(".btn-download").onclick = (e) => {
  551. if (imgWaitDownload.length >= 1) {
  552. //console.log(imgWaitDownload);
  553. imgWaitDownload.forEach(async (img, index) => {
  554. //let filename = `pic-${index}.jpg`;
  555. //filename=filename.replace(/\\/g, '/').replace(/\/{2,}/g, '/');
  556. await GM_download(img, `pic-${index}`);
  557. });
  558. } else {
  559. alert(`${langSet.selectAlert}`);
  560. }
  561. }
  562. document.querySelector(".btn-zipDownload").onclick = (e) => {
  563. //console.log(zipImgWaitDownload);
  564. try {
  565. if (zipImgWaitDownload.length >= 1) {
  566. //console.log(zipImgWaitDownload);
  567. zipImgWaitDownload.forEach(async (img, index) => {
  568. let fileExt = img.substring(img.indexOf("image/") + 6, img.indexOf(";"))
  569. fileExt=fileExt.includes("svg")?"svg":fileExt;
  570. let filename = `pic${index}.${fileExt}`;
  571. zipSubFoler.file(filename, img.split(",")[1], { base64: true });
  572. });
  573. zipFolder.generateAsync({ type: "blob" })
  574. .then(function (content) {
  575. // see FileSaver.js
  576. saveAs(content, "pics.zip");
  577. zipFolder.remove("pics");
  578. zipSubFoler = zipFolder.folder('pics');
  579. });
  580. } else {
  581. alert(`${langSet.selectAlert}`);
  582. }
  583. } catch (error) {
  584. //console.log(error);
  585. }
  586.  
  587. }
  588. document.querySelector(".tyc-cors").onmouseover=e=>{
  589. e.preventDefault();
  590. document.querySelector(".tyc-tip").style.display="block";
  591. }
  592. document.querySelector(".tyc-cors").onmouseout=e=>{
  593. e.preventDefault();
  594. document.querySelector(".tyc-tip").style.display="none";
  595. }
  596. document.body.onchange = (e) => {
  597. if (e.target.className.includes("width-check")) {
  598. GM_setValue('width-check', e.target.checked);
  599. }
  600. if (e.target.className.includes("height-check")) {
  601. GM_setValue('height-check', e.target.checked);
  602. }
  603. if (e.target.className.includes("cors-check")) {
  604. GM_setValue('cors-check', e.target.checked);
  605. if (document.querySelector(".cors-check").checked) {
  606. fetchBase64ImgsThenPushToZipArray();
  607. }
  608. }
  609. if (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")) {
  610. GM_setValue(e.target.className, e.target.value);
  611. }
  612. (e.target.className.includes("width-check") || e.target.className.includes("height-check") ||
  613. (e.target.nodeName === "INPUT" && e.target.type === "text" && e.target.className.includes("value")))
  614. && (clean(), init());
  615. }
  616. document.querySelector(".select-all").onchange = (e) => {
  617. if (document.querySelector(".select-all").checked) {
  618. imgWaitDownload = filteredImgUrls;
  619. zipImgWaitDownload=cutoffNotBase64Img(zipFilteredImgUrls);
  620. } else {
  621. imgWaitDownload=transIndexToLink(filteredImgUrls,imgSelected);
  622. zipImgWaitDownload=transIndexToLink(zipFilteredImgUrls,zipImgSelected);
  623. }
  624. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgWaitDownload.length}/${filteredImgUrls.length}${langSet.fetchDoneTip2}`;
  625. }
  626.  
  627. document.querySelector(".tyc-extend-btn").onclick=e=>{
  628. if(document.querySelector(".tyc-extend-btn").classList.contains("extend-open")){
  629. document.querySelector(".tyc-extend-btn").classList.remove("extend-open");
  630. document.querySelector(".tyc-extend-set").style.display="none";
  631. document.querySelector(".tyc-extend-btn").style.color="black";
  632. document.querySelector(".tyc-extend-btn").innerHTML=`<span>更多设置 </span>
  633. <span style="top: 3px;position: relative;">
  634. <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">
  635. <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"/>
  636. <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"/>
  637. </svg>
  638. </span> `
  639. ;
  640. }else{
  641. document.querySelector(".tyc-extend-btn").classList.add("extend-open");
  642. document.querySelector(".tyc-extend-set").style.display="flex";
  643. document.querySelector(".tyc-extend-btn").style.color="#f50";
  644. document.querySelector(".tyc-extend-btn").innerHTML=`<span>收起 </span>
  645. <span style="top: 3px;position: relative;">
  646. <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">
  647. <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"/>
  648. <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"/>
  649. </svg>
  650. </span> `
  651.  
  652. }
  653. }
  654.  
  655.  
  656. init();
  657. function init() {
  658. filteredImgUrls = imgUrls;
  659. filteredImgUrls=autoBigImage.getBigImageArray(filteredImgUrls);
  660. getSavedValue();
  661. if (document.querySelector(".width-check").checked) {
  662. filteredImgUrls = filteredImgUrls.filter(filterByWidth);
  663. }
  664. if (document.querySelector(".height-check").checked) {
  665. filteredImgUrls = filteredImgUrls.filter(filterByHeight);
  666. }
  667. zipFilteredImgUrls = filteredImgUrls;
  668. if (document.querySelector(".cors-check").checked) {
  669. fetchBase64ImgsThenPushToZipArray();
  670. }
  671. showImage(filteredImgUrls);
  672. }
  673. function clean() {
  674. imgWaitDownload = [];
  675. imgSelected = [];
  676. document.querySelector(".num-tip").innerText = `${langSet.fetchDoneTip1Type2}${imgSelected.length}/${imgUrls.length}${langSet.fetchDoneTip2}`;
  677. document.querySelector(".tyc-image-wrapper").innerHTML = "";
  678. }
  679. function isDownload(ele) {
  680. return ele.className == "download-direct";
  681. }
  682. function isSelect(ele) {
  683. return ele.className == "select-image";
  684. }
  685. function transIndexToLink(WholeImgs,selectedImgs) {
  686. let transedImgs=[];
  687. selectedImgs.forEach((imgIndex, index) => {
  688. transedImgs.push(WholeImgs[imgIndex]);
  689. });
  690. return transedImgs;
  691. }
  692. function showImage(filtedImgUrls) {
  693. filtedImgUrls.forEach((img, index) => {
  694. if (window.location.href.includes("huaban.com")) {
  695. if (img.includes("/webp")) {
  696. img = img.replace(/\/webp/g, "/png");
  697. }
  698. }
  699. let insertImg = `<div class="tyc-img-item-container-${index}" style="text-align:center;font-size:0px;
  700. margin:5px;border:1px solid #99d;border-radius:3px;
  701. ">
  702. <img class="tyc-image-preview" src="${img}"/ style="width:auto;height:200px;"></div>`
  703. document.querySelector(".tyc-image-wrapper").insertAdjacentHTML("beforeend", insertImg);
  704. let naturalW = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalWidth;
  705. let naturalH = document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalHeight;
  706. let imgInfoContainer = `
  707. <div style="font-size:0px;background-color:rgba(100,100,100,0.6);height:30px;position:relative;">
  708. </div>
  709. `;
  710. let thisImgContainer = document.querySelector(`.tyc-img-item-container-${index}`);
  711. let imgContainerWidth = thisImgContainer.getBoundingClientRect().width;
  712. let imgInfo = `
  713. <span style="font-size:16px;position:absolute;left:calc(50% - 80px);top:7px;">${naturalW}X${naturalH}</span>
  714. `;
  715. /*
  716. <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;">
  717. <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"/>
  718. </svg>*/
  719. let downAndFullBtn = `
  720. <span style="position:absolute;right:calc(50% - 30px);top:2px;border:1px solid #333;
  721. width:26px;height:26px;border-radius:20px;" class="select-image" data-value="${index}">
  722. <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check" viewBox="0 0 16 16" style="position:absolute;top:-1px;right:-2px;width:30px;height:30px;" data-value="${index}">
  723. <path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z"/>
  724. </svg>
  725. </span>
  726. <span style="position:absolute;right:calc(50% - 60px);top:2px;border:1px solid #333;
  727. width:26px;height:26px;border-radius:20px;
  728. " class="download-direct">
  729. <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;">
  730. <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"/>
  731. <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"/>
  732. </svg>
  733. </span>
  734. `;
  735. let downloadBtn = `
  736. <span style="position:absolute;right:calc(50% - 15px);top:2px;border:1px solid #333;
  737. width:26px;height:26px;border-radius:20px;
  738. " class="download-direct">
  739. <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;">
  740. <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"/>
  741. <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"/>
  742. </svg>
  743. </span>
  744. `
  745. thisImgContainer.insertAdjacentHTML("beforeend", imgInfoContainer);
  746. let thisImgInfoContainer = thisImgContainer.querySelector("div");
  747. let rectWidth = parseInt(thisImgContainer.getBoundingClientRect().width);
  748. if (rectWidth > 120) {
  749. thisImgInfoContainer.insertAdjacentHTML("beforeend", imgInfo);
  750. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  751. } else if (rectWidth <= 120 && rectWidth >= 50) {
  752. thisImgInfoContainer.insertAdjacentHTML("beforeend", downAndFullBtn);
  753. thisImgInfoContainer.getElementsByClassName("select-image")[0].style.right = "50%";
  754. thisImgInfoContainer.getElementsByClassName("download-direct")[0].style.right = "calc(50% - 30px)";
  755. } else {
  756. thisImgInfoContainer.insertAdjacentHTML("beforeend", downloadBtn);
  757. }
  758. ////console.log(img);
  759. });
  760. }
  761. function filterByWidth(src) {
  762. let tempImg = new Image();
  763. tempImg.src = src;
  764. if (tempImg.width >= parseInt(document.querySelector(".width-value-min").value)
  765. && tempImg.width <= parseInt(document.querySelector(".width-value-max").value)) {
  766. return src;
  767. }
  768. }
  769. function filterByHeight(src) {
  770. let tempImg = new Image();
  771. tempImg.src = src;
  772. if (tempImg.height >= parseInt(document.querySelector(".height-value-min").value)
  773. && tempImg.height <= parseInt(document.querySelector(".height-value-max").value)) {
  774. return src;
  775. }
  776. }
  777. function getSavedValue() {
  778. if(GM_getValue("width-check")!=undefined){
  779. //console.log(GM_getValue("width-check"));
  780. (document.querySelector(".width-check").checked = GM_getValue("width-check"));
  781. }
  782. if(GM_getValue("height-check")!=undefined){
  783. (document.querySelector(".height-check").checked = GM_getValue("height-check"));
  784. }
  785. if(GM_getValue("cors-check")!=undefined){
  786. (document.querySelector(".cors-check").checked = GM_getValue("cors-check"));
  787. }
  788. GM_getValue("width-value-min") && (document.querySelector(".width-value-min").value = GM_getValue("width-value-min"));
  789. GM_getValue("width-value-max") && (document.querySelector(".width-value-max").value = GM_getValue("width-value-max"));
  790. GM_getValue("height-value-min") && (document.querySelector(".height-value-min").value = GM_getValue("height-value-min"));
  791. GM_getValue("height-value-max") && (document.querySelector(".height-value-max").value = GM_getValue("height-value-max"));
  792. }
  793. function fetchBase64ImgsThenPushToZipArray() {
  794. zipFilteredImgUrls.forEach((imgUrl, urlIndex) => {
  795. if (imgUrl.includes("data:image")) {
  796. return;
  797. }
  798. /* fetch(imgUrl,{
  799. method: "get",
  800. mode: 'cors'
  801. }).then(response=>{
  802. if (!response.ok) {
  803. throw new Error('Network response was not OK');
  804. }
  805. return response.blob();
  806. }).then(myBlob=>{
  807. var blob = myBlob
  808. let oFileReader = new FileReader();
  809. oFileReader.onloadend = function (e) {
  810. let base64 = e.target.result;
  811. //console.log("》》", base64)
  812. if (base64.includes("data:image")) {
  813. zipFilteredImgUrls[urlIndex] = base64;
  814. //zipImgWaitDownload.push(base64);
  815. }
  816. };
  817. oFileReader.readAsDataURL(blob);
  818. })
  819. .catch((error)=>{ */
  820. try {
  821. GM_xmlhttpRequest({
  822. method: "get",
  823. url: imgUrl,
  824. responseType: "blob",
  825. onload: function (r) {
  826. var blob = r.response;
  827. let oFileReader = new FileReader();
  828. oFileReader.onloadend = function (e) {
  829. let base64 = e.target.result;
  830. if (base64.startsWith("data:image")) {
  831. zipFilteredImgUrls[urlIndex] = base64;
  832. //zipImgWaitDownload.push(base64);
  833. }
  834. };
  835. oFileReader.readAsDataURL(blob);
  836. }
  837. });
  838. } catch (error) {
  839. }
  840.  
  841. //})
  842. })
  843. }
  844. function cutoffNotBase64Img(imgsUrlArray) {
  845. let resultArr = [];
  846. imgsUrlArray.forEach((imgUrl, urlIndex) => {
  847. if (imgUrl.startsWith("data:image")&&imgUrl.includes("base64")) {
  848. resultArr.push(imgUrl);
  849. }
  850. }
  851. );
  852. return resultArr;
  853. }
  854. //下面这个括号是wrapper的括号
  855. }
  856. })();