This is code for a bookmarklet that highlights what you're reading. I've had this for years and am just now dumping into a gist.
Last active
March 11, 2026 00:10
-
-
Save bradmontgomery/513ae31a872bbf1af315e910f44d608b to your computer and use it in GitHub Desktop.
A Bookmarklet that highlights you're reading on the web based on where your mouse is at.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript:(function(){var lastElems=[];var lastStyles=[];function isDark(){var bg=window.getComputedStyle(document.body).backgroundColor;var m=bg.match(/\d+/g);if(!m)return false;var r=parseInt(m[0]),g=parseInt(m[1]),b=parseInt(m[2]);return(0.299*r+0.587*g+0.114*b)<128;}window.onmousemove=function(e){for(var i=0;i<lastElems.length;i++){lastElems[i].style.backgroundColor=lastStyles[i].bg;lastElems[i].style.opacity=lastStyles[i].op;lastElems[i].style.color=lastStyles[i].color;}lastElems=[];lastStyles=[];var elem=document.elementFromPoint(e.clientX,e.clientY);if(!elem||elem===document.body||elem===document.documentElement){return;}var el=elem;while(el&&el!==document.body){var rect=el.getBoundingClientRect();if(rect.height>0&&rect.height<200){lastElems.push(el);lastStyles.push({bg:el.style.backgroundColor,op:el.style.opacity,color:el.style.color});if(isDark()){el.style.backgroundColor="#4a3d00";el.style.color="#ffffff";}else{el.style.backgroundColor="#ffffa0";el.style.color="#000000";}el.style.opacity="1";break;}el=el.parentNode;}};})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment