图片下载器

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

当前为 2021-01-24 提交的版本,查看 最新版本

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