Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
nahid18 committed Jul 28, 2023
0 parents commit c52d077
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ePDF Downloader

ePDF Downloader is a simple Chrome extension that adds a floating download button to webpages containing links containing `/doi/reader/` or `/doi/epdf/`.

![screenshot](image.png)

## Installation
1. Download the extension ZIP file from the GitHub repository.
2. Unzip the downloaded file.
3. Open Google Chrome and go to [chrome://extensions/](chrome://extensions/).
4. Turn on "Developer mode" (top right corner).
5. Click "Load unpacked" and select the unzipped folder.
6. ePDF Downloader will be added to your Chrome browser.

## Usage
1. Visit a webpage that has paper links with either `/doi/reader/` or `doi/epdf/`.
2. Look for the floating download button in the bottom right corner.
3. If a DOI link with the specified pattern is detected, the button will appear.
4. Click the button to open a new tab and download the PDF.

## Uninstalling
1. Go to [chrome://extensions/](chrome://extensions/).
2. Find "ePDF Downloader" in the list.
3. Click "Remove" to uninstall the extension.

## Contributing
Contributions are welcome! Feel free to open an issue or create a pull request on GitHub.

## License
ePDF Downloader is licensed under the MIT License.

Thank you for using ePDF Downloader! If you have any questions or need support, please let us know in the Issues section. Enjoy easy PDF downloads!
47 changes: 47 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
Binary file added download-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added epdf-downloader.zip
Binary file not shown.
Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"manifest_version": 3,
"name": "ePDF Downloader",
"version": "1.0",
"description": "A Chrome extension to download PDF from ePDF links",
"permissions": ["activeTab"],
"content_scripts": [
{
"matches": ["https://*/*", "http://*/*"],
"js": ["content.js"]
}
],
"web_accessible_resources": [
{
"resources": ["pdf.svg"],
"matches": ["https://*/*", "http://*/*"]
}
],
"icons": {
"48": "download-icon.png"
}
}
19 changes: 19 additions & 0 deletions pdf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c52d077

Please sign in to comment.