寂月download

寂月神社图片预览下使用的是复用页面,分辨率为300x300,本脚本为自动访问分辨率高的地址并下载图片。

Od 04.08.2021.. Pogledajte najnovija verzija.

// ==UserScript==
// @name         寂月download
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  寂月神社图片预览下使用的是复用页面,分辨率为300x300,本脚本为自动访问分辨率高的地址并下载图片。
// @description  v0.1版本进入页面后点击“获取”按钮,提示获取完成后点击“下载”按钮;目前仅能同时下载58张以下的图片。
// @description  v0.2版本进入页面后点击“获取”按钮,提示获取完成后点击“下载”按钮;目前由于服务器访问数量限制,超过59页将会以一页/s的速度访问(会消耗大量浏览器资源)。
// @description  本脚本不可用于商业行为,仅限交流自用!
// @author       香香不吃饭
// @match        https://www.jiyue.pro/*
// @require      http://code.jquery.com/jquery-1.11.0.min.js
// @require      https://cdn.bootcss.com/FileSaver.js/1.3.8/FileSaver.min.js
// @grant        GM_info
// @grant        GM_registerMenuCommand
// @grant        GM_xmlhttpRequest
// @grant        GM_download
// ==/UserScript==

(function() {
    'use strict';

    //创建隐藏a标签
    //var elea = document.createElement("a");
    //elea.setAttribute("id", "a");
    //elea.textContent="值";
    //elea.setAttribute("href", "www.baidu.com");


    //创建一个img标签
    //var eleimg = document.createElement("img");
    //eleimg.setAttribute("id", "img");
    // eleimg.textContent="值";
    //eleimg.setAttribute("class", "img-fluid lazyloaded");

    //创建数组来存储每张图片对应的src
    var imgUrl = [];

    var button = document.createElement("button"); //创建一个获取图片url按钮
    button.setAttribute("id", "btn");
    button.setAttribute("type", "button");
    button.textContent="获取";
    button.style.background = "#b46300";
    button.style.color = "white";
    button.style.cssText="padding:4px 0;position: absolute;top:-1px;right:45px;width:40px;height:35px";

    var button2 = document.createElement("button"); //创建一个下载图片按钮
    button2.setAttribute("id", "btn2");
    button2.setAttribute("type", "button");
    button2.textContent="下载";
    button2.style.background = "#b46300";
    button2.style.color = "white";
    button2.style.cssText="padding:4px 0;position: absolute;top:-1px;right:0px;width:40px;height:35px";

    var testdiv = document.getElementById("navbarNav");
    testdiv.appendChild(button);
    testdiv.appendChild(button2);
    //testdiv.appendChild(elea);
    //elea.appendChild(eleimg);

    //eleimg.style.display="none";

    //document.getElementById("elea").style.display="none";

    var newurl = "";
    var pagenum = 0; //图片页数
    var imgname = ''; //漫画名称

    var x = 1;

    //拿到当前页面所有预览图片对应的URL
    var baseUrl = window.location.href;

    button.onclick = function getimgurl(){
        pagenum = document.getElementsByClassName('badge badge-pill badge-secondary float-right')[0].innerText;
        pagenum = pagenum.substr(0,pagenum.length-1);
        imgname = document.getElementsByClassName('h4 font-weight-bold title mb-2')[0].innerText;

        //eleimg.setAttribute("alt",imgname);


        if(pagenum>59){

            alert("开始获取")
            //  for(let i = 1;i<=58;i++) {
            //      newurl = baseUrl + '/'+i
            //      geturl();
            //  }
            //setTimeout("is58()",1000)
            sleep(1000);

        }else{
            for(let i = 1;i<=pagenum;i++) {
                newurl = baseUrl + '/'+i
                geturl();
            }
        }

        alert("共获取"+pagenum+"页!点击下载按钮即可下载!")
        //console.log(imgUrl)

    }

    function sleep(n){
        if(x <= pagenum){
            newurl = baseUrl + '/'+x

            geturl();
            x = x+1

            var start = new Date().getTime();
            //  console.log('休眠前:' + start);
            while (true) {
                if (new Date().getTime() - start > n) {
                    break;
                }
            }
            // console.log('休眠后:' + new Date().getTime());
        }

        sleep(1000);
    }



    //ajax同步请求获取url
    function geturl(){
        $.ajax({
            type:'get',
            url:newurl,//这里是url
            async: false,
            //data就是内容了,也就是url网页中的内容
            success:function(data){
                //正则表达式截取图片url
                var srcReg = /"(.*?)"/g
                var arr = data.match(srcReg)[162]
                arr = arr.substr(1,arr.length-2)

                imgUrl.push(arr)
                console.log(arr)


            }
        });
    }

    button2.onclick = function downloadimg(){
        alert("开始下载!")
        for(let a=0;a<=imgUrl.length-1;a++){
            GM_download(imgUrl[a],"picture"+a);
        }


        //GM_download(imgUrl[0],"aaa");

    }



    //alert("获取完成!")

    // Your code here...
})();