Skip to content

Bookmarklet that lets you highlight text using your mouse selection

Notifications You must be signed in to change notification settings

sk22/selection-highlighter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

javascript:let mouseEvent=null;function replacePart(a,b,c,d){b.innerHTML=(c?"<span>"+b.innerText.slice(0,a.startOffset)+"</span>":"")+"<span style=\"background: yellow\">"+b.innerText.slice(c?a.startOffset:0,d?a.endOffset:void 0)+"</span>"+(d?"<span>"+b.innerText.slice(a.endOffset)+"</span>":"")}document.addEventListener("selectstart",()=>{mouseEvent=document.addEventListener("mouseup",()=>{document.removeEventListener("mouseup",mouseEvent);const a=document.getSelection(),{anchorOffset:b,extentOffset:c}=a,d=a.getRangeAt(0),e=Math.min(b,c),f=Math.max(c,b);if(0<f-e){const{startContainer:a,endContainer:b}=d,c="yellow"===a.parentElement.style.background;if(c)a.parentElement.outerHTML=a.parentElement.innerText;else{const c=a===b;replacePart(d,a.parentElement,!0,c);for(let c=a.parentElement;c.nextSibling&&c!==b;)c=c.nextSibling,replacePart(d,c,!1,!1);c||replacePart(d,b.parentElement,!1,!0)}}})});

About

Bookmarklet that lets you highlight text using your mouse selection

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published