图片下载器

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