// ==UserScript== // @name 中国知网CNKI硕博论文PDF下载 // @version 0.9.3 // @namespace https://greasyfork.org/users/244539 // @icon https://www.cnki.net/favicon.ico // @description 添加知网文献PDF下载按钮/add PDF download button to CNKI. // @author leftjie // @match http*://*.cnki.net // @match http*://cdmd.cnki.com.cn/Article/CDMD-* // @match http*://*/kcms/detail/detail.aspx?*dbcode=* // @match http*://*/*/*/kcms/detail/detail.aspx?*dbcode=* // @match http*://*/*/*/kcms/detail* // @match http*://*/https/*/kcms* // @match http*://*/KCMS/detail/detail.aspx?*dbcode=* // @match http*://*/kns*/defaultresult/index* // @match http*://*/https/*/kns8/defaultresult/index // @match http*://*/KNS8/AdvSearch?* // @match http*://*/kns/brief/*result* // @run-at document-idle // @grant unsafeWindow // @downloadURL none // ==/UserScript== //文献详情页面 var $ = unsafeWindow.jQuery; (function() { 'use strict'; function saveFile(name,data) { const blob = new Blob([data],{type:'text/plain'}); const link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = name + ".txt"; link.click(); window.URL.revokeObjectURL(link.href); } function add_cate_dl_btn() { var other_btns = document.getElementsByClassName('other-btns')[0]; var li2 = document.createElement('li'); var a2 = document.createElement('a'); li2.className = "btn-diy"; li2.style = "width:auto;height:23px;line-height:22px;background-color:#3f8af0;border-radius:3px;"; a2.innerHTML = "目录下载"; a2.className = "a-diy"; a2.style = "color:#ffffff;padding: 2px 10px;"; a2.href = "javascript:void(0)"; li2.appendChild(a2); other_btns.appendChild(li2); } var url = window.location.href; if(url.indexOf('detail.aspx') != -1){ var wx_title = document.getElementsByClassName('wx-tit')[0]; if(document.getElementsByClassName('catalog-list').length>0){ var category_list = document.getElementsByClassName('catalog-list')[0]; var cate_data = category_list.innerText; add_cate_dl_btn(); } $(document).on("click",".a-diy",function(){saveFile(wx_title.innerText,cate_data)}); var dllink = document.getElementsByClassName('operate-btn'); var dlurl = JSON.parse(localStorage.getItem("fnlist"))["tmpfn_" + url.match(/filename=([^&]*)/)[1]]; for (var i = 0;i <= dllink.length; i++) { var li = document.createElement('li'); var a1 = document.createElement('a'); li.className = "btn-dlpdf"; a1.innerHTML = "PDF 下载"; a1.href = dlurl; a1.style.backgroundColor="#fb4376"; li.appendChild(a1); dllink[i].appendChild(li); } }; })(); //知网空间学位论文 (function() { var url = window.location.href; if(url.indexOf('cdmd.cnki.com.cn') != -1){ var cnki_space_id = url.match(/-([0-9]+).htm/)[1]; console.log(cnki_space_id); var ty_caj = document.getElementById("ty_caj"); var newe = document.createElement("div"); var newe_a = document.createElement('a'); newe.className = "down_button"; newe.id = "ty_pdf"; newe_a.innerHTML = "PDF 下载(跳)"; newe_a.href = "https://kns.cnki.net/kcms/detail/detail.aspx?dbcode=CMFD&dbname=CMFDTEMP&filename=" + cnki_space_id + ".nh"; newe_a.target = "_blank"; newe.appendChild(newe_a); document.getElementById("down_3").insertBefore(newe,ty_caj); } })(); //搜索结果页面 (function() { function downloadFile(url) { window.open(url,'_blank') } function getlist(){ var l = localStorage.getItem("FileNameS").split(","); var urls = []; if (l == ""){ urls = []; au = []; }else{ $.each(l,function(index,val){ var u = $("input[value='"+ l[index] +"']").parent("td").parent("tr").find(".downloadlink")[0].href; urls.push(u); //console.log(u); }); } au = urls; } var au = []; $(document).ajaxSuccess(function() { if (arguments[2].url.indexOf('/Brief/GetGridTableHtml') + 1) { $('.downloadlink').attr('href',function(){return this.href+"&dflag=pdfdown";}); // 传值 localStorage.removeItem("fnlist"); var dllink = document.getElementsByClassName('cbItem'); var simgle_name = {}; $.each(dllink,function(index){ var u = $("input[value='"+ dllink[index].value +"']").parent("td").parent("tr").find(".downloadlink")[0].href; //console.log(u); simgle_name["tmpfn_" + dllink[index].value.split("!")[1]] = u; localStorage.setItem("fnlist",JSON.stringify(simgle_name)); }); // console.log(localStorage.getItem("fnlist")); $(document).on("click","#selectCheckAll1",function(){ getlist(); }) $("tr input[name='CookieName']").click(function(){ getlist(); }) $(".toolbar").after(`
`); }; // 开关 $(".diy-choose-btn").each(function(){ var texts = $(this).attr('data-toggle').split('|'); $(this).siblings('.choose-text').text(this.checked?texts[0]:texts[1]); $("#dd").text(this.checked?"批量下载"+texts[0]:"批量下载"+texts[1]); }); $(".diy-choose-btn").off("change"); $(".diy-choose-btn").on("change", function(){ var texts = $(this).attr('data-toggle').split('|'); $(this).siblings('.choose-text').text(this.checked?texts[0]:texts[1]); $("#dd").text(this.checked?"批量下载"+texts[0]:"批量下载"+texts[1]); if(this.checked){ $('.downloadlink').attr('href',function(){return this.href+"&dflag=pdfdown";}); }else{ $('.downloadlink').attr('href',function(){return this.href.replace("&dflag=pdfdown","");}); } }); }); $(document).on("click","#dd",function(){ //console.log(au); if(au.length == 0){ alert("未选择"); return false; } for(var i=0;i