31 lines
751 B
JavaScript
31 lines
751 B
JavaScript
|
function initUiObservers(store, _router) {
|
||
|
let keyHistory = [];
|
||
|
|
||
|
document.addEventListener('keypress', (event) => {
|
||
|
if (event.target.tagName === 'INPUT') {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
keyHistory = keyHistory
|
||
|
.concat({
|
||
|
key: event.key,
|
||
|
time: new Date().getTime(),
|
||
|
})
|
||
|
.slice(-3);
|
||
|
|
||
|
if (keyHistory.length === 3
|
||
|
&& keyHistory.every(input => input.key === 's')
|
||
|
&& new Date().getTime() - keyHistory[0].time < 1000
|
||
|
) {
|
||
|
store.dispatch('setSfw', false);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (event.key === 's') {
|
||
|
store.dispatch('setSfw', true);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export default initUiObservers;
|