-
-
Save inertia186/ee7458f2ef7aa338a0fc8c32bf3369f9 to your computer and use it in GitHub Desktop.
// ==UserScript== | |
// @name unhover | |
// @namespace https://example.com/ | |
// @version 2024-07-18 | |
// @description Trap hover events so they don't interrupt you constantly and invert colors of the element causing hover. | |
// @author You | |
// @match *://*/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// @updateURL https://gist.githubusercontent.com/inertia186/ee7458f2ef7aa338a0fc8c32bf3369f9/raw/unhover.user.js | |
// @downloadURL https://gist.githubusercontent.com/inertia186/ee7458f2ef7aa338a0fc8c32bf3369f9/raw/unhover.user.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Function to stop propagation of hover events and invert colors | |
function handleHoverEvents(event) { | |
event.stopPropagation(); | |
event.target.classList.toggle('invert-color'); | |
} | |
// Add CSS class to invert colors | |
const style = document.createElement('style'); | |
style.innerHTML = ` | |
.invert-color { | |
filter: invert(1); | |
} | |
`; | |
document.head.appendChild(style); | |
// Attach event listeners to capture and prevent hover events | |
document.addEventListener('mouseover', handleHoverEvents, true); | |
document.addEventListener('mouseout', handleHoverEvents, true); | |
})(); |
I recommend commenting out the event.target.classList.toggle('invert-color');
line. It's there to remind you this user script is running. But if you're fine with running it all the time, for all sites, may as well just let it do its thing without any reminder.
In my opinion, there is never any reason to have hover events, ever. Tooltips are one thing. They might be handy. If they're implemented without a hover, they won't be affected. But you don't need them. No UI element should ever need to activate with a hover. Website designers know that you might be on a mobile device with touch controls, so they aren't going to make the site unusable if you don't have hover controls.
And if they do, you can always disable the user script, if you remember it's running and you need the odd hover event, once in a while.
To install, make sure you have the Tampermonkey extension and open this link:
https://gist.githubusercontent.com/inertia186/ee7458f2ef7aa338a0fc8c32bf3369f9/raw/unhover.user.js