Skip to content

Instantly share code, notes, and snippets.

@clo4
Last active May 13, 2024 07:43
Show Gist options
  • Save clo4/97720cab417ef2eefaccebf97d62944f to your computer and use it in GitHub Desktop.
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.
// ==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