|
// ==UserScript== |
|
// @name ScienceDirect pdf |
|
// @namespace https://gist.github.com/ms609/beaed274ec473fbe0f929d1ea88e4158 |
|
// @version 0.1 |
|
// @description Go directly to the Elsevier PDF, not the "epdf" |
|
// @author Martin R. Smith |
|
// @match https://www.sciencedirect.com/* |
|
// @match https://reader.elsevier.com/reader/* |
|
// @icon https://www.google.com/s2/favicons?sz=64&domain=sciencedirect.com |
|
// @run-at document-start |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
(function() { |
|
'use strict'; |
|
function PDFURL (id) { |
|
return "https://www.sciencedirect.com/science/article/pii/" + id + "/pdfft"; |
|
} |
|
|
|
function ReplaceHrefs() { |
|
var anchors = document.getElementsByTagName("a"); |
|
for (var i = 0, len = anchors.length; i < len; i++) { |
|
if (anchors[i].getAttribute("role") == "button") { |
|
console.log(anchors[i]) |
|
console.log(anchors[i].href) |
|
} |
|
if (anchors[i].href != "") { |
|
var match = anchors[i].href.match(/\/science\/article\/pii\/(S\d+X?)\/pdfft/); |
|
if (match) { |
|
anchors[i].href = PDFURL(match[1]); |
|
} |
|
} else { |
|
// Doesn't quite work - suggestions welcome! |
|
anchors[i].href = PDFURL(document.location.href.match(/S\d+X?/)[0]); |
|
var newA = document.createElement("a"); |
|
newA.href = PDFURL(document.location.href.match(/S\d+/)[0]); |
|
newA.innerHTML = "PDF (direct)"; |
|
document.insertBefore(newA, anchors[i]); |
|
} |
|
} |
|
} |
|
|
|
// https://www.sciencedirect.com/sdfe/reader/pii/S0031018221004983/pdf |
|
let inURL = document.location.href.match(/https:\/\/reader\.elsevier\.com\/reader\/sd\/pii\/(S[\dX]+)/); |
|
if (inURL) { |
|
document.location.href = PDFURL(inURL[1]); |
|
} |
|
|
|
if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") { |
|
ReplaceHrefs(); |
|
} else { |
|
document.addEventListener("DOMContentLoaded", function(event) { |
|
ReplaceHrefs(); |
|
}); |
|
} |
|
})(); |