-
Notifications
You must be signed in to change notification settings - Fork 24
/
decrypto.js
130 lines (111 loc) · 2.27 KB
/
decrypto.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
var wordList;
function loadWordList() {
var wordList;
$.ajax({
url : "wordlist.txt",
dataType: "text",
success : function (data) {
wordList = data.split("\n");
},
async: false
});
return wordList;
}
function pickWords(numWords) {
return _.sample(wordList, numWords);
}
function generateCode() {
var code = _.sample([1,2,3,4], 3);
Cookies.set("code", code);
setCode(code);
$('#codeModal').modal('show');
}
function setCode(code) {
for(idx = 0; idx < 3; idx++) {
$('#code' + idx).text(code[idx]);
}
$('#revealCodeButton').show();
}
function setWords(words) {
for(idx = 0; idx < 4; idx++) {
$('#word' + idx).text(words[idx]);
}
}
function loadWords() {
return Cookies.getJSON("words");
}
function loadCode() {
var code = Cookies.getJSON("code");
if (code) {
setCode(code);
} else {
$('#revealCodeButton').hide();
}
}
function newGame() {
var words = pickWords(4);
Cookies.set("words", words);
Cookies.remove("code");
$('#revealCodeButton').hide();
return words;
}
function toggleFullScreen() {
if (screenfull.isFullscreen) {
screenfull.exit();
} else {
screenfull.request();
}
setFullScreenIcon();
}
function setFullScreenIcon() {
if (screenfull.isFullscreen) {
$('#enableFullScreen').hide();
$('#disableFullScreen').show();
} else {
$('#enableFullScreen').show();
$('#disableFullScreen').hide();
}
}
function startNewGame() {
setWords(newGame());
}
function disableScreenLock() {
var noSleep = new NoSleep();
noSleep.enable();
}
function initScreenfull() {
var noSleep = new NoSleep();
if (screenfull.enabled) {
screenfull.on('change', () => {
if (screenfull.isFullscreen) {
noSleep.enable();
} else {
noSleep.disable();
}
});
setInterval(setFullScreenIcon, 200);
} else {
$('#fullScreenButton').hide();
$('#disableScreenLockModal').modal('show');
}
}
function initialize() {
initScreenfull();
wordList = loadWordList();
loadCode();
var words = loadWords();
if (words) {
setWords(words);
} else {
/*
startNewGame();
$('#newGameModalCancelButton').hide();
$('#newGameModal').modal({
show: true,
keyboard: false,
backdrop: 'static'
});
*/
$('#newGameModal').modal('show');
}
}