Konami 密技 JavaScript 簡單實作
Table of Contents
#
Konami 密技 JavaScript 簡單實作
最近有一個網站很紅 vogue 上上下下左右左右BA 接下來就狂按 A
身為一個宅宅前端攻城獅一定要學起來這招(以後就藏一些東西在程式中)
var keyCount = 0;
window.onkeydown = konami;
function konami(e) {
if (e.keyCode === 38 && keyCount === 0) {
keyCount++;
console.log(keyCount);
} else if (e.keyCode === 38 && keyCount === 1) {
keyCount++;
console.log(keyCount);
} else if (e.keyCode === 40 && keyCount === 2) {
keyCount++;
console.log(keyCount);
} else if (e.keyCode === 40 && keyCount === 3) {
keyCount++;
console.log(keyCount);
} else if (e.keyCode === 37 && keyCount === 4) {
keyCount++;
console.log(keyCount);
} else if (e.keyCode === 39 && keyCount === 5) {
keyCount++;
console.log(keyCount);
} else if (e.keyCode === 37 && keyCount === 6) {
keyCount++;
console.log(keyCount);
} else if (e.keyCode === 39 && keyCount === 7) {
keyCount++;
console.log(keyCount);
} else if (e.keyCode === 66 && keyCount === 8) {
keyCount++;
console.log(keyCount);
} else if (e.keyCode === 65 && keyCount === 9) {
keyCount = 0;
console.log('Konami');
alert('打密技阿你');
} else {
keyCount = 0;
console.log('fail');
}
}