New tweak: disable L-to-like
User-facing changes
- Adds a tweak that disables the L-to-like keyboard shortcut.
Technical explanation
The event listener that handles page-wide keyboard shortcuts are attached directly to the document element (document.addEventListener("keydown", this.onKeyDown)), so this prevents the L key event from reaching it even when no element is selected (document.activeElement is the body element).
I could inject a function that calls disableHotkeys('KeyL') and enableHotkeys('KeyL') on the big app component in the Redpop internals instead, which is sort of cuter but way more complicated and prone to breakage for no reason.
Issues this closes
n/a
The fun way:
import { inject } from '../../util/inject.js';
const controlHotkeys = (funcName, ...args) => {
const baseContainerElement = document.querySelector('#base-container');
const reactKey = Object.keys(baseContainerElement).find(key => key.startsWith('__reactFiber'));
let fiber = baseContainerElement[reactKey];
while (fiber !== null) {
if (fiber.stateNode?.[funcName] !== undefined) {
fiber.stateNode[funcName](...args);
return;
} else {
fiber = fiber.return;
}
}
};
const disableHotkeys = (keys) => inject(controlHotkeys, ['disableHotkeys', keys]);
const enableHotkeys = (keys) => inject(controlHotkeys, ['enableHotkeys', keys]);
export const main = async () => disableHotkeys(['KeyL']);
export const clean = async () => enableHotkeys(['KeyL']);
I don't plan to review this. It would be fun to have completely configurably keyboard shortcuts, but just the shortcut for liking is too niche on its own to justify its place in Tweaks.