Initial commit

release
Jake Bauer 2022-09-18 12:33:01 -04:00
commit 12e87cac60
3 changed files with 60 additions and 0 deletions

15
README.md Normal file
View File

@ -0,0 +1,15 @@
# simple-highlight
A small chromium extension to make highlighting pages on the fly easier.
Designed to allow you to mark up a page with highlights then print it to PDF,
instead of needing to print to PDF first and then highlight in your PDF reader.
## What it does
Select some text, then press _Alt+H_ and the text will be highlighted yellow.
Right now, you can only highlight within a block of text. If you try to
highlight across two paragraphs or similar, things will break and not look good.
Also, you can't remove highlights yet, I still have to figure that one out too.

22
background.js Normal file
View File

@ -0,0 +1,22 @@
// background.js
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: {tabId: tab.id},
func: highlight,
args: [],
});
});
function highlight() {
let selection = document.getSelection();
if (selection.rangeCount <= 0) return;
// Perform the highlight
let mark = document.createElement("mark");
let range = selection.getRangeAt(0);
mark.appendChild(range.extractContents());
range.insertNode(mark);
// De-select text
selection.removeAllRanges();
}

23
manifest.json Normal file
View File

@ -0,0 +1,23 @@
{
"manifest_version": 3,
"name": "simple-highlight",
"description": "Easily highlight text on a webpage.",
"version": "0.1.0",
"permissions": ["activeTab", "scripting"],
"host_permissions": ["<all_urls>"],
"background": {
"service_worker": "background.js"
},
"action": {},
"commands": {
"_execute_action": {
"suggested_key": "Alt+H",
"description": "Highlight selected text."
}
}
}