// ==UserScript== // @name Publication Auto PDF // @name:zh-CN SCI文献PDF直达 // @version 0.3 // @author sincostandx // @description Automatically jumps to PDF when you visit a journal article abstract page. Also includes a utility to copy or download citation info. // @description:zh-CN 访问SCI文献摘要页时自动跳转至PDF,附带文献摘录工具 // @include http*://www.sciencedirect.com/science/article/* // @include http*://pubs.acs.org/doi/* // @include http*://www.tandfonline.com/doi/abs/* // @include http*://www.beilstein-journals.org/* // @include http*://onlinelibrary.wiley.com/doi/* // @include http*://www.eurekaselect.com/*/article* // @include http*://pubs.rsc.org/en/Content/* // @include http*://link.springer.com/article* // @include http*://aip.scitation.org/doi/10* // @include http*://aip.scitation.org/doi/abs/10* // @include http*://www.nature.com/articles* // @include http*://science.sciencemag.org/content* // @include http*://journals.aps.org/*/abstract/10* // @include http*://www.nrcresearchpress.com/doi/10* // @include http*://iopscience.iop.org/article/10* // @exclude *.pdf // @grant GM.xmlHttpRequest // @grant GM.getValue // @grant GM.setValue // @run-at document-start // @namespace https://greasyfork.org/users/171198 // @downloadURL none // ==/UserScript== "use strict"; var tit=null; //title var doi=null; var pdf=null; //pdf url var sty=""; // citation text style if (location.href.includes("pubs.acs.org/doi/abs/")) pdf=location.href.replace("/abs/","/pdf/"); // Works for ACS journals else if (location.href.includes("pubs.acs.org/doi/10.")) pdf=location.href.replace("/doi/","/doi/pdf/"); else if (location.href.includes("journals.aps.org/") && location.href.includes("abstract/10.")) pdf=location.href.replace("/abstract/","/pdf/"); const jump = window.history.length<=1 || sessionStorage.getItem(location.pathname) === null; sessionStorage.setItem(location.pathname,"1"); if (jump && pdf !== null && location.href !== pdf) { window.stop(); location.href=pdf; } else { checkLoaded(); } function checkLoaded() { if (document.body !== null && document.body.innerHTML.length !== 0) loadMeta(); else setTimeout(checkLoaded,100); } function loadMeta() { const titmeta=["dc.title","citation_title"]; const doimeta=["citation_doi","dc.identifier","dc.source"]; const l=document.getElementsByTagName("meta"); for(let i=0; i p > a").href; sessionStorage.setItem(doi,href); location.href = href; } } catch(e) { console.log(e); location.href = pdf; } } xhr.open("GET", pdf, true); xhr.send(); } function toolbox(tit,doi,pdf) { const div = document.createElement("div"); div.style="z-index:2147483646;position:fixed;right:10px;top:50%;transform: translate(0, -50%);border:2px groove black;background:white;box-shadow:6px 6px 3px grey;"; const sheet = document.createElement("style") sheet.innerHTML = ".toolbox{font-size: 10pt;font-family: sans-serif;margin:0;padding:0;margin-bottom:2px;display:initial;}input.toolbox,select.toolbox{background-image: none !important;width: auto;max-height:none}textarea.toolbox,input.toolbox[type=text]{-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;width: 11em;}input.toolbox[type=button]{padding: 2px 8px;}[tooltip]:before {position: absolute;opacity: 0;}[tooltip]:hover:before {content: attr(tooltip);opacity:1;color:black;background:white;padding:2px;border:1px groove black;white-space: nowrap;overflow: hidden;right:0;margin-top:-25pt;}" div.appendChild(sheet); // Hide button const hide_btn_parent = newtag(div,"div",null); hide_btn_parent.style = "display:flex;justify-content:flex-end;padding-right:10px;"; const hide_btn = newtag(hide_btn_parent,"a","✖"); hide_btn.style = "cursor:pointer;font-size:large;text-decoration:none;"; hide_btn.addEventListener("click", function(){div.remove();}, false); // DOI textbox and copy button const txt_doi = newinput(div,"text",doi,null); newbr(div); newinput(div,"button","Copy",function(){txt_doi.select();document.execCommand("Copy");}); newbr(div);newbr(div); // info textbox and copy button const info = tit+"\t"+doi; const txt_inf = newinput(div,"text",info,null); newbr(div); newinput(div,"button","Copy",function(){txt_inf.select();document.execCommand("Copy");}); newbr(div);newbr(div); // bibtex button const txt_bib = newtag(div,"textarea",null); txt_bib.style.display = "none"; txt_bib.style.resize = "none"; newbr(div); const btn_bib = newinput(div,"button","Copy BibTeX",loadBib); newbr(div); function loadBib() { btn_bib.disabled = true; btn_bib.value = "Loading"; GM.xmlHttpRequest({ method: "GET", url: "https://dx.doi.org/" + doi, headers: { "Accept": "application/x-bibtex" }, onload: function(response) { if (response.readyState == 4 && response.status == 200) { const bib = response.responseText; txt_bib.value = bib; txt_bib.style.display = ""; txt_bib.select(); document.execCommand("Copy"); btn_bib.value = "Copy BibTeX"; } else { btn_bib.value = "Reload BibTeX"; } btn_bib.disabled = false; }, onerror: function(response) { btn_bib.value = "Reload BibTeX"; btn_bib.disabled = false; } }); } // Text button const btn_txt = newinput(div,"button","Copy Text",loadTxt); function loadTxt() { if (sty==="") { setstyle(); return; } btn_txt.disabled = true; btn_txt.value = "Loading"; GM.xmlHttpRequest({ method: "GET", url: "https://dx.doi.org/" + doi, headers: { "Accept": "text/x-bibliography; style="+sty }, onload: function(response) { if (response.readyState == 4 && response.status == 200) { const bib = response.responseText; txt_bib.value = bib; txt_bib.style.display = ""; txt_bib.select(); document.execCommand("Copy"); btn_txt.value = "Copy Text"; } else { btn_txt.value = "Reload Text"; } btn_txt.disabled = false; }, onerror: function(response) { btn_txt.value = "Reload Text"; btn_txt.disabled = false; } }); } // text style link const stylink = newtag(div,"a","Style"); stylink.addEventListener("click",setstyle,false); stylink.style.cursor = "pointer"; newbr(div); function setstyle() { const div = document.createElement("div"); div.style="z-index:2147483647;position:fixed;left:50%;top:50%;transform:translate(-50%, -50%);border:2px groove black;background:white;padding:20px;box-shadow:10px 10px 5px grey;"; newtag(div,"h3","Choose a citation style for text references:").style.fontSize="medium"; const sel = newtag(div,"select",null); sel.size = 15; sel.style.minWidth="600px"; newbr(div);newbr(div); newtag(div,"p","This citation style will be saved as default."); const btns = newtag(div,"div",null); btns.style.textAlign = "center"; // OK button newinput(btns,"button","OK",function() { sty = sel.value; GM.setValue("sty",sty); document.body.removeChild(div); loadTxt(); }); // cancel button newinput(btns,"button","Cancel",function(){document.body.removeChild(div);}).style.marginLeft = "1em"; // load styles GM.xmlHttpRequest({ method: "GET", url: "https://citation.crosscite.org/styles", onload: function(response) { if (response.readyState == 4 && response.status == 200) { const l = JSON.parse(response.responseText); for (let i=0; i