You've already forked konami-code-snippets
mirror of
https://github.com/hexolan/konami-code-snippets.git
synced 2026-05-20 11:39:22 +01:00
feat(package): minifying js
feat(src): refactor for library usage refactor: move examples to root dir
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>KC Examples: Redirect</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Enter the code</p>
|
||||
|
||||
<script>
|
||||
const keySequence = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "a"];
|
||||
let sequenceStep = 0;
|
||||
|
||||
document.addEventListener("keydown", function (e) {
|
||||
console.log(e)
|
||||
if (keySequence[sequenceStep] === e.key) {
|
||||
sequenceStep += 1;
|
||||
|
||||
if (sequenceStep === keySequence.length) {
|
||||
window.location.href = `https://github.com/hexolan/konami-code-snippets`;
|
||||
}
|
||||
} else {
|
||||
sequenceStep = 0;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+8
-10
@@ -1,22 +1,20 @@
|
||||
// NOTE: not using deprecated `keyCode` attribute
|
||||
const keySequence = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "a"];
|
||||
let sequenceStep = 0;
|
||||
|
||||
function callbackFunc() {
|
||||
|
||||
}
|
||||
|
||||
// TODO: as func to pass to `keydown` listener
|
||||
document.addEventListener("keydown", function (e) {
|
||||
console.log(e)
|
||||
let handleKonami = (e) => (callback) => {
|
||||
if (keySequence[sequenceStep] === e.key) {
|
||||
sequenceStep += 1;
|
||||
|
||||
if (sequenceStep === keySequence.length) {
|
||||
sequenceStep = 0;
|
||||
callbackFunc();
|
||||
callback();
|
||||
}
|
||||
} else {
|
||||
sequenceStep = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Example usage:
|
||||
document.addEventListener("keydown", handleKonami(() => {
|
||||
console.log('konami!');
|
||||
}));
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
let a=['ArrowUp','ArrowUp','ArrowDown','ArrowDown','ArrowLeft','ArrowRight','ArrowLeft','ArrowRight','b','a'];let b=0;document.addEventListener('keydown',(e=>A=>{if(a[b]===e.key){b+=1;b===a.length&&(b=0,A())}else b=0})(()=>console.log('konami!')));
|
||||
Reference in New Issue
Block a user