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
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
8c64c67c80
|
|||
|
fca497ac1e
|
@@ -1,12 +1,16 @@
|
||||
# Konami Code Snippets
|
||||
|
||||
The Konami Code (sometimes called the Contra Code) is a cheat code that has appeared in many Konami video games.
|
||||
The Konami Code (sometimes called the Contra Code) is a cheat code from many Konami video games.
|
||||
|
||||
It is now often used as a gag, homage or an easter egg within many products or websites.
|
||||
|
||||
> ↑ ↑ ↓ ↓ ← → ← → B A
|
||||
>
|
||||
> Up, Up, Down, Down, Left, Right, Left, Right, B, A
|
||||
|
||||
Read more about the Konami Code from the associated [Wikipedia entry](https://en.wikipedia.org/wiki/Konami_Code).
|
||||
|
||||
## Usage
|
||||
## 🚀 Usage
|
||||
|
||||
### JSDelivr
|
||||
|
||||
@@ -16,7 +20,7 @@ You can use this as a library within your web applications.
|
||||
|
||||
Version 1.0 (+ hotfixes): <https://cdn.jsdelivr.net/gh/hexolan/konami-code-snippets@1.0/src/core.min.js>
|
||||
|
||||
Latest Version: <https://cdn.jsdelivr.net/gh/hexolan/konami-code-snippets/src/core.min.js>
|
||||
Latest Version: <https://cdn.jsdelivr.net/gh/hexolan/konami-code-snippets@main/src/core.min.js>
|
||||
|
||||
#### Example
|
||||
|
||||
@@ -25,7 +29,7 @@ Latest Version: <https://cdn.jsdelivr.net/gh/hexolan/konami-code-snippets/src/co
|
||||
<body>
|
||||
(...content)
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/gh/hexolan/konami-code-snippets/src/core.min.js" />
|
||||
<script src="https://cdn.jsdelivr.net/gh/hexolan/konami-code-snippets@main/src/core.min.js"></script>
|
||||
|
||||
<script>
|
||||
document.addEventListener("keydown", handleKonami(() => {
|
||||
@@ -38,9 +42,9 @@ Latest Version: <https://cdn.jsdelivr.net/gh/hexolan/konami-code-snippets/src/co
|
||||
|
||||
### Direct
|
||||
|
||||
An example of direct usage can be seen within the source of [examples/redirect.html](/examples/redirect.html).
|
||||
An example of direct usage can be seen within the source of [examples/direct-nolib-unminified.html](/examples/direct-nolib-unminified.html).
|
||||
|
||||
## License
|
||||
## 📜 License
|
||||
|
||||
The code contained within this repository is released under the [MIT License](/LICENSE.txt).
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Konami Code Snippets: Redirect</title>
|
||||
<title>Konami Code Snippets: Nolib Usage</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Enter the code.</p>
|
||||
<p>Konami Code</p>
|
||||
|
||||
<script>
|
||||
const keySequence = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "a"];
|
||||
@@ -0,0 +1,19 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Konami Code Snippets: Direct Usage</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>Konami Code</p>
|
||||
|
||||
<script>
|
||||
const konamiSequence = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "a"]; let konamiStep = 0, handleKonami = callback => e => { konamiSequence[sequenceStep] === e.key ? (konamiStep += 1, konamiStep === konamiSequence.length && (konamiStep = 0, callback())) : konamiStep = 0 };
|
||||
|
||||
function konamiCallback() {
|
||||
window.location.href = `https://github.com/hexolan/konami-code-snippets`;
|
||||
}
|
||||
|
||||
document.addEventListener("keydown", handleKonami(konamiCallback));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,22 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Konami Code Snippets</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>Konami Code - O(1)</p>
|
||||
|
||||
<sup>Note: currently just lower case `b` and `a` keys.</sup>
|
||||
|
||||
<sup>(as using <code>event.code</code> not deprecated <code>event.keyCode</code>)</sup>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/gh/hexolan/konami-code-snippets@main/src/core.min.js"></script>
|
||||
<script>
|
||||
function konamiCallback() {
|
||||
window.location.href = `https://github.com/hexolan/konami-code-snippets`;
|
||||
}
|
||||
|
||||
document.addEventListener("keydown", handleKonami(konamiCallback));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
"author": "Declan Teevan <dt@hexolan.com>",
|
||||
"license": "MIT",
|
||||
"packageManager": "pnpm@10.33.0",
|
||||
"dependencies": {
|
||||
"devDependencies": {
|
||||
"minify": "^15.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+1
-1
@@ -7,7 +7,7 @@ settings:
|
||||
importers:
|
||||
|
||||
.:
|
||||
dependencies:
|
||||
devDependencies:
|
||||
minify:
|
||||
specifier: ^15.2.0
|
||||
version: 15.2.0(@emnapi/core@1.9.2)(@emnapi/runtime@1.9.2)
|
||||
|
||||
+10
-8
@@ -1,15 +1,17 @@
|
||||
const keySequence = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "a"];
|
||||
let sequenceStep = 0;
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
let handleKonami = (e) => (callback) => {
|
||||
if (keySequence[sequenceStep] === e.key) {
|
||||
sequenceStep += 1;
|
||||
const konamiSequence = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "a"];
|
||||
let konamiStep = 0;
|
||||
|
||||
if (sequenceStep === keySequence.length) {
|
||||
sequenceStep = 0;
|
||||
let handleKonami = (callback) => (e) => {
|
||||
if (konamiSequence[sequenceStep] === e.key) {
|
||||
konamiStep += 1;
|
||||
|
||||
if (konamiStep === konamiSequence.length) {
|
||||
konamiStep = 0;
|
||||
callback();
|
||||
}
|
||||
} else {
|
||||
sequenceStep = 0;
|
||||
konamiStep = 0;
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
const keySequence=["ArrowUp","ArrowUp","ArrowDown","ArrowDown","ArrowLeft","ArrowRight","ArrowLeft","ArrowRight","b","a"];let sequenceStep=0,handleKonami=e=>callback=>{keySequence[sequenceStep]===e.key?(sequenceStep+=1,sequenceStep===keySequence.length&&(sequenceStep=0,callback())):sequenceStep=0};
|
||||
const konamiSequence=["ArrowUp","ArrowUp","ArrowDown","ArrowDown","ArrowLeft","ArrowRight","ArrowLeft","ArrowRight","b","a"];let konamiStep=0,handleKonami=callback=>e=>{konamiSequence[sequenceStep]===e.key?(konamiStep+=1,konamiStep===konamiSequence.length&&(konamiStep=0,callback())):konamiStep=0};
|
||||
|
||||
Reference in New Issue
Block a user