-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyPressListener.js
More file actions
32 lines (28 loc) · 841 Bytes
/
Copy pathkeyPressListener.js
File metadata and controls
32 lines (28 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
console.log('keyPressListener loaded');
const { USE_N_KEYS } = globalThis.settings;
if (window === top) {
window.addEventListener('keydown', doKeyPress, false);
}
const goToUrl = (url) => {
window.location.replace(url);
};
async function doKeyPress(e) {
console.log({ e }, USE_N_KEYS);
for (let index = 1; index <= USE_N_KEYS; index++) {
const key = index.toString();
if (e.altKey && e.key === key) {
e.preventDefault();
globalThis.getUrlValue(key, (url) => {
console.log({ url });
if (url.startsWith('https://stackoverflow.com/questions/')) {
goToUrl(url);
} else {
const extractedUrl = url.substring(url.indexOf('https://stackoverflow.com/questions/'));
if (extractedUrl) {
goToUrl(extractedUrl);
}
}
});
}
}
}