图片下载器

可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网这种,不能右键保存图片的网站,提取之后,可以右键保存,或者直接下载所有的图片。其他的淘宝、天猫电商图片批量下载,youtube、B站封面下载,等等都可以的。点击右键-tampermonkey-图片下载器,按这个顺序使用。

目前為 2021-01-23 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 图片下载器
  3. // @name Image Downloader
  4. // @namespace http://tampermonkey.net/
  5. // @description 可以在绝大多数网站提取并批量下载图片。尤其是类似于千库网这种,不能右键保存图片的网站,提取之后,可以右键保存,或者直接下载所有的图片。其他的淘宝、天猫电商图片批量下载,youtube、B站封面下载,等等都可以的。点击右键-tampermonkey-图片下载器,按这个顺序使用。
  6. // @version 1.8
  7. // @author 桃源隐叟
  8. // @include *
  9. // @grant GM_openInTab
  10. // @grant GM_download
  11. // @run-at context-menu
  12. // @match *
  13. // @match https://www.bilibili.com/
  14. // @match https://588ku.com/
  15. // @homepageURL https://github.com/taoyuancun123/modifyText/blob/master/modifyText.js
  16. // @supportURL https://greasyfork.org/zh-CN/scripts/419894/feedback
  17. //@updateURL https://greasyfork.org/zh-CN/scripts/419894
  18. //@downloadURL https://greasyfork.org/zh-CN/scripts/419894
  19. //@installURL https://greasyfork.org/zh-CN/scripts/419894
  20. // ==/UserScript==
  21.  
  22. (function () {
  23. 'use strict';
  24.  
  25. try{
  26. document.querySelector(".tyc-image-container").remove();
  27. }catch{
  28.  
  29. }
  30. let imgUrls = [];
  31. let bodyStr = document.body.innerHTML;
  32.  
  33. try {
  34. let imgEles = document.getElementsByTagName("img")
  35.  
  36. for (let i = 0; i < imgEles.length; i++) {
  37. //console.log(imgEles[i].src);
  38. if (!imgUrls.includes(imgEles[i].src)) {
  39. imgUrls.push(imgEles[i].src);
  40. }
  41.  
  42.  
  43. }
  44.  
  45.  
  46. } catch {
  47. //alert("error");
  48. }
  49.  
  50.  
  51. try {
  52. let imgRegs = bodyStr.match(/(?<=background-image:\s*url\()(\S+)(?=\))/g);
  53.  
  54. for (let i = 0; i < imgRegs.length; i++) {
  55. //console.log(imgRegs[i]);
  56. if (!imgUrls.includes(imgRegs[i].replace(/&quot;/g, ""))) {
  57. imgUrls.push(imgRegs[i].replace(/&quot;/g, ""));
  58. }
  59.  
  60. }
  61. } catch {
  62. //alert("error");
  63. }
  64.  
  65.  
  66. let imgContainer = `
  67. <div class="tyc-image-container" style="position:fixed;
  68. top:0px;right:0px;width:50vw;z-index:2147483646;
  69. background-color: #dedede;
  70. border: 1px solid #aaa;
  71. overflow:scroll;height:100%;
  72. ">
  73. <div class="control-section" style="width:46vw;
  74. position:fixed;right:30px;
  75. top:0px;display:block;
  76. height:40px;line-height:40px;
  77. background:#eee;border:1px solid #aaa;border-radius:10px;">
  78. <input class="select-all" type="checkbox" name="select-all" value="select-all">全选
  79. <button class="btn-download" style="border:1px solid #aaa;border-radius:5px;
  80. height:32px;line-height:32px;
  81. margin:0px;padding:0 5px;
  82. ">download</button>
  83. <button class="btn-close" style="font-size:20px;position:absolute;
  84. right:30px;top:4px;
  85. height:32px;line-height:32px;
  86. margin:0px;
  87. border-radius:10px;border:1px solid #aaa;
  88. width:30px;">X</button>
  89. </div>
  90. <div class="tyc-image-wrapper" style="margin-top:42px;display:flex;justify-content:center;
  91. align-items:center;flex-wrap:wrap;">
  92. </div>
  93. </div>
  94. `
  95.  
  96. let showBigImage=`
  97. <div class="show-big-image" style="position:fixed;left:30%;top:30%;z-index:2147483647;">
  98. </div>
  99. `
  100.  
  101. document.body.insertAdjacentHTML("afterbegin", imgContainer);
  102.  
  103. document.querySelector(".btn-close").onclick=(e)=>{
  104. document.querySelector(".tyc-image-container").remove();
  105. }
  106.  
  107. document.querySelector(".btn-download").onclick=(e)=>{
  108. if(document.querySelector(".select-all").checked){
  109. imgUrls.forEach((img,index) => {
  110. GM_download(img, `pic-${index}`);
  111. });
  112. }else{
  113. alert("请勾选全选,下载全部,或者手动在图片上右键另存为指定图片");
  114. }
  115. }
  116.  
  117.  
  118. imgUrls.forEach((img,index) => {
  119. let insertImg = `<div class="tyc-img-item-container-${index}" style="text-align:center;font-size:12px;margin:5px;">
  120. <img class="tyc-image-preview" src="${img}"/ style="width:auto;height:200px;"></div>`
  121. document.querySelector(".tyc-image-wrapper").insertAdjacentHTML("beforeend", insertImg);
  122. let naturalW=document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalWidth;
  123. let naturalH=document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalHeight;
  124.  
  125. let imgInfo=`<p style="line-height:14px;height:14px;font-size:12px;">${naturalW}X${naturalH}</p>`;
  126. document.querySelector(`.tyc-img-item-container-${index}`).insertAdjacentHTML("beforeend", imgInfo);
  127. //console.log(img);
  128. });
  129.  
  130. document.body.onclick=(e)=>{
  131. if(e.target.nodeName=="IMG" && e.target.className==="tyc-image-preview"){
  132. try{
  133. document.querySelector(".show-big-image").remove();
  134. }
  135. catch{
  136.  
  137. }
  138. document.body.insertAdjacentHTML("beforeend",showBigImage);
  139. let showItem=`<img src="${e.target.src}"/>`
  140.  
  141. document.querySelector(".show-big-image").insertAdjacentHTML("beforeend",showItem);
  142.  
  143. let tempImg=document.querySelector(".show-big-image img");
  144.  
  145. let dWidth=(window.innerWidth-tempImg.width)/2;
  146. let dHeight=(window.innerHeight-tempImg.height)/2;
  147.  
  148. document.querySelector(".show-big-image").style.left=dWidth+"px";
  149. document.querySelector(".show-big-image").style.top=dHeight+"px";
  150. }else if(e.target.parentElement.className==="show-big-image"){
  151. document.querySelector(".show-big-image").remove();
  152. }
  153. }
  154.  
  155.  
  156. })();