projects
/
invirt/packages/invirt-web.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Remove quadratic-complexity keylogger from Konami easter egg
[invirt/packages/invirt-web.git]
/
code
/
static
/
nc.js
diff --git
a/code/static/nc.js
b/code/static/nc.js
index
4ea168f
..
b82ed8b
100644
(file)
--- a/
code/static/nc.js
+++ b/
code/static/nc.js
@@
-1,9
+1,12
@@
-var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
+var konami = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65],
+ konami_jump = [-1, 0, 1, 0, 0, 0, 0, 0, 0, 0],
+ konami_state = 0;
document.onkeydown = function (e) {
document.onkeydown = function (e) {
- kkeys.push(e.keyCode);
- var idx = kkeys.toString().indexOf( konami );
- if (idx >= 0 && idx != kkeys.toString().length - konami.length) {
- kkeys = [];
- window.location.assign("http://nyan.cat/");
+ while (konami_state != -1 && e.keyCode != konami[konami_state]) {
+ konami_state = konami_jump[konami_state];
+ }
+ if (++konami_state == konami.length) {
+ window.location.assign("http://nyan.cat/");
+ konami_state = 0;
}
};
}
};