-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjavascript.js
executable file
·202 lines (175 loc) · 6.7 KB
/
javascript.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
195
196
197
198
199
200
201
202
var top_score = 0;
var bottom_score = 0;
var top_game_score = 0;
var bottom_game_score = 0;
function swapserve(force_switch = false) {
if ((!((top_score + bottom_score) % 2) || ((top_score >= 10) && (bottom_score >= 10))) || force_switch) {
var top_player = document.getElementById("serve_indicator_top_player");
var bottom_player = document.getElementById("serve_indicator_bottom_player");
if (top_player.style.display === "none") {
top_player.style.display = "block";
bottom_player.style.display = "none";
} else {
top_player.style.display = "none";
bottom_player.style.display = "block";
}
}
checkgameormatchpoint();
};
function checkgameormatchpoint() {
// gamepoint calculation
var gamepoint = document.getElementById("gamepoint");
var match_mode = document.getElementById("match_mode");
var gamemode = document.querySelector('input[name="gamemode"]:checked').id;
match_mode.innerText = gamemode;
// alert("top_score: " + top_score);
// alert("bottom_score: " + bottom_score);
if ((top_score >= 10 && bottom_score < 10) || (bottom_score >= 10 && top_score < 10) || (((top_score >= 10) && (bottom_score >= 10)) && (bottom_score != top_score))) {
gamepoint.innerText = "GAME POINT";
// gamepoint.style.display = "block";
gamepoint.style.visibility = 'visible';
gamepoint.style.height = "26%";
gamepoint.style.width = "auto";
gamepoint.style.padding = '3px';
gamepoint.style.paddingLeft = '13px';
gamepoint.style.paddingRight = '13px';
gamepoint.style.left = gamepoint.style.left;
} else {
gamepoint.innerText = "";
// gamepoint.style.display = "none";
gamepoint.style.visibility = 'hidden';
//hint.style.opacity = '0';
gamepoint.style.height = '0';
gamepoint.style.width = '0';
gamepoint.style.padding = '0';
}
// matchpoint calculation
if (gamepoint.style.visibility == "visible") {
gamemode = document.querySelector('input[name="gamemode"]:checked').value;
// alert(gamemode);
if ((top_game_score == gamemode - 1 && top_score > bottom_score) || (bottom_game_score == gamemode - 1 && bottom_score > top_score)) {
gamepoint.innerText = "MATCH POINT";
// change position because MATCHPOINT has more character than GAMEPOINT
// so that it lines up with the end of the top player's score <div>
// gamepoint.style.left = "199%";
}
}
};
function topi() {
top_score = top_score + 1;
document.getElementById('top_score').innerHTML = top_score;
swapserve();
};
function topm() {
top_score = top_score - 1;
document.getElementById('top_score').innerHTML = top_score;
swapserve();
};
function topr() {
top_score = 0;
document.getElementById('top_score').innerHTML = top_score;
swapserve();
};
function bottomi() {
bottom_score = bottom_score + 1;
document.getElementById('bottom_score').innerHTML = bottom_score;
swapserve();
};
function bottomm() {
bottom_score = bottom_score - 1;
document.getElementById('bottom_score').innerHTML = bottom_score;
};
function bottomr() {
bottom_score = 0;
document.getElementById('bottom_score').innerHTML = bottom_score;
};
function nextgame() {
// var gamepoint = document.getElementById("gamepoint");
// gamepoint.innerText = "";
// // gamepoint.style.display = "none";
// gamepoint.style.visibility = 'hidden';
// //hint.style.opacity = '0';
// gamepoint.style.height = '0';
// gamepoint.style.width = '0';
// gamepoint.style.padding = '0';
document.getElementById('bottom_score').innerHTML = bottom_score;
document.getElementById('top_score').innerHTML = top_score;
if (top_score > bottom_score) {
top_game_score = top_game_score + 1
} else {
bottom_game_score = bottom_game_score + 1
}
document.getElementById('bottom_game_score').innerHTML = bottom_game_score;
document.getElementById('top_game_score').innerHTML = top_game_score;
topr();
bottomr();
swapserve();
};
function resetall() {
bottom_game_score = 0;
top_game_score = 0;
document.getElementById("gamepoint").visibility = "hidden";
document.getElementById('bottom_game_score').innerHTML = bottom_game_score;
document.getElementById('top_game_score').innerHTML = top_game_score;
topr();
bottomr();
};
function toggle_header_text() {
score_text = document.getElementById('score_text').innerHTML;
game_text = document.getElementById('game_text').innerHTML;
if (score_text == "" || game_text == "") {
document.getElementById('score_text').innerHTML = "Points";
document.getElementById('game_text').innerHTML = "Games";
} else {
document.getElementById('score_text').innerHTML = "";
document.getElementById('game_text').innerHTML = "";
}
};
function toggle_match_mode_text() {
match_mode = document.getElementById('match_mode');
if (match_mode.style.visibility == "visible") {
match_mode.style.visibility = 'hidden';
checkgameormatchpoint();
} else {
match_mode.style.visibility = 'visible';
}
};
// color selector stuff
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color
var color_top_player;
var color_bottom_player;
var top_defaultColor = "#008000";
var bottom_defaultColor = "#FF0000";
window.addEventListener("load", startup, false);
function startup() {
var top_defaultColor = "#008000";
var bottom_defaultColor = "#FF0000";
color_top_player = document.querySelector("#color_top_player");
if (color_top_player) {
color_top_player.value = top_defaultColor;
color_top_player.addEventListener("change", updateTopColor, false);
color_top_player.select();
}
if (color_bottom_player) {
color_bottom_player = document.querySelector("#color_bottom_player");
color_bottom_player.value = bottom_defaultColor;
color_bottom_player.addEventListener("change", updateBottomColor, false);
color_bottom_player.select();
}
}
function updateTopColor(event) {
document.querySelectorAll("#top_player").forEach(function (p) {
p.style.backgroundColor = event.target.value;
});
document.querySelectorAll("#top_score").forEach(function (p) {
p.style.backgroundColor = event.target.value;
});
}
function updateBottomColor(event) {
document.querySelectorAll("#bottom_player").forEach(function (p) {
p.style.backgroundColor = event.target.value;
});
document.querySelectorAll("#bottom_score").forEach(function (p) {
p.style.backgroundColor = event.target.value;
});
}