-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
47 lines (40 loc) · 1.24 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
scanHTMLForDOIUrls();
function scanHTMLForDOIUrls() {
const docLinks = document.links;
for (let i = 0; i < docLinks.length; i++) {
const link = docLinks[i].href;
if (link.includes("/doi/reader/") || link.includes("/doi/epdf/")) {
addDownloadButton(link);
}
}
}
function addDownloadButton(url) {
const newUrl = getUpdatedURL(url);
if (newUrl) {
const button = document.createElement("button");
button.style.position = "fixed";
button.style.bottom = "20px";
button.style.right = "20px";
button.style.backgroundColor = "transparent";
button.style.border = "none";
button.style.zIndex = "9999";
const iconImage = new Image();
iconImage.src = chrome.runtime.getURL('pdf.svg');
iconImage.style.width = "auto";
iconImage.style.height = "60px";
iconImage.style.objectFit = "contain";
button.appendChild(iconImage);
button.addEventListener("click", function () {
window.open(newUrl, "_blank");
});
document.body.appendChild(button);
}
}
function getUpdatedURL(url) {
if (url.includes("/doi/reader/")) {
return url.replace("/doi/reader/", "/doi/pdf/");
} else if (url.includes("/doi/epdf/")) {
return url.replace("/doi/epdf/", "/doi/pdf/");
}
return null;
}