Greasy Fork is available in English.

【书友互助】读秀超星龙岩全国图书馆参考联盟,直接下载PDF文件,绝大部分有目录书签。

读秀超星龙岩全国图书馆参考联盟,直接下载PDF文件,绝大部分有目录书签。

// ==UserScript==
// @name              【书友互助】读秀超星龙岩全国图书馆参考联盟,直接下载PDF文件,绝大部分有目录书签。
// @namespace         http://syhz.getpdf.online
// @version           0.0.16
// @description       读秀超星龙岩全国图书馆参考联盟,直接下载PDF文件,绝大部分有目录书签。
// @include			*search*
// @include			*bookDetail.jsp?*
// @include			*advsearch*
// @include			*book.do?go=guide*
// @include			*book.do?go=showmorelib*
// @include			*searchEBook*
// @include			*www.duxiu.com*
// @include			*img.duxiu.com*
// @include			*book.douban.com*
// @include			*product.dangdang.com*
// @include			*kongfz.com*
// @copyright		houge
// @grant			none
// @require      https://libs.baidu.com/jquery/2.0.0/jquery.min.js
// ==/UserScript==
//获取当前网页地址
var myurl = window.location.href;
//定义统一的样式
var mystyle = "font-family:Verdana;color:red;font-size:15px;font-weight:bold;text-align:center;margin-top:5px;margin-bottom:5px;";

var app = {
    run: function() {
        processUCDSRList();
        processUCDSR();
    }
};

function processUCDSRList() {
    //搜索页显示ssid
    var isSearch = myurl.indexOf("search?") != -1;
    var notBaoku = myurl.indexOf("book/search?") == -1;
    var notAdvsearch = myurl.indexOf("advsearch") == -1;
    if (isSearch && notAdvsearch && notBaoku) {
        var subdomain = document.getElementsByName("sp.subdomain")[0];
        if (typeof(subdomain) != "undefined") {
            var isDuxiu = subdomain.value == "book.duxiu.com";
            var isCcelib = subdomain.value == "book.ccelib.com";
            if (isDuxiu || isCcelib) {
                var mybooks = document.getElementsByClassName("books");
                for (var i = 0; i < mybooks.length; i++) {
                    var listDL = mybooks[i].querySelector("dl");
                    listDL.style.minHeight = "210px";

                    var ssid = GetSSIDDXID("ssid" + i, "dxid" + i);
                    var ssNode = CreateSSIDNode2(ssid, "myssid" + i);
                    var divImg = mybooks[i].querySelector(".divImg");

                    var infoAnchor = divImg.querySelector("a").href;
                    var oldstr = "bookDetail.jsp?dxNumber=";
                    var newstr = "book.do?go=showmorelib&type=1&dxid=";
                    var scgAnchor = "";
                    var csgbutton = document.createElement("a");
                    csgbutton.href = scgAnchor;
                    csgbutton.target = "_blank";

                    var csgP = document.createElement("p");
                    csgP.style = "text-align:center;";
                    csgP.appendChild(csgbutton);

                    divImg.appendChild(ssNode);
                    divImg.appendChild(csgP);
                };
            }
        }
        else {
            var mybooks = document.getElementsByClassName("book1");
            for (var i = 0; i < mybooks.length; i++) {
                var ssid = GetSSIDDXID("ssid" + i, "dxid" + i);
                var ssNode = CreateSSIDNode2(ssid, "myssid" + i);

                var infoUrl = document.getElementById("url" + i).value;
                var dxid = getValueFromUrl2(infoUrl, "dxNumber");
                var dValue = getValueFromUrl2(infoUrl, "&d");
                var myhref = "";

                var csgbutton = document.createElement("a");
                csgbutton.href = myhref;
                csgbutton.target = "_blank";

                var csgP = document.createElement("p");
                csgP.style = "text-align:center;";
                csgP.appendChild(csgbutton);

                var tdelems = mybooks[i].getElementsByTagName("td");
                for (var j = 0; j < tdelems.length; j++) {
                    if (tdelems[j].id == "b_img") {
                        var imgNode = tdelems[j];
                        var insertPoint = imgNode.nextSibling;
                        var myParentNode = insertPoint.parentNode;
                        myParentNode.insertBefore(ssNode, insertPoint);
                        myParentNode.insertBefore(csgP, insertPoint);
                    }
                }
            }
        }
    }
}

function getMatchResult(){
     let send_requestajax = $('script:contains(send_requestajax)');
    console.log(send_requestajax);
     let key = /ssn=(\d{3,})/
     return send_requestajax.text().match(key);
}


