-
Notifications
You must be signed in to change notification settings - Fork 3
/
bonus.js
194 lines (180 loc) · 5.1 KB
/
bonus.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* Shows/hides relevant bonus stars depending on game,
*
* @param {string} game The game.
* @param {boolean} keepHash If true the URL hash (location.hash) will not be removed. Hash will always be kept if it's not one of the bonus stars.
*/
function changeGame (game, keepHash) {
getElem('noBonusError').style.visibility = 'hidden';
if (game != 'all') {
var hideGames = document.querySelectorAll('.bonusStarContainer');
for (let num = 0; num < hideGames.length; num++) {
hideGames[num].style.display = 'none';
}
}
var showGames = [];
switch (game) {
case 'mp1':
case 'mp2':
case 'mp3':
case 'mp4':
case 'mp5':
showGames.push('happening');
showGames.push('minigame');
showGames.push('coin');
break;
case 'mp6':
showGames.push('happening');
showGames.push('minigame');
showGames.push('item');
break;
case 'mp7':
case 'mp8':
showGames.push('happening');
showGames.push('minigame');
showGames.push('red');
showGames.push('running');
showGames.push('shopping');
showGames.push('item');
break;
case 'mp9':
showGames.push('item');
showGames.push('spin');
case 'mp10':
showGames.push('minigame');
showGames.push('running');
showGames.push('slow');
showGames.push('minus');
break;
case 'mpds':
showGames.push('happening');
showGames.push('minigame');
showGames.push('running');
showGames.push('item');
showGames.push('friendship');
showGames.push('hex');
break;
case 'mpsr':
showGames.push('loner');
showGames.push('duel');
showGames.push('wanderer');
showGames.push('buddy');
case 'mptt100':
showGames.push('minigame');
showGames.push('running');
showGames.push('slow');
showGames.push('item');
showGames.push('unused');
showGames.push('balloon');
showGames.push('almost');
break;
case 'smp':
showGames.push('happening');
showGames.push('minigame');
showGames.push('coin');
showGames.push('red');
showGames.push('running');
showGames.push('slow');
showGames.push('item');
showGames.push('buddy');
showGames.push('ally');
showGames.push('stompy');
showGames.push('doormat');
break;
case 'mpa':
case 'mpit':
getElem('noBonusError').style.visibility = 'visible';
break;
case 'mps':
showGames.push('happening');
showGames.push('minigame');
showGames.push('coin');
showGames.push('red');
showGames.push('running');
showGames.push('slow');
showGames.push('shopping');
showGames.push('item');
showGames.push('bowser');
break;
default:
nodelist = document.querySelectorAll('.bonusStarContainer');
for (let num = 0; num < nodelist.length; num++) {
showGames.push(nodelist[num].id);
}
}
if (keepHash === true || location.hash === '#explanation' || location.hash === '#bonusStars' || location.hash === '#credits') {
history.replaceState(null, document.title, '?game=' + game + location.hash);
} else {
history.replaceState(null, document.title, '?game=' + game);
}
for (let num = 0; num < showGames.length; num++) {
getElem(showGames[num]).style.display = 'block';
var def = document.querySelector('#' + showGames[num] + ' .sub-' + game);
if (def === null)
var def = document.querySelector('#' + showGames[num] + ' .sub-all');
var title = document.querySelector('#' + showGames[num] + ' .sub-title');
if (title != null && def != null) {
title.title = def.title;
title.innerHTML = def.innerHTML.substring(2);
var elems = title.parentNode.children[1].children;
for (let num2 = 0; num2 < elems.length; num2++) {
elems[num2].style.display = 'inline';
}
def.style.display = 'none';
}
}
}
/*
* Changes Themes incl. greenscreen.
*
* @param {string} theme Which theme should be used.
* @param {string} theme What color should be used.
* @param {boolean} greenscreen If greenscreen should be used.
*/
function changeTheme (theme, color, greenscreen) {
if (greenscreen === true) {
document.querySelector('html').style.backgroundImage = 'unset';
document.querySelector('html').style.backgroundColor = color;
} else {
document.querySelector('html').style.backgroundImage = 'url("img/bgs/' + theme + '.jpg"), url("img/bgs/default.jpg")';
document.querySelector('html').style.backgroundColor = 'unset';
}
}
/*
* Checks if Ctrl & Shift is pressed.
*/
function keyPressed (e) {
if (e.key === 'Enter') {
var focused = document.activeElement;
if (focused.tagName === 'LABEL') {
var elem = getElem(focused.getAttribute('for'));
editValue(elem.id, true);
eval(elem.getAttribute('onchange'));
}
}
}
window.onkeydown = keyPressed;
/*
* Checks if the URL specifies a specific game or if a theme should be used.
*/
function startup () {
var game = getUrl('game');
if (game != false) {
try {
changeGame(game, true);
editValue(game, true);
} catch {
changeGame('all');
editValue('all', true);
}
}
if (location.hash != '') {
getElem(location.hash.substring(1)).scrollIntoView();
}
try {
var settings = JSON.parse(localStorage.getItem('settings'));
var theme = settings.theme;
changeTheme(settings.theme, settings.bgColor, settings.greenscreen)
} catch {}
}
window.onload = startup();