图片提取

可以提取绝大部分网站的图片,如千库网、包图网、花瓣网等等,以及youtube/bilibili的视频封面等等。点击右键后,即可看到图片提取选项

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

  1. // ==UserScript==
  2. // @name 图片提取
  3. // @name:en Fetch Image
  4. // @namespace http://tampermonkey.net/
  5. // @description 可以提取绝大部分网站的图片,如千库网、包图网、花瓣网等等,以及youtube/bilibili的视频封面等等。点击右键后,即可看到图片提取选项
  6. // @description:en It can extract the images of most websites, such as qianku.com, baotu.com, huaban.com, and the video cover of YouTube / BiliBili. Right click to see the image extraction options
  7. // @version 1.0
  8. // @author 桃源隐叟
  9. // @include *
  10. // @grant GM_openInTab
  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. // ==/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;display:flex;justify-content:center;
  65. align-items:center;flex-wrap:wrap;z-index:2147483646;
  66. background-color: #dedede;
  67. border: 1px solid #aaa;
  68. overflow:scroll;height:100%;
  69. ">
  70. <button style="font-size:30px;position:fixed;top:0px;right:30px;border-radius:10px;">X</button>
  71. </div>
  72. `
  73.  
  74. let showBigImage=`
  75. <div class="show-big-image" style="position:fixed;left:30%;top:30%;z-index:2147483647;">
  76. </div>
  77. `
  78.  
  79. document.body.insertAdjacentHTML("afterbegin", imgContainer);
  80.  
  81. document.querySelector(".tyc-image-container button").onclick=(e)=>{
  82. document.querySelector(".tyc-image-container").remove();
  83. }
  84. imgUrls.forEach((img,index) => {
  85. let insertImg = `<div class="tyc-img-item-container-${index}" style="text-align:center;font-size:12px;margin:5px;">
  86. <img class="tyc-image-preview" src="${img}"/ style="width:auto;height:200px;"></div>`
  87. document.querySelector(".tyc-image-container").insertAdjacentHTML("beforeend", insertImg);
  88. let naturalW=document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalWidth;
  89. let naturalH=document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalHeight;
  90.  
  91. let imgInfo=`<p style="line-height:14px;height:14px;font-size:12px;">${naturalW}X${naturalH}</p>`;
  92. document.querySelector(`.tyc-img-item-container-${index}`).insertAdjacentHTML("beforeend", imgInfo);
  93. //console.log(img);
  94. });
  95.  
  96. document.body.onclick=(e)=>{
  97. if(e.target.nodeName=="IMG" && e.target.className==="tyc-image-preview"){
  98. try{
  99. document.querySelector(".show-big-image").remove();
  100. }
  101. catch{
  102.  
  103. }
  104. document.body.insertAdjacentHTML("beforeend",showBigImage);
  105. let showItem=`<img src="${e.target.src}"/>`
  106.  
  107. document.querySelector(".show-big-image").insertAdjacentHTML("beforeend",showItem);
  108.  
  109. let tempImg=document.querySelector(".show-big-image img");
  110.  
  111. let dWidth=(window.innerWidth-tempImg.width)/2;
  112. let dHeight=(window.innerHeight-tempImg.height)/2;
  113.  
  114. document.querySelector(".show-big-image").style.left=dWidth+"px";
  115. document.querySelector(".show-big-image").style.top=dHeight+"px";
  116. }else if(e.target.parentElement.className==="show-big-image"){
  117. document.querySelector(".show-big-image").remove();
  118. }
  119. }
  120.  
  121.  
  122. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址