Greasy Fork

Greasy Fork is available in English.

知网下载助手

论文搜索结果页面和硕博论文详述页面的caj格式下载链接替换为pdf格式下载链接

当前为 2019-01-23 提交的版本,查看 最新版本

// ==UserScript==
// @name         知网下载助手
// @namespace    [email protected]
// @version      1.1.0
// @description  论文搜索结果页面和硕博论文详述页面的caj格式下载链接替换为pdf格式下载链接
// @author       wyn665817
// @match        *://*.cnki.net/*
// @include      *://*.cnki.net.*
// @include      *://*/cnki.net/*
// @run-at       document-end
// @grant        unsafeWindow
// @supportURL   http://greasyfork.icu/zh-CN/scripts/371938/feedback
// @license      MIT
// ==/UserScript==

var $ = unsafeWindow.$,
url = location.pathname,
dbcode = ['CDFD', 'CMFD'];

String.prototype.endsWith = function(search) {
    return this.substring(this.length - search.length, this.length) === search;
};
String.prototype.dbcode = function() {
    var r = this.match(/dbcode=(.*?)&/);
    return r ? r[1] : '';
};

if (url.endsWith('brief.aspx')) {
    $('.GridTableContent tr[bgcolor]').each(function() {
        var $dl = $('.briefDl_Y, .briefDl_D', this),
        href = $dl[0].href;
        href = href.indexOf('&dflag') + 1 ? href.replace('&dflag=nhdown', '&dflag=pdfdown') : (href + '&dflag=pdfdown');
        if ($.inArray($('.fz14', this).attr('href').dbcode(), dbcode) + 1) {
            href = href.replace('kns', 'gb.oversea').replace('kns', 'kcms');
        }
        $dl.attr('href', href);
    });
} else if (url.endsWith('detail.aspx') && $.inArray(location.search.dbcode(), dbcode) + 1) {
    $('.dllink > .icon').each(function() {
        url = $(this).text().trim();
        if (url == '整本下载') {
            this.href = this.href.replace('&dflag=nhdown', '&dflag=pdfdown');
        } else if (url == '分页下载' || url == '分章下载') {
            this.href += '&cflag=pdf';
        } else {
            return true;
        }
        this.href = this.href.replace('kns', 'gb.oversea').replace('kns', 'kcms');
    });
}