Skip to content

Commit

Permalink
Add highlighting, update README and icons
Browse files Browse the repository at this point in the history
  • Loading branch information
salcc committed Nov 10, 2024
1 parent 425ffeb commit f25cb1b
Show file tree
Hide file tree
Showing 12 changed files with 856 additions and 6 deletions.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Scholar PDF Reader with Annotations

This extension adds annotation capabilities to the Google Scholar PDF Reader extension. The extended features include:

- Highlight text with a selection of colors (yellow, green, blue, pink, red).
- Easily remove individual annotations or clear all at once.

Currently, annotations are stored in the browser's local storage and associated with each document URL. The PDF files themselves are not modified, but annotations persist across browser sessions.

![Screenshot](screenshot.png)

The extension maintains all the functionality of the original Google Scholar PDF Reader:

- Preview references as you read. Click the in-text citation to see a summary and find the PDF.
- Read faster with the AI outline. Get a quick overview and click on interesting bullets to jump within the paper.
- Click in-text figure mentions to see the figure and the back button to keep reading.
- Make it right for your eyes with light, dark, and night modes.
- Copy and paste common citation formats without leaving the paper.
- Save articles to your Scholar Library to read or cite later.

The annotation functionality is implemented through separate modules without modifying the original extension's code.

## Installation

The extension works with all Chromium-based browsers, including Google Chrome, Microsoft Edge, and Brave.
Unfortunately, the original extension uses features that are not supported by Firefox or Safari, so it cannot be installed on those browsers.

To install the extension, follow these steps:

1. Uninstall the original Google Scholar PDF Reader extension if you have it installed.
2. Download the latest release from the Releases section of this repository.
3. Extract the ZIP file to a folder on your computer.
4. Open the browser's extension management page:
- Google Chrome: `chrome://extensions`
- Microsoft Edge: `edge://extensions`
- Brave: `brave://extensions`
- Other Chromium-based browsers: check the browser's documentation for the extension management page.
5. Enable developer mode if it is not already enabled (usually a toggle switch in the top right corner).
6. Click "Load unpacked" and select the "extension" folder inside the extracted ZIP file.

The extension should now be installed and ready to use!

Note that the extension will not automatically update when new versions are released. To update the extension, download the latest release and repeat the installation steps. You can watch the GitHub repository to receive notifications of new releases.

## Planned features

The following features are planned for future releases:

- Local annotation storage through direct PDF file modification.
- Drawing tools.
- Text comments.
- Annotation management interface for selective storage cleanup, annotation file import/export, and annotation transfer between PDF files.


## Implementation Questions

Q: Why there is no support for Firefox or Safari?
A: The original extension uses the sandbox key in the manifest.json file, which is only supported by Chromium-based browsers. Firefox and Safari do not support this key, so the extension cannot be installed on those browsers. [[MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_security_policy#browser_compatibility)]

Q: Why is the code of the original extension included in this one? Why not just make an extension that works with the original one?
A: Browser extensions are sandboxed and cannot directly interact with each other.

If you find workarounds to these limitations, contributions are welcome!


## Support & Contributions

For bug reports and feature suggestions, please open an issue on GitHub. Feel free to submit pull requests that enhance the extension.

## Disclaimer

This project is not affiliated with, supported, or endorsed by Google.
Binary file added extension/MaterialSymbolsOutlined.woff2
Binary file not shown.
13 changes: 13 additions & 0 deletions extension/annotation-background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import './background-compiled.js';

chrome.runtime.onMessage.addListener((request) => {
if (request.action === "getPdfUrl") {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
if (tabs[0]) {
let url = tabs[0].url;
let cleanUrl = url.split('#')[0]; // Remove the fragment identifier
chrome.tabs.sendMessage(tabs[0].id, {action: "setPdfUrl", url: cleanUrl});
}
});
}
});
27 changes: 27 additions & 0 deletions extension/annotation-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(function () {
function injectPdfUrl(pdfUrl) {
const iframeUrl = chrome.runtime.getURL("reader.html");
const iframe = document.querySelector(`iframe[src="${iframeUrl}"]`);

iframe.addEventListener('load', () => {
iframe.contentWindow.postMessage({ type: "FROM_CONTENT_SCRIPT", pdfUrl: pdfUrl }, "*");
});
}

chrome.runtime.onMessage.addListener((message) => {
if (message.action === "setPdfUrl") {
injectPdfUrl(message.url);
}
});

function requestPdfUrl() {
chrome.runtime.sendMessage({ action: "getPdfUrl" });
}

// Run when the page is loaded
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', requestPdfUrl);
} else {
requestPdfUrl();
}
})();
112 changes: 112 additions & 0 deletions extension/annotation.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
@font-face {
font-family: 'Material Symbols Outlined';
font-style: normal;
src: url('MaterialSymbolsOutlined.woff2') format('woff2');
}

.material-symbols-outlined {
font-family: 'Material Symbols Outlined';
font-weight: normal;
font-style: normal;
font-size: 24px;
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
}

#annotation-toolbar {
position: fixed;
top: 60px;
right: 20px;
background-color: #333;
border-radius: 25px;
padding: 10px;
z-index: 1000;
display: flex;
gap: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.toolbar-button {
width: 40px;
height: 40px;
border-radius: 50%;
border: 2px solid transparent;
background-color: #555;
color: white;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: background-color 0.3s, border-color 0.3s;
position: relative;
}

.toolbar-button:hover,
.toolbar-button.active {
background-color: #777;
}

.toolbar-button.active {
border-color: #fff;
}

.toolbar-button::after {
content: attr(data-tooltip);
position: absolute;
bottom: -35px;
left: 50%;
transform: translateX(-50%);
background-color: #555;
color: white;
padding: 5px 10px;
border-radius: 5px;
font-size: 12px;
white-space: nowrap;
opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
text-shadow: none;
}

.toolbar-button:hover::after {
opacity: 1;
}

#color-picker {
position: relative;
}

#color-popup {
display: none;
position: absolute;
top: calc(100% + 10px);
left: 50%;
transform: translateX(-50%);
background-color: #444;
border-radius: 10px;
padding: 10px;
z-index: 1001;
}

.color-option {
width: 30px;
height: 30px;
border-radius: 50%;
border: 2px solid transparent;
margin: 5px auto;
cursor: pointer;
display: block;
}

.color-option.active {
border-color: #fff;
}

.pdf-highlight {
opacity: 0.5;
}
Loading

0 comments on commit f25cb1b

Please sign in to comment.