Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Discord Refocus Binki
// ==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);
@binki

This comment has been minimized.

Copy link
Owner Author

@binki binki commented Nov 12, 2020

I gave up and now use the desktop client. But I haven’t needed the desktop clients’ features in a while…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment