MovieNight/static/js/both.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

/// <reference path="./jquery.js" />
2019-03-29 02:55:28 +01:00
let konamiCode = ["ArrowUp", "ArrowUp", "ArrowDown", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "b", "a"]
let lastKeys = []
let devKeys = false;
2019-03-29 02:55:28 +01:00
// Make this on all pages so video page also doesn't do this
$(document).on("keydown", function (e) {
lastKeys.push(e);
if (lastKeys.length > 10) {
lastKeys.shift();
}
if (devKeys) {
let modifiedLastKeys = []
lastKeys.forEach((e) => {
switch (e.key) {
case " ":
modifiedLastKeys.push(`Space - ${e.keyCode}`);
break;
default:
modifiedLastKeys.push(`${e.key} - ${e.keyCode}`);
break;
}
})
$("#devKeys").html(`'${modifiedLastKeys.join("', '")}'`);
}
2019-03-29 02:55:28 +01:00
if (e.which === 8 && !$(e.target).is("input, textarea")) {
e.preventDefault();
}
checkKonami(e);
});
2019-03-29 02:55:28 +01:00
function checkKonami(e) {
if (lastKeys.length === konamiCode.length) {
for (let i = 0; i < lastKeys.length; i++) {
if (lastKeys[i].key != konamiCode[i]) {
2019-03-29 02:55:28 +01:00
return;
}
}
$("#remote").css("display", "block");
2019-03-29 02:55:28 +01:00
}
}
function flipRemote() {
$("#remote").attr("src", "/static/img/remote_active.png");
setTimeout(() => {
$("#remote").attr("src", "/static/img/remote.png");
}, Math.round(Math.random() * 10000) + 1000);
}
function enableDebug() {
devKeys = true;
$("#devKeys").css("display", "block");
}
/*
// Just add a / above to uncomment the block
setTimeout(() => {
enableDebug();
alert("Comment this out. It shows the keys.");
}, 150);
//*/