Created
April 29, 2026 11:07
-
-
Save eugrus/55f66c0adc01bdb4a27b31fe039f8f48 to your computer and use it in GitHub Desktop.
Deactivate Ctrl+U capturers
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
| (() => { | |
| const targets = [window, document, document.documentElement, document.body].filter(Boolean); | |
| const eventTypes = ['keydown', 'keypress', 'keyup']; | |
| const backup = []; | |
| for (const t of targets) { | |
| backup.push({ | |
| target: t, | |
| onkeydown: t.onkeydown, | |
| onkeypress: t.onkeypress, | |
| onkeyup: t.onkeyup | |
| }); | |
| t.onkeydown = null; | |
| t.onkeypress = null; | |
| t.onkeyup = null; | |
| } | |
| if (typeof getEventListeners === 'function') { | |
| for (const t of targets) { | |
| const all = getEventListeners(t); | |
| for (const type of eventTypes) { | |
| for (const l of (all[type] || [])) { | |
| try { | |
| t.removeEventListener(type, l.listener, l.useCapture ?? l.capture ?? false); | |
| } catch {} | |
| } | |
| } | |
| } | |
| } | |
| const guard = e => { | |
| if (e.ctrlKey && String(e.key).toLowerCase() === 'u') { | |
| e.stopImmediatePropagation(); | |
| } | |
| }; | |
| for (const t of targets) { | |
| for (const type of eventTypes) { | |
| t.addEventListener(type, guard, true); | |
| } | |
| } | |
| globalThis.__ctrlu_unblock_restore = () => { | |
| for (const t of targets) { | |
| for (const type of eventTypes) { | |
| t.removeEventListener(type, guard, true); | |
| } | |
| } | |
| for (const b of backup) { | |
| b.target.onkeydown = b.onkeydown; | |
| b.target.onkeypress = b.onkeypress; | |
| b.target.onkeyup = b.onkeyup; | |
| } | |
| delete globalThis.__ctrlu_unblock_restore; | |
| }; | |
| console.log('Ctrl+U unblock active; restore with __ctrlu_unblock_restore()'); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment