Created
July 8, 2018 02:57
-
-
Save AyrA/2c24609f617c1a887504b9a0473d3d01 to your computer and use it in GitHub Desktop.
JS Konami code script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Small konami code script that doesn't uses the usual method of an integer array | |
//Either run this through a minifier or remove the comments, | |
//otherwise people can just search for "konami" or variable name combinations | |
//The string of the konami code itself is almost impossible to find by using search engines. | |
//Params: | |
//cb - required(function), called on complete sequence with all 3 parameters | |
//check - optional(function), checks if key presses should be evaluated, called with all 3 parameters. | |
//single - optional(bool), if set to something that evaluates to 'true' the secret can only be used once. | |
(function (cb, check, single) { | |
var d = "&&((%'%'BA"; | |
var i = 0; | |
if (typeof(cb) === typeof(function () {})) { | |
document.addEventListener("keydown", function (e) { | |
if (typeof(check) !== typeof(cb) || check(cb, check, single)) { | |
if (i < d.length && d.charCodeAt(i) === e.keyCode) { | |
if (++i === d.length) { | |
i = 0; | |
if (single) { | |
d = ""; | |
} | |
cb(cb, check, single); | |
} | |
} else { | |
i = 0; | |
} | |
} | |
}); | |
} | |
})(/*PARAMS HERE*/); | |
//Example of a single use alert box that can only be triggered | |
//if the document title has been set to a certain value. | |
//Param 1: | |
//window.alert.bind(window, "You found it") | |
//Param 2: | |
//function () {return document.title === "SECRET";} | |
//Param 3: | |
//true | |
// -- /u/AyrA_ch | |
//Licensed under MIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment