Skip to content

Instantly share code, notes, and snippets.

@xnuk
Last active December 12, 2022 13:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnuk/575b23393e25539e39a7fd5aae120cf9 to your computer and use it in GitHub Desktop.
Save xnuk/575b23393e25539e39a7fd5aae120cf9 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Twitter hangul sucks
// @version 2
// @grant none
// @match https://twitter.com/*
// @noframes
// @icon https://twitter.com/favicon.ico
// @run-at document-end
// ==/UserScript==
;(() => {
const listener = e => {
const target = e.target
const isDM = target.dataset.testid.startsWith('dmComposer')
if (
// DM -> Enter / Tweet -> Ctrl + Enter
(e.ctrlKey || isDM) &&
e.key === 'Enter' &&
target.isContentEditable
) {
target.contentEditable = false
e.stopPropagation()
setTimeout(() => target.dispatchEvent(e), 200)
setTimeout(() => (target.contentEditable = true), 400)
}
}
const addListener = () =>
[
...document.querySelectorAll(
'.public-DraftEditor-content[contenteditable]',
),
].map(v => v.addEventListener('keydown', listener))
const observer = new MutationObserver(mutations => {
if (
mutations.some(({ addedNodes }) =>
[...addedNodes].some(node => node.isContentEditable),
)
)
addListener()
})
observer.observe(document.getElementById('react-root'), {
childList: true,
subtree: true,
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment