the-glorious-startpage/js/keybindings.js

75 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-06-04 09:09:22 +02:00
let keysPressed = {};
document.addEventListener(
'keydown',
(event) => {
2020-06-04 09:18:32 +02:00
keysPressed[event.key] = true;
2020-06-04 09:09:22 +02:00
// Open dashboard
if (keysPressed['Alt'] && event.key === 's') {
2020-06-04 09:18:32 +02:00
event.preventDefault();
2020-06-04 09:09:22 +02:00
toggleDashboard();
return;
} else if (keysPressed['Alt'] && event.key === 'e') {
2020-06-04 09:18:32 +02:00
event.preventDefault();
2020-06-04 09:09:22 +02:00
toggleWebMenu();
return;
} else if (keysPressed['Alt'] && event.key === 'x') {
2020-06-04 09:18:32 +02:00
event.preventDefault();
2020-06-04 09:09:22 +02:00
toggleWeatherScreen();
return;
}
2020-06-04 09:18:32 +02:00
if (event.key === 'Escape') {
// If searchbox is visible, hide and clear input field
if (searchBoxVisility) {
// Hide searchbox
toggleSearchBox();
searchBox.value = '';
return;
};
// Show web menu
toggleWebMenu();
return;
}
if (searchBoxVisility === false) {
// Don't show searchbox when web menu, dashboard
// and weather screen is open
if (webMenuVisibility || weatherScreenVisibility ||
rightDashboardVisibility) return;
// Dont accept ctrl, alt,
// left window key, f5, f12, return
if (event.key === 'Control' ||
event.key === 'Alt' ||
event.key === 'Shift' ||
event.key === 'Meta' ||
event.key === 'F5' ||
event.key === 'F12' ||
event.key === 'Enter')
return;
// Open searchbox
toggleSearchBox();
} else {
// Backspacing while there's no search query will hide searhbox
// Will also hide if you hit enter
if ((event.key === 'Backspace' || event.key === 'Enter') &&
searchBox.value < 1) { toggleSearchBox(); return; };
}
2020-06-04 09:09:22 +02:00
}
);
document.addEventListener(
'keyup',
(event) => {
delete keysPressed[event.key];
}
);