function processUCDSR() {
    if (myurl.indexOf("bookDetail.jsp?") != -1 && myurl.indexOf("/views/specific/") != -1) {
        var htmLink = document.getElementById("libinfo").innerHTML;
        if (htmLink.length < 100) {
            setTimeout(processUCDSR, 1000);
        } else {
            var htmlInfo = document.getElementsByClassName("leftnav_tu")[0].innerHTML;

            var ssid=null;
            var tubookimg = document.querySelector(".tubookimg");
            var r = getMatchResult();
            console.log(r);
            if (r){
                ssid=r[1];
            }
            else{
                ssid = GetSSID(tubookimg.querySelector("img").src);
            }

            var ssNode = CreateSSIDNode(ssid);

            var ssLink = document.createElement("a");
            ssLink.style = "text-decoration:none";
            ssLink.href = "http://> /downloadpdf/" + ssid + ".aspx?_k=20220419";
            ssLink.target = "_blank";
            ssLink.appendChild(ssNode);

            tubookimg.appendChild(ssLink);

            var xmlHttpRequest = createXmlHttpRequest();
            xmlHttpRequest.onreadystatechange = function() {
                if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
                    var stockNode = document.createElement("img");
                    stockNode.src = xmlHttpRequest.responseText;

                    var csgbutton = document.createElement("a");
                    csgbutton.href = "http://syhz.getpdfnow.com/downloadpdf/" + ssid + ".aspx?_k=20220419";
                    csgbutton.target = "_blank";
                    csgbutton.appendChild(stockNode);

                    var pTemp = document.createElement("p");
                    pTemp.style = "text-align:center;";
                    pTemp.appendChild(csgbutton);

                    tubookimg.appendChild(pTemp);
                }
            }
            xmlHttpRequest.open("POST", "http://stock.getpdfnow.com/query.ashx", true);
            xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xmlHttpRequest.send("ssid=" + escape(ssid) + "&url=" + encodeURIComponent(base64encode(myurl)) + "&info=" + encodeURIComponent(base64encode(htmlInfo)) + "&link=" + encodeURIComponent(base64encode(htmLink)));
        }
    }
}

//从当前网址中提取某个字段,输入字段名称
function getValueFromUrl(myfield) {
    var str = myfield + "=";
    if (myurl.indexOf(str) != -1) {
        var reg = new RegExp(myfield + "\\=\\w+");

        var fieldStr = myurl.match(reg)[0];
        console.log(myfield.toString());
        var fieldValue = fieldStr.replace(myfield + "=", "");
        return fieldValue;
    }
}

//从当前网址中提取某个字段,输入字段名称
function getValueFromUrl2(URL, myfield) {
    var str = myfield + "=";
    if (URL.indexOf(str) != -1) {
        var reg = new RegExp(myfield + "\\=\\w+");

        var fieldStr = URL.match(reg)[0];
        var fieldValue = fieldStr.replace(myfield + "=", "");
        return fieldValue;
    }
}

//获取ssid或者dxid,当ssid不存在的时候,返回dxid
//输入ssid的元素id以及读秀dxid的元素id
function GetSSIDDXID(ssidNodeID, dxidNodeID) {
    //获取ssid
    var ssid = GetSSIDByID(ssidNodeID, "value");

    //获取dxid
    var dxid = GetSSIDByID(dxidNodeID, "value");

    //如果ssid不存在,则用dxid替代
    if (ssid == "") {
        ssid = dxid;
    }
    return ssid;
}
//获取ssid,输入元素的id、属性名称(一般为value)
function GetSSIDByID(elementID, strAttribute) {
    var ssidNode = document.getElementById(elementID);
    var ssid = ssidNode.getAttribute(strAttribute);
    return ssid;
}
//创建默认的ssid节点,节点id为myssid
function CreateSSIDNode(ssid) {
    var myid = 'myssid';
    return CreateSSIDNode2(ssid, myid);
}
//创建ssid节点,输入ssid和节点id
function CreateSSIDNode2(ssid, strID) {
    var ssNode = document.createElement("p");
    ssNode.id = strID;
    ssNode.style = mystyle;
    ssNode.innerHTML = ssid;
    return ssNode;
}

function GetSSID(strImgSrc) {
    var ssid = "";
    var iidStr = GetEncode(strImgSrc);
    var ssidStr = DeCode(iidStr);
    ssid = TrimString(ssidStr);
    return ssid;
}

function GetEncode(strImgSrc) {
    var reg = /iid\=\w+/;
    var iidStr = strImgSrc.match(reg)[0];
    iidStr = iidStr.replace("iid=", "");
    return iidStr;
}

function TrimString(inputStr) {
    var outPutStr = "";
    inputStr = inputStr.replace(/\//g, "");
    var reg = /\d{8,}/;
    outPutStr = inputStr.match(reg);
    outPutStr = outPutStr.toString();
    return outPutStr;
}

function DeCode(EnCodeStr) {
    var decodeStr = "";
    var baseNumStr = EnCodeStr.substring(EnCodeStr.length - 2);
    var baseNum = parseInt(baseNumStr, 16);
    var myCodeStr = EnCodeStr.substring(0, EnCodeStr.length - 16);
    for (var i = 0; i < myCodeStr.length; i = i + 2) {
        decodeStr += GetSubString(myCodeStr, baseNum, i);
    }
    return decodeStr;
}

function GetSubString(EnCodeStr, BaseNum, startIndex) {
    var s = "";
    s = EnCodeStr.substring(startIndex, startIndex + 2);
    //转换进制
    var i = parseInt(s, 16) - BaseNum;
    s = String.fromCharCode(i);
    return s;
}

function createXmlHttpRequest() {
    if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } else if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
}

function base64encode(input) {
    var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var output = "";
    var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
    var i = 0;
    input = _utf8_encode(input);
    while (i < input.length) {
        chr1 = input.charCodeAt(i++);
        chr2 = input.charCodeAt(i++);
        chr3 = input.charCodeAt(i++);
        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;
        if (isNaN(chr2)) {
            enc3 = enc4 = 64;
        } else if (isNaN(chr3)) {
            enc4 = 64;
        }
        output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
    }
    return output;
}

function _utf8_encode(string) {
    string = string.replace(/\r\n/g, "\n");
    var utftext = "";
    for (var n = 0; n < string.length; n++) {
        var c = string.charCodeAt(n);
        if (c < 128) {
            utftext += String.fromCharCode(c);
        } else if ((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        } else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }

    }
    return utftext;
}

try {
    app.run();
} catch(e) {
    console.log(e);
}