simple-highlight

A small chromium extension to make highlighting pages on the fly easier.
git clone https://git.jaderune.net/jbauer/simple-highlight
Log | Files | Refs | README | LICENSE

background.js (501B)


      1 // background.js
      2 chrome.action.onClicked.addListener((tab) => {
      3 	chrome.scripting.executeScript({
      4 		target: {tabId: tab.id},
      5 		func: highlight,
      6 		args: [],
      7 	});
      8 });
      9 
     10 function highlight() {
     11 	let selection = document.getSelection();
     12 	if (selection.rangeCount <= 0) return;
     13 
     14 	// Perform the highlight
     15 	let mark = document.createElement("mark");
     16 	let range = selection.getRangeAt(0);
     17 	mark.appendChild(range.extractContents());
     18 	range.insertNode(mark);
     19 
     20 	// De-select text
     21 	selection.removeAllRanges();
     22 }