feat: add kb shortcut detection
This commit is contained in:
parent
e939174040
commit
cf2a5c2ffb
|
@ -28,6 +28,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ts", "ts", "{BB9F76AC-292A-
|
|||
src\ts\Author.ts = src\ts\Author.ts
|
||||
src\ts\TimeUtility.ts = src\ts\TimeUtility.ts
|
||||
src\ts\UI.ts = src\ts\UI.ts
|
||||
src\ts\Input.ts = src\ts\Input.ts
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
class Input {
|
||||
public static readonly KONAMI_CODE = [
|
||||
"ArrowUp",
|
||||
"ArrowUp",
|
||||
"ArrowDown",
|
||||
"ArrowDown",
|
||||
"ArrowLeft",
|
||||
"ArrowRight",
|
||||
"ArrowLeft",
|
||||
"ArrowRight",
|
||||
"b",
|
||||
"a",
|
||||
"Enter"
|
||||
];
|
||||
|
||||
public static registerShortcut(shortcut: string | string[], callback: Function) {
|
||||
let keys: string[];
|
||||
if (typeof shortcut === 'string') keys = shortcut.split(' ');
|
||||
else keys = shortcut;
|
||||
|
||||
let sequence: string[] = [];
|
||||
document.addEventListener('keydown', e => {
|
||||
sequence.push(e.key);
|
||||
|
||||
if (sequence.slice(-keys.length).join(' ') === keys.join(' ')) {
|
||||
callback();
|
||||
sequence = [];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default Input;
|
|
@ -1,9 +1,14 @@
|
|||
import API from "./API";
|
||||
import API from "./API";
|
||||
import UI from "./UI";
|
||||
import Input from "./Input";
|
||||
|
||||
declare const Handlebars: any;
|
||||
|
||||
(() => {
|
||||
Input.registerShortcut(Input.KONAMI_CODE, () => {
|
||||
window.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "_blank");
|
||||
});
|
||||
|
||||
const blogPostContainer = UI.blogPostContainer;
|
||||
if (blogPostContainer) {
|
||||
const template = Handlebars.compile(UI.blogPostTemplate.innerHTML);
|
||||
|
|
Loading…
Reference in New Issue