Last active
May 13, 2024 07:43
-
-
Save clo4/97720cab417ef2eefaccebf97d62944f to your computer and use it in GitHub Desktop.
Userscript that force-unfocusses the currently focused element when you press shift-escape.
This file contains 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
// ==UserScript== | |
// @name Unfocus | |
// @namespace https://clo4.net | |
// @version 1.0.0 | |
// @description Unfocuses the current element when you press shift+esc | |
// @author github.com/clo4 | |
// @match *://*/* | |
// @icon https://upload.wikimedia.org/wikipedia/commons/d/dc/Escts.jpg | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
document.addEventListener("keydown", (ev) => { | |
if (!(ev.key === "Escape" && ev.shiftKey && !ev.ctrlKey && !ev.altKey && !ev.metaKey)) { | |
return; | |
} | |
ev.stopImmediatePropagation(); | |
ev.preventDefault(); | |
// activeElement is never null | |
document.activeElement.blur(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment