Last active
May 17, 2024 10:45
-
-
Save xnuk/575b23393e25539e39a7fd5aae120cf9 to your computer and use it in GitHub Desktop.
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 Twitter hangul sucks | |
// @version 3 | |
// @grant none | |
// @match https://twitter.com/* | |
// @match https://x.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