~jbauer/simple-highlight

12e87cac60ac48be5b964dbaa4b4ed8ae31679fd — Jake Bauer 2 months ago
Initial commit
3 files changed, 60 insertions(+), 0 deletions(-)

A README.md
A background.js
A manifest.json
A  => README.md +15 -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.

A  => background.js +22 -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();
}

A  => manifest.json +23 -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."
	}
    }
}