知网批量下载PDF

用于知网批量下载PDF

// ==UserScript==
// @name         知网批量下载PDF
// @namespace    https://ixz.im/
// @version      0.1
// @description  用于知网批量下载PDF
// @author       Juicpt
// @match        *://*.cnki.net/*
// @include      *://*.cnki.net.*
// @include      *://*/cnki.net/*
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    const html = document.querySelector(".SavePoint");
    const button = document.createElement('a');
    const Util = {
        dflag: res => res.replace('&dflag=nhdown', '&dflag=pdfdown'),

    };
    button.innerHTML = '批量下载PDF';

    if (html) {
        html.style.width = '600px';
        html.appendChild(button);

    }
    const table = document.querySelector('.GridTableContent');
    const tr = table.querySelectorAll('tr [bgcolor]');
    tr.forEach(
        res => {
            const a = res.querySelector('.briefDl_Y, .briefDl_D');
            a.href = a.href.match('&dflag') ? Util.dflag(a.href) : (a.href + '&dflag=pdfdown');
        }
    );
    button.addEventListener('click', () => {
        tr.forEach(
            res=>{
                const a = res.querySelector('.briefDl_Y, .briefDl_D');
                a.click();
            }
        )
    });

})();