// ==UserScript== // @name 知网PDF下载助手 // @version 3.7.15 // @author Supernova // @description 提供搜索页面的直接PDF下载 // @match http*://*.cnki.net/* // @match http*://*.cnki.net.*/* // @match http*://*/defaultResult/index* // @match http*://*/KNS8/AdvSearch* // @match http*://*/kcms/detail/detail.aspx* // @exclude http://image.cnki.net/* // @run-at document-idle // @icon https://cnki.net/favicon.ico // @grant unsafeWindow // @grant GM_setClipboard // @grant GM_xmlhttpRequest // @grant GM_notification // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @license MIT // @namespace https://github.com/supernovaZhangJiaXing/Tampermonkey/ // @downloadURL none // ==/UserScript== 'use strict'; var $ = unsafeWindow.jQuery; $(document).ready(function() { var myurl = window.location.href; var isDetailPage = myurl.match(/(article|detail\.aspx)/g) ? true: false; // 点进文献后的详情页 if (isDetailPage === false) { // 对应普通检索和高级检索 if (window.location.href.indexOf("kns8") != -1 || window.location.href.indexOf("KNS8") != -1){ $(document).ajaxSuccess(function(event, xhr, settings) { if (settings.url.indexOf('/Brief/GetGridTableHtml') + 1) { $('.downloadlink').each(function () { $(this).css('background-color', '#C7FFFF').mouseover(function (e) { this.title="CAJ下载"; }) }); $.each($('.downloadlink'), function (index, value) { var pdf_down = $(this).clone().css('background-color', '#C7FFC7').mouseover(function(e){ this.title="PDF下载"; }); GM_xmlhttpRequest({ method: "GET", url: $(".fz14").eq(index).attr('href'), synchronous: true, headers: { Referer: 'https://kns.cnki.net/kns8/defaultresult/index', 'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.68" }, redirectionLimit: 10, onload: function(response) { GM_xmlhttpRequest({ method: "GET", url: response.finalUrl, // 跳转后的最终链接 synchronous: true, headers: { Referer: 'https://kns.cnki.net/kns8/defaultresult/index', 'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.68" }, onload: function(response){ // if (!response.responseText.trim().startswith('