Skip to content

Instantly share code, notes, and snippets.

@eugrus
Created April 29, 2026 11:07
Show Gist options
  • Select an option

  • Save eugrus/55f66c0adc01bdb4a27b31fe039f8f48 to your computer and use it in GitHub Desktop.

Select an option

Save eugrus/55f66c0adc01bdb4a27b31fe039f8f48 to your computer and use it in GitHub Desktop.
Deactivate Ctrl+U capturers
(() => {
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