Skip to content

Commit

Permalink
add konamicode
Browse files Browse the repository at this point in the history
  • Loading branch information
renaholic committed Mar 18, 2023
1 parent 0074bf0 commit 8554ee4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/routes/swipe/konamiCode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { $, useOnDocument, useStore } from '@builder.io/qwik';
import _ from 'lodash';
import Toastify from 'toastify-js';


export const konamiCode = [
'ArrowUp',
'ArrowUp',
'ArrowDown',
'ArrowDown',
'ArrowLeft',
'ArrowRight',
'ArrowLeft',
'ArrowRight',
'b',
'a',
];

export const useKonamiCode = () => {
const keyPresses = useStore({
presses: [] as string[],
});
useOnDocument(
'keydown',
$((ev) => {
const event = ev as KeyboardEvent;
keyPresses.presses = _.takeRight([...keyPresses.presses, event.key], 10);
if (_.isEqual(keyPresses.presses, konamiCode)) {
Toastify({
text: 'Konami code!',
duration: 3000,
close: true,
gravity: 'top',
position: 'left',
stopOnFocus: true, // Prevents dismissing of toast on hover
}).showToast();
}
})
);
};

0 comments on commit 8554ee4

Please sign in to comment.