MrCong全量加載 图片查看

MrCong全量加載 图片查看123

Versión del día 11/03/2022. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name         MrCong全量加載 图片查看
// @namespace    http://tampermonkey.net/
// @version      0.29
// @description  MrCong全量加載 图片查看123
// @author       LARA_SSR
// @match        https://mrcong.com/*/
// @exclude      https://mrcong.com/tag/*
// @exclude      https://mrcong.com/category/*
// @exclude      https://mrcong.com/sets/*
// @exclude      https://mrcong.com/top*/*
// @exclude      https://mrcong.com/tim-kiem/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// @require      https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
// @require      https://cdn.staticfile.org/viewerjs/1.10.4/viewer.min.js
// ==/UserScript==

(async function () {
    let addStyle = function (aCss) {
        let head = document.getElementsByTagName('head')[0];
        if (head) {
            let style = document.createElement('style');
            style.setAttribute('type', 'text/css');
            style.textContent = aCss;
            head.appendChild(style);
            return style;
        }
        return null;
    }

    //获取页数
    let paginationClass = "div .page-link";
    let length = 0;
    let paginationExist = false;
    $(paginationClass).each(function () {
        if (paginationExist == true) {
            return false;
        }
        length = $(this).find("a").length;
        paginationExist = true;
        //console.log(linkArr);
        console.log("页数:" + length);
    });

    //标题
    addStyle(`.titleHrefs .postTagHrefs{
        display: inline-block;
        background-color: #27282d;
        border: 1px solid;
        border-radius: 4px;
    }
    #title_info{
        color: pink;
        display: inline-block;
    }
    #separate{
        display: inline-block;
        color:white;
    }
    #downHref{
        display: inline-block;
        background-color: #815c94;
        border: 1px solid;
        border-radius: 4px;
        color: rgba(129,92,148,0.8);
    }`);
    let titleHrefs = $("<div class = titleHrefs></div>");
    let postTagHrefs = $("<div class = postTagHrefs></div>");

    await new Promise(function (resolve) {
        $("#crumbs a").each(function (index, value) {
            let title = $(this).attr("id", "title_info");
            titleHrefs.append(title);
            // console.log(title);
            let p3 = $("<div id = separate>\xa0/\xa0</div>");
            titleHrefs.append(p3);
        });
        $(".post-tag a").each(function (index, value) {
            let title = $(this).attr("id", "title_info");
            postTagHrefs.append(title);
            // console.log(title);
            let p3 = $("<div id = separate>\xa0/\xa0</div>");
            postTagHrefs.append(p3);
        });
        resolve();
    });

    let password = $("strong+input[value]").attr('value');
    console.log("Password: " + password);

    let patt = /(?<=Dung lượng: )[0-9]+[A-Z]B/g
    let inerBoxStr = $(".box-inner-block").text()
    let imgSize = inerBoxStr.match(patt)[0];
    console.log(imgSize);

    $("p[style] a").each(function (index, value) {

        let downHref = $("<div id = downHref></div>");
        let itemTitleHref = $("<a style='color:white;'>图片下载</a>").attr("href", $(this)[0].href).text(`图片下载链接[ ${index+1} ]`);

        downHref.append(itemTitleHref);
        titleHrefs.append(downHref);
        let p3 = $("<div id = separate>\xa0/\xa0</div>");
        titleHrefs.append(p3);
    })
    let p3 = $("<div id = separate>\xa0/\xa0</div>");
    titleHrefs.append($("<div style = 'color: white; display: inline-block;'></div>").text(`解压密码: (${password})`))
    titleHrefs.append(p3);
    titleHrefs.append($("<div style = 'color: white; display: inline-block;'></div>").text(`图片大小: (${imgSize})`))
    /*!
     * Viewer.js v1.10.4
     * https://fengyuanchen.github.io/viewerjs
     *
     * Copyright 2015-present Chen Fengyuan
     * Released under the MIT license
     *
     * Date: 2022-02-13T08:39:57.620Z
     */
    //viewerjsCSS
    let viewerCssLink = "https://cdn.staticfile.org/viewerjs/1.10.4/viewer.min.css";
    let viewerCssData = await Get(viewerCssLink);
    addStyle(viewerCssData);

    addStyle(`ul li{
        list-style-type:none;
    } 
    body{
        background:#4a4035;
    } 
    #viewer{
        padding:0px;margin:0px
    }
    .imgbox{
        position: relative;
        overflow: hidden;
    }
    .imgnum{
        position: absolute;
        font-size:100%;
        left: 5px;
        top: 5px;
        background: #17A1FF;
        background: rgba(23,161,255,0.5);
        z-index: 100;
        padding: 0px 5px;
        color: #f9f9f9;
        color: rgba(249,249,249,0.8);
        border-radius: 2px;
    }`);

    'use strict';
    $("body").empty();
    let i = 1;
    let str3 = self.location.href;
    let newStr = str3.replace(/-anh.+/g, "");
    let link = "";
    let viewer2 = $('<ul id ="viewer"></ul>');
    $("body").append(viewer2);
    viewer2.append(titleHrefs);
    do {
        link = newStr + "-anh/" + i;
        let data = await Get(link);

        let image = $(".content img", data);
        image.each(function (item) {
            let imgli = $('<li class = "imgbox"></li>');
            let imageItem = '<img width= "100%" style="float: left;border-radius: 8px; margin: 1px" src="' + $(this)[0].src + '" >';

            //序号
            let stringNum = "<div class = 'imgnum'>{imgnum}</div>";
            let newStringNum = stringNum.replace('{imgnum}', ` `)
            imgli = imgli.prepend($(newStringNum));

            imgli = imgli.append(imageItem);
            viewer2.append(imgli)
        });

        i = i + 1;
        if (i === (length + 2)) {
            $(document).ready(function () {
                $("#viewer").after(postTagHrefs);
            });
        }
    } while (i < length + 2);

    setTimeout(() => {
        let viewer3 = new Viewer(document.getElementById('viewer'), {
            //inline:true,
            viewed() {}
        });
    }, 3000);
    // Your code here...

    let imgCount = $("#viewer img").length;
    console.log("imgCount: " + imgCount);

    $(".imgnum").each(function (index, value) {
        if (index < imgCount) {
            // console.log($(this));
            $(this).text(`[${index+1}/${imgCount}]`)
        } else {
            return false;
        }
    })

    //删除标题最后一个"/"
    $(document).ready(function () {
        // $(".titleHrefs div").eq(-1).remove();

        $(".postTagHrefs #separate").eq(-1).remove();
    });

    function Get(link) {
        return new Promise(function (resolve) {
            $.get(link, data => {
                resolve(data);
            })
        });
    }

})();