Greasy Fork

来自缓存

Greasy Fork is available in English.

CNKI PDF Download

中国知网PDF下载(搜索列表)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        CNKI PDF Download
// @description 中国知网PDF下载(搜索列表)
// @author      Jachin
// @version     0.4
// @license     MIT
// @grant       GM_registerMenuCommand
// @namespace   http://tampermonkey.net/
// @include     *://kns.cnki.net/kns8/defaultresult/index*
// @include     *://oversea.cnki.net/kns/defaultresult/index*
// @include     *://*.res.gxlib.org.cn/kns*
// @exclude     *://image.cnki.net/*
// @include     *://kns.cnki.net/kns8/defaultresult/index*
// @include     *://oversea.cnki.net/kns/defaultresult/index*
// @include     */kns/brief/*
// @include     */kns55/brief/*
// @include     */grid2008/brief/*
// @include     */kcms/detail/detail.aspx*
// @include     *://er.szlib.org.cn/rwt/331/*

// ==/UserScript==


function get_pdf_url(url){
    let url_obj = new URL(url);
    url_obj.searchParams.set('dflag', "pdfdown");
    return url_obj.toString();
}

function add_pdf_download(){
    var $ = selector => Array.from(document.querySelectorAll(selector));
    $(".operat").forEach(i => {
        if(i.querySelector(".icon-download-pdf") != null)
            return
        if(i.querySelectorAll("a.downloadlink").length >= 2)
            return
        let download_node = i.querySelector(".downloadlink");
        if(download_node == null)
            return
        let pdf_download_node = download_node.cloneNode(true);
        pdf_download_node.href = get_pdf_url(pdf_download_node.href);
        pdf_download_node.classList.add("icon-download-pdf");
        pdf_download_node.classList.remove("icon-download");
        pdf_download_node.title = "download_pdf"
        pdf_download_node.querySelector("i").style.backgroundPosition = "-2px -140px"

        i.insertBefore(pdf_download_node, download_node);
        i.style.minWidth = "112px";
    })
}

(function() {
    'use strict';
    let observer = new MutationObserver(add_pdf_download);
    let options = {
        'childList': true,
        'attributes':true
    };

    observer.observe(document.querySelector(".main"), options);

    GM_registerMenuCommand(`PDF`, add_pdf_download);
})();