图片提取

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

Stan na 08-01-2021. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name            图片提取
// @name:en         Fetch Image
// @namespace       http://tampermonkey.net/
// @description     可以提取绝大部分网站的图片,如千库网、包图网、花瓣网等等,以及youtube/bilibili的视频封面等等。点击右键后,即可看到图片提取选项
// @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
// @version         1.1
// @author          桃源隐叟
// @include         *
// @grant           GM_openInTab
// @run-at            context-menu
// @match        *
// @match        https://www.bilibili.com/
// @match        https://588ku.com/
// @homepageURL       https://github.com/taoyuancun123/modifyText/blob/master/modifyText.js
// @supportURL        https://greasyfork.org/zh-CN/scripts/419894/feedback
// ==/UserScript==

(function () {
    'use strict';

    try{
        document.querySelector(".tyc-image-container").remove();
    }catch{

}
        let imgUrls = [];
        let bodyStr = document.body.innerHTML;

        try {
        let imgEles = document.getElementsByTagName("img")

        for (let i = 0; i < imgEles.length; i++) {
            //console.log(imgEles[i].src);
            if (!imgUrls.includes(imgEles[i].src)) {
                imgUrls.push(imgEles[i].src);
            }


        }


} catch {
 //alert("error");
 }


 try {
 let imgRegs = bodyStr.match(/(?<=background-image:\s*url\()(\S+)(?=\))/g);

for (let i = 0; i < imgRegs.length; i++) {
    //console.log(imgRegs[i]);
    if (!imgUrls.includes(imgRegs[i].replace(/&quot;/g, ""))) {
        imgUrls.push(imgRegs[i].replace(/&quot;/g, ""));
    }

}
} catch {
    //alert("error");
}


    let imgContainer = `
    <div class="tyc-image-container" style="position:fixed;
    top:0px;right:0px;width:50vw;display:flex;justify-content:center;
    align-items:center;flex-wrap:wrap;z-index:2147483646;
    background-color: #dedede;
    border: 1px solid #aaa;
    overflow:scroll;height:100%;
    ">
    <button style="font-size:30px;position:fixed;top:0px;right:30px;border-radius:10px;">X</button>
    </div>
    `

    let showBigImage=`
        <div class="show-big-image" style="position:fixed;left:30%;top:30%;z-index:2147483647;">
        </div>
    `

    document.body.insertAdjacentHTML("afterbegin", imgContainer);

document.querySelector(".tyc-image-container button").onclick=(e)=>{
    document.querySelector(".tyc-image-container").remove();
}
imgUrls.forEach((img,index) => {
    let insertImg = `<div class="tyc-img-item-container-${index}" style="text-align:center;font-size:12px;margin:5px;">
<img class="tyc-image-preview" src="${img}"/ style="width:auto;height:200px;"></div>`
        document.querySelector(".tyc-image-container").insertAdjacentHTML("beforeend", insertImg);
        let naturalW=document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalWidth;
        let naturalH=document.querySelector(`.tyc-img-item-container-${index} .tyc-image-preview`).naturalHeight;

        let imgInfo=`<p style="line-height:14px;height:14px;font-size:12px;">${naturalW}X${naturalH}</p>`;
        document.querySelector(`.tyc-img-item-container-${index}`).insertAdjacentHTML("beforeend", imgInfo);
        //console.log(img);
    });

document.body.onclick=(e)=>{
    if(e.target.nodeName=="IMG" && e.target.className==="tyc-image-preview"){
        try{
            document.querySelector(".show-big-image").remove();
        }
        catch{

    }
            document.body.insertAdjacentHTML("beforeend",showBigImage);
        let showItem=`<img src="${e.target.src}"/>`

            document.querySelector(".show-big-image").insertAdjacentHTML("beforeend",showItem);

            let tempImg=document.querySelector(".show-big-image img");

            let dWidth=(window.innerWidth-tempImg.width)/2;
            let dHeight=(window.innerHeight-tempImg.height)/2;

            document.querySelector(".show-big-image").style.left=dWidth+"px";
            document.querySelector(".show-big-image").style.top=dHeight+"px";
        }else if(e.target.parentElement.className==="show-big-image"){
            document.querySelector(".show-big-image").remove();
        }
    }


})();