理论资源下载器

一键导出图片

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        理论资源下载器
// @namespace    https://qinlili.bid
// @version      0.1
// @description  一键导出图片
// @author       琴梨梨
// @match       */Service/?logic=PDFReaderController&call=readPDF&*
// @grant        none
// @run-at        document-end
// ==/UserScript==

(function() {
    'use strict';
    document.body.oncontextmenu = ""
    var pageTotal = 0;
    var picUrl = ""
    //从0开始
    var pageCurrent = 1;
    let urlParams = new URLSearchParams(window.location.search);
    var bookid = urlParams.get("bookid");
    //下载指定页面图片
    function downloadPic(page) {
        picUrl = window.location.origin + "/Service/?logic=PDFReaderController&call=ReadImg&imgurl=" + btoa(bookid + "(" + page + ").jpg");
        fetch(picUrl).then(res => res.blob().then(blob => {
            var a = document.createElement('a');
            var url = window.URL.createObjectURL(blob);
            var filename = page + '.jpg';
            a.href = url;
            a.download = filename;
            a.click();
            window.URL.revokeObjectURL(url);
        }))
    }
    //批量下载
    function batchDownload() {
        pageTotal = Number(document.getElementById("pageinfo").innerText.replace("共","").replace("页",""))
        nextPage();
    }
    //太快了会丢页,手动减速
    function nextPage(){
        if(pageCurrent<=pageTotal){
            downloadPic(pageCurrent);
            pageCurrent++;
            setTimeout(nextPage,250);}
    }
    //创建下载按钮
    var downloadBtn = document.createElement("a");
    downloadBtn.innerText = "批量下载全书";
    downloadBtn.onclick = function () { batchDownload() };
    document.querySelector("#ReaderTool").appendChild(downloadBtn);

})();