Skip to content

Instantly share code, notes, and snippets.

@m1k3yfoo
Created December 30, 2017 21:39
Show Gist options
  • Save m1k3yfoo/34b0ace211c978e2c041c41cd6bba5a9 to your computer and use it in GitHub Desktop.
Save m1k3yfoo/34b0ace211c978e2c041c41cd6bba5a9 to your computer and use it in GitHub Desktop.
[Konami Cheat Code Sequence] #CSS, #JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Key Detection</title>
<script type="text/javascript" src="http://www.cornify.com/js/cornify.js"></script>
</head>
<body>
<script>
const typed = [];
// Konami cheat code sequence
// Array of keyCode for up, down, up, down, left, right, left, right, B, A, B
const secretCodeArr = [38, 40, 38, 40, 37, 39, 37, 39, 66, 65, 66];
const secretCodeStr = '3840384037393739666566';
window.addEventListener('keyup', (e) => {
console.log(e);
typed.push(e.keyCode);
// Counting from the end 7 characters (assuming secretCode is 6 letters), the 2nd parameter is deleteCount
typed.splice(-secretCodeArr.length - 1,
typed.length - secretCodeArr.length);
console.log(typed);
// Converts
if (typed.join('').includes(secretCodeStr)) {
cornify_add();
}
let myFish = ['angel', 'clown', 'mandarin', 'surgeon'];
// removes 2 elements from the second postion from the end
let removed = myFish.splice(-2, 2);
console.log(removed); // Returns ['mandarin', 'surgeon'];
console.log(myFish); // Returns ['angel', 'clown'];
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment