added code

This commit is contained in:
2015-04-10 19:40:17 +02:00
parent 553972b6ac
commit da1234ef0a
3 changed files with 54 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
*~
.idea/
+19
View File
@@ -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>
+31
View File
@@ -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);