Last active
December 2, 2020 09:10
-
-
Save kapsh/afdac0d51b3be1efa8f28f65bd626d00 to your computer and use it in GitHub Desktop.
This file contains 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 zulip hotkeys fix | |
// @namespace Violentmonkey Scripts | |
// @match https://chat.zulip.org/ | |
// @grant none | |
// @version 1.0 | |
// @author kapsh | |
// @description Make zulip hotkeys work on any (?) layout (see https://github.com/zulip/zulip/issues/7517) | |
// @downloadURL https://gist.github.com/kapsh/afdac0d51b3be1efa8f28f65bd626d00/raw/zulip_hotkeys.user.js | |
// @updateURL https://gist.github.com/kapsh/afdac0d51b3be1efa8f28f65bd626d00/raw/zulip_hotkeys.user.js | |
// ==/UserScript== | |
(() => { | |
// Map KeyboardEvent.code used in hotkey.js to .which values from english layout | |
const scanCodes = { | |
"KeyC": 99, | |
"KeyD": 100, | |
"KeyE": 101, | |
"KeyG": 103, | |
"KeyH": 104, | |
"KeyI": 105, | |
"KeyJ": 106, | |
"KeyK": 107, | |
"KeyL": 108, | |
"KeyN": 110, | |
"KeyP": 112, | |
"KeyQ": 113, | |
"KeyR": 114, | |
"KeyS": 115, | |
"KeyT": 116, | |
"KeyU": 117, | |
"KeyV": 118, | |
"KeyW": 119, | |
"KeyX": 120, | |
"Slash": 47, | |
} | |
const scanCodesShift = { | |
"KeyA": 65, | |
"KeyC": 67, | |
"KeyD": 68, | |
"KeyG": 71, | |
"KeyJ": 74, | |
"KeyK": 75, | |
"KeyM": 77, | |
"KeyP": 80, | |
"KeyR": 82, | |
"KeyS": 83, | |
"KeyV": 86, | |
"Digit2": 64, | |
"Period": 62, | |
"Semicolon": 58, | |
"Slash": 63, | |
} | |
function loggedAction(funcName, hotkey) { | |
console.log(`${funcName} detected ${hotkey? hotkey.name : "none"}`); | |
return hotkey; | |
} | |
function wrapHotkeyFunc(name) { | |
var orig = window.hotkey[name]; | |
window.hotkey[name] = (e) => { | |
e.which = (e.shiftKey? scanCodesShift[e.code] : scanCodes[e.code]) || e.which | |
// return loggedAction(name, orig(e)); | |
return orig(e); | |
} | |
} | |
wrapHotkeyFunc("get_keydown_hotkey"); | |
wrapHotkeyFunc("get_keypress_hotkey"); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment