parent
553972b6ac
commit
da1234ef0a
@ -0,0 +1,4 @@ |
|||||||
|
*~ |
||||||
|
.idea/ |
||||||
|
|
||||||
|
|
@ -0,0 +1,19 @@ |
|||||||
|
<!DOCTYPE HTML> |
||||||
|
<html> |
||||||
|
<head> |
||||||
|
<title>Konami code example</title> |
||||||
|
|
||||||
|
<script src="konami.js"></script> |
||||||
|
|
||||||
|
<script> |
||||||
|
konami(function () { |
||||||
|
var html = document.getElementsByTagName('html')[0]; |
||||||
|
html.style.backgroundColor = 'black'; |
||||||
|
html.style.color = 'white'; |
||||||
|
}); |
||||||
|
</script> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
blah blah |
||||||
|
</body> |
||||||
|
</html> |
@ -0,0 +1,31 @@ |
|||||||
|
(function (window) { |
||||||
|
"use strict"; |
||||||
|
|
||||||
|
var d = window.document; |
||||||
|
var keys = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]; |
||||||
|
var progress = 0; |
||||||
|
|
||||||
|
window.konami = function (h) { |
||||||
|
var listener = function (e) { |
||||||
|
if (e.keyCode == keys[progress]) { |
||||||
|
if (++progress == keys.length) { |
||||||
|
console.log('コナミ'); |
||||||
|
|
||||||
|
if (typeof h == 'function') { |
||||||
|
h(); |
||||||
|
} |
||||||
|
|
||||||
|
progress = 0; |
||||||
|
} |
||||||
|
} else { |
||||||
|
progress = 0; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
if (d.addEventListener) { |
||||||
|
d.addEventListener('keyup', listener); |
||||||
|
} else { |
||||||
|
d.onkeyup = listener; |
||||||
|
} |
||||||
|
}; |
||||||
|
})(window); |
Loading…
Reference in new issue