Last active
November 12, 2020 15:14
-
-
Save binki/4dcbb7e47f18d17fcc4fc898af46e871 to your computer and use it in GitHub Desktop.
Discord Refocus Binki
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
// ==UserScript== | |
// @name discord-refocus-binki | |
// @namespace https://gist.github.com/binki/4dcbb7e47f18d17fcc4fc898af46e871 | |
// @version 1 | |
// @grant none | |
// @match https://discordapp.com/* | |
// @description Make Discord blink the input textbox upon being refocused (it seems unsafe to type at a window without a blinking cursor). | |
// ==/UserScript== | |
// Discord does this weird thing where it stops the cursor from blinking in the input textbox if | |
// you blur it. When refocusing the window, it doesn’t restore the blinking cursor. This bugs | |
// me because, in everything else, not having a blinking cursor means that weird things will | |
// happen if you start typing (e.g., activating mnemonics in winforms). So, add logic to refocus | |
// the text input. | |
window.addEventListener('focus', e => { | |
// Because Discord does some weird blurring of everything when it blurs, the refocus upon switching | |
// tabs or refocusing the browser itself will be targeted at the window. Other focus events are probably | |
// legit, so don’t do things because that’ll break stuff. | |
if (e.target !== window) { | |
return; | |
} | |
// Locate the current input textbox. | |
const textChannelInputBox = document.querySelector('div[data-slate-editor=true][aria-label^=\'#\']'); | |
if (!textChannelInputBox) { | |
return; | |
} | |
textChannelInputBox.focus(); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I gave up and now use the desktop client. But I haven’t needed the desktop clients’ features in a while…