commit 12e87cac60ac48be5b964dbaa4b4ed8ae31679fd
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Sun, 18 Sep 2022 12:33:01 -0400
Initial commit
Diffstat:
3 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -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.
diff --git a/background.js b/background.js
@@ -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();
+}
diff --git a/manifest.json b/manifest.json
@@ -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."
+ }
+ }
+}