1/* 2 * Konami-JS ~ 3 * :: Now with support for touch events and multiple instances for 4 * :: those situations that call for multiple easter eggs! 5 * Code: https://github.com/georgemandis/konami-js 6 * Copyright (c) 2009 George Mandis (https://george.mand.is) 7 * Version: 1.6.3 (11/11/2021) 8 * Licensed under the MIT License (http://opensource.org/licenses/MIT) 9 * Tested in: Safari 4+, Google Chrome 4+, Firefox 3+, IE7+, Mobile Safari 2.2.1+ and Android 10 */ 11 12var Konami = function (callback) { 13 var konami = { 14 addEvent: function (obj, type, fn, ref_obj) { 15 if (obj.addEventListener) 16 obj.addEventListener(type, fn, false); 17 else if (obj.attachEvent) { 18 // IE 19 obj["e" + type + fn] = fn; 20 obj[type + fn] = function () { 21 obj["e" + type + fn](window.event, ref_obj); 22 } 23 obj.attachEvent("on" + type, obj[type + fn]); 24 } 25 }, 26 removeEvent: function (obj, eventName, eventCallback) { 27 if (obj.removeEventListener) { 28 obj.removeEventListener(eventName, eventCallback); 29 } else if (obj.attachEvent) { 30 obj.detachEvent(eventName); 31 } 32 }, 33 input: "", 34 pattern: "38384040373937396665", 35 keydownHandler: function (e, ref_obj) { 36 if (ref_obj) { 37 konami = ref_obj; 38 } // IE 39 konami.input += e ? e.keyCode : event.keyCode; 40 if (konami.input.length > konami.pattern.length) { 41 konami.input = konami.input.substr((konami.input.length - konami.pattern.length)); 42 } 43 if (konami.input === konami.pattern) { 44 konami.code(konami._currentLink); 45 konami.input = ''; 46 e.preventDefault(); 47 return false; 48 } 49 }, 50 load: function (link) { 51 this._currentLink = link; 52 this.addEvent(document, "keydown", this.keydownHandler, this); 53 this.iphone.load(link); 54 }, 55 unload: function () { 56 this.removeEvent(document, 'keydown', this.keydownHandler); 57 this.iphone.unload(); 58 }, 59 code: function (link) { 60 window.location = link 61 }, 62 iphone: { 63 start_x: 0, 64 start_y: 0, 65 stop_x: 0, 66 stop_y: 0, 67 tap: false, 68 capture: false, 69 orig_keys: "", 70 keys: ["UP", "UP", "DOWN", "DOWN", "LEFT", "RIGHT", "LEFT", "RIGHT", "TAP", "TAP"], 71 input: [], 72 code: function (link) { 73 konami.code(link); 74 }, 75 touchmoveHandler: function (e) { 76 if (e.touches.length === 1 && konami.iphone.capture === true) { 77 var touch = e.touches[0]; 78 konami.iphone.stop_x = touch.pageX; 79 konami.iphone.stop_y = touch.pageY; 80 konami.iphone.tap = false; 81 konami.iphone.capture = false; 82 konami.iphone.check_direction(); 83 } 84 }, 85 touchendHandler: function () { 86 konami.iphone.input.push(konami.iphone.check_direction()); 87 88 if (konami.iphone.input.length > konami.iphone.keys.length) konami.iphone.input.shift(); 89 90 if (konami.iphone.input.length === konami.iphone.keys.length) { 91 var match = true; 92 for (var i = 0; i < konami.iphone.keys.length; i++) { 93 if (konami.iphone.input[i] !== konami.iphone.keys[i]) { 94 match = false; 95 } 96 } 97 if (match) { 98 konami.iphone.code(konami._currentLink); 99 } 100 } 101 }, 102 touchstartHandler: function (e) { 103 konami.iphone.start_x = e.changedTouches[0].pageX; 104 konami.iphone.start_y = e.changedTouches[0].pageY; 105 konami.iphone.tap = true; 106 konami.iphone.capture = true; 107 }, 108 load: function (link) { 109 this.orig_keys = this.keys; 110 konami.addEvent(document, "touchmove", this.touchmoveHandler); 111 konami.addEvent(document, "touchend", this.touchendHandler, false); 112 konami.addEvent(document, "touchstart", this.touchstartHandler); 113 }, 114 unload: function () { 115 konami.removeEvent(document, 'touchmove', this.touchmoveHandler); 116 konami.removeEvent(document, 'touchend', this.touchendHandler); 117 konami.removeEvent(document, 'touchstart', this.touchstartHandler); 118 }, 119 check_direction: function () { 120 x_magnitude = Math.abs(this.start_x - this.stop_x); 121 y_magnitude = Math.abs(this.start_y - this.stop_y); 122 x = ((this.start_x - this.stop_x) < 0) ? "RIGHT" : "LEFT"; 123 y = ((this.start_y - this.stop_y) < 0) ? "DOWN" : "UP"; 124 result = (x_magnitude > y_magnitude) ? x : y; 125 result = (this.tap === true) ? "TAP" : result; 126 return result; 127 } 128 } 129 } 130 131 typeof callback === "string" && konami.load(callback); 132 if (typeof callback === "function") { 133 konami.code = callback; 134 konami.load(); 135 } 136 137 return konami; 138}; 139 140 141if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { 142 module.exports = Konami; 143} else { 144 if (typeof define === 'function' && define.amd) { 145 define([], function() { 146 return Konami; 147 }); 148 } else {
149 window.Konami = Konami; 150 } 151}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.