-
Notifications
You must be signed in to change notification settings - Fork 0
/
win_counters_stream.html
500 lines (441 loc) · 13.7 KB
/
win_counters_stream.html
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Win/Loss Counters</title>
<!-- Bootstrap core CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet">
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"></script>
<style>
main {
padding-top: 5px;
padding-left: 15px;
width: 320px;
}
.win-loss-span {
font-weight: bold;
font-size: 1em;
}
.counter {
text-align: center;
border: 1px solid black;
padding: 5px;
margin: 0 5px 5px;
}
.counter p, .counter h5 {
margin-bottom: 0 !important;
}
.counter button {
margin: 5px;
}
.close-counter {
margin-right: 5px;
color: black;
}
.counter .form-check-inline {
font-size: .8em;
}
* {
box-sizing: border-box;
}
.sidebar-toggle, .sidebar-item {
position: fixed;
z-index: 1;
outline: none;
margin-left: 20.25em;
margin-top: 0px;
cursor: pointer;
transition: 0.2s;
}
.sidebar-item {
margin-top: 25px;
}
.sidebar-toggle.is-closed, .sidebar-item.is-closed {
transform: translateX(0.3em) rotate(0deg);
margin-left: 0em;
}
}
.sidebar-toggle .icon, .sidebar-item .icon {
font-size: 1rem;
color: #000;
}
.sidebar {
width: 20em;
height: 100vh;
background-color: #fff;
transition: 0.2s;
/**border-right: 1px solid black;**/
position: absolute;
}
.sidebar.is-closed {
transform: translateX(-20em);
}
.sidebar .container {
margin: 10px;
}
#decks {
overflow-y: scroll;
height: 500px;
padding-left: 0 5px;
}
.deck:nth-child(even) {
background-color: #f5f5f5;
}
.add-deck-div, .event-label, .entry-fee {
margin-top: 8px !important;
}
.add-deck-div {
margin-left: auto;
margin-right: auto;
}
.event-label, .entry-fee, .add-deck-div {
text-align: right;
}
.add-deck-counter, .close-counter, .remove-deck, .plus{
float: right;
}
.add-deck-counter{
margin-right: 10px;
}
.deck {
clear: both;
}
.form-check-label {
margin: 3px 5px 0 0;
}
#counters {
height: 485px;
overflow-y: scroll;
}
a {
cursor: pointer;
}
sup {
top: -0.8em;
font-size: x-small;
}
li {
padding-left: 5px;
}
.form-check {
padding-left: 2.25rem !important;
}
.net-record {
margin-left: 5px;
}
.loss-record {
color: red;
}
.win-record {
color: green;
}
h5 {
font-size: .9em;
}
.counter p {
font-size: .8em;
}
</style>
<script src="https://use.fontawesome.com/d2b8364476.js"></script>
<script>
var stored = window.localStorage.getItem('decks');
var decks = stored != null ? JSON.parse(stored) : [];
var actions = [];
var used = [];
var event_log = [];
var counterNumber = 0;
var buildCounter = function(deck){
var code = getCode(deck) + counterNumber++;
var counter = buildCounterStructure(code);
counter.append(closeCounterLink(code))
counter.append(counterTitle(deck))
counter.append(winLossRow(code))
counter.append(rankedOrPlayedSelector(code))
counter.append(winLossButtons(code))
$('#counters').append(counter);
$('.sidebar-toggle').click();
$('#event').prop('checked',false);
//updateCosts(code);
};
var winLossButtons = function(code){
var btn_row = $('<div class=""></div>');
var win = $('<button class="btn btn-success btn-sm">Win</button>');
btn_row.append(win);
var loss = $('<button class="btn btn-danger btn-sm">Loss</button>');
btn_row.append(loss);
return btn_row;
};
var getCode = function(name){
name = name.toLowerCase().replace(/[^\w]/g,'_');
return name;
};
var rankedOrPlayedSelector = function(code){
var form = $('<div class="form-check-inline"></div>');
form.append($('<label class="form-check-label"><input type="radio" class="form-check-input" name="' + code + '-game-type" value="ranked"/>Ranked</label>'));
form.append($('<label class="form-check-label"><input type="radio" class="form-check-input" name="' + code + '-game-type" value="play" checked/>Play</label>'));
return form
};
var winLossRow = function(code){
var win_row = $('<div class="win-loss-row"></div>');
win_row.append($('<span class="win-loss-span win-loss" id="' + code +
'-win">0</span> <span class="win-loss-span">-</span> <span class="win-loss-span win-loss" id="' + code +
'-loss">0</span>'));
win_row.append($('<p>Percentage: <span id="' + code + '-percentage" class="percentage">0.00</span>%</p>'));
win_row.append($('<p>Total Games: <span id="' + code + '-total" class="total">0</span><span class="net-record" id="' + code + '-net-record">(0)</span></p>'));
return win_row;
};
var buildCounterStructure = function(code){
return $('<div id="' + code + '" class="win-loss-counter counter"></div>' );
};
var counterTitle = function(deck) {
return $('<h5>' + deck + '</h5>')
};
var closeCounterLink = function(code) {
return $('<a class="close-counter" data-target="' + code + '">X</a>')
};
var addSidebarToggle = function(doc) {
doc.on('click', '.sidebar-toggle', function(){
$(this).toggleClass('is-closed')
$('.sidebar').toggleClass('is-closed')
$('.sidebar-item').toggleClass('is-closed')
$('.sidebar-toggle i').toggleClass('fa-minus fa-plus')
})
}
var getNewDeckName = function(){
var name = $('#deck-name').val()
$('#deck-name').val('')
if ( ! name ){
name = ''
}
return name
};
var addToDecksListing = function(name) {
if (!decks.includes(name)){
decks.push(name);
decks = decks.sort();
buildDeckListing(name);
window.localStorage.setItem('decks',JSON.stringify(decks));
}
}
var createDeckListingStructure = function(){
return $('<div class="deck"></div>')
}
var removeListingLink = function() {
return $('<a class="remove-deck">-</a>')
}
var buildDeckCounterLink = function(name) {
return $('<a class="add-deck-counter" id="add-deck-counter-' + getCode(name) + '">+</a>');
}
var deckListingTitle = function(name) {
return $('<h5>' + name + '</h5>')
}
var buildDeckListing = function(name){
var deck = createDeckListingStructure()
deck.append(removeListingLink())
deck.append(buildDeckCounterLink(name))
deck.append(deckListingTitle(name))
$('#decks').append(deck)
}
var addDeckListingActions = function(doc){
doc.on('click','a.remove-deck', function(e){
removeDeckListing($(e.target))
})
doc.on('click','a.add-deck-counter',function(e){
buildDeckCounter($(e.target))
})
}
var buildDeckCounter = function(target){
var name = target.siblings('h5').text();
buildCounter(name);
}
var removeDeckListing = function(target){
var name = target.siblings('h5').text();
target.parent().detach();
decks = decks.filter(v => v != name );
window.localStorage.setItem('decks',JSON.stringify(decks));
}
var addDeckCounter = function(name){
$('#add-deck-counter-' + getCode(name)).click();
}
var addAddDeckAction = function(doc) {
doc.on('click', '#add-deck', function(){
var name = getNewDeckName();
if ( name == '' ) {
return;
}
addToDecksListing(name)
addDeckCounter(name)
})
}
var buildFullDeckListing = function() {
for ( var x=0; x < decks.length; x++) {
buildDeckListing(decks[x])
}
}
var addCounterCloseAction = function(doc){
doc.on('click','.close-counter', function(e){
closeCounter($(e.target))
})
}
var closeCounter = function(target) {
target.parent().detach()
}
var addCounterWinAction = function(doc) {
doc.on('click', '.counter .btn-success', function(e){
recordWin($(e.target))
})
doc.on('click', '.counter .btn-danger', function(e){
recordLoss($(e.target))
})
}
var recordGame = function(target,win) {
var counterId = targetCounterId(target)
var ranked = targetRanked(target)
updateCounter(counterId,win,ranked,true)
actions.push([counterId,win,ranked])
}
var recordWin = function(target) {
recordGame(target,true)
}
var recordLoss = function(target) {
recordGame(target,false)
}
var updateCounter = function(counterId,win,ranked,forward) {
performCounterUpdate(counterId,win,forward);
performCounterUpdate('all',win,forward);
performCounterUpdate('all-' + (ranked ? 'ranked' : 'play'),win,forward);
}
var counterWins = function(counterId){
return parseInt($('#' + counterId + '-win').text())
}
var counterLosses = function(counterId){
return parseInt($('#' + counterId + '-loss').text())
}
var targetCounterId = function(target) {
return target.parent().parent().prop('id')
}
var targetRanked = function(target) {
return $('#' + targetCounterId(target) + ' input[type=radio]:checked').val() === 'ranked'
}
var performCounterUpdate = function(code,win,forward){
updateValue('#' + code + (win ? '-win' : '-loss'), (forward ? 1 : -1))
var wins = parseInt($('#' + code + '-win').text());
var losses = parseInt($('#' + code + '-loss').text());
var total = wins + losses;
var net = wins - losses;
var net_record = $('#' + code + '-net-record');
net_record.removeClass('loss-record win-record');
setValue(net_record,'('+net+')');
if (net < 0){
net_record.addClass('loss-record');
setValue(net_record,'('+net+')');
} else if ( net > 0 ){
net_record.addClass('win-record');
setValue(net_record,'(+'+net+')');
}
setValue('#' + code + '-total',total);
var percentage = total == 0 ? '0.00' : (wins / parseFloat(total) * 100).toFixed(2);
setValue('#' + code + '-percentage',percentage);
}
var updateValue = function(selector,amount){
var value = parseInt($(selector).text()) + amount
setValue(selector,value);
}
var setValue = function(selector,value) {
$(selector).text(value);
};
var addCounterActions = function(doc){
addCounterCloseAction(doc)
addCounterWinAction(doc)
}
var addUndo = function(doc){
doc.on('click', '.fa-undo', function(){
const action = actions.pop()
updateCounter(action[0],action[1],action[2],false)
})
}
var addEnterKeypress = function(doc){
doc.on('keypress',function(e){
if (e.which == 13){
$('#add-deck').click();
}
});
}
$(document).ready( function() {
const doc = $(document)
addSidebarToggle(doc)
addAddDeckAction(doc)
buildFullDeckListing()
addDeckListingActions(doc)
addCounterActions(doc)
addUndo(doc)
addEnterKeypress(doc)
})
</script>
</head>
<body>
<div class="sidebar is-closed">
<a class="sidebar-toggle"><i class="fa fa-plus icon"></i></a>
<a class="sidebar-item"><i class="fa fa-undo icon"></i></a>
<div class="container">
<div class="form-group row">
<div class="col-4 add-deck-div">Name</div>
<div class="col-8">
<input type="text" class="form-control" id="deck-name"/>
</div>
</div>
<div class="form-group row">
<div class="add-deck-div"><a id="add-deck">Add Deck</a></div>
</div>
<div id="decks"></div>
</div>
</div>
<main class="page-content">
<div id="summary-div">
<div class="summary-counter counter">
<h5>All-Day All Games</h5>
<div class="win-loss-row">
<span class="win-loss-span win-loss" id="all-win">0</span>
<span class="win-loss-span">-</span>
<span class="win-loss-span win-loss" id="all-loss">0</span>
</div>
<p>Percentage: <span id="all-percentage" class="percentage">0.00</span>%</p>
<p>Total Games: <span id="all-total" class="total">0</span><span class="net-record" id="all-net-record">(0)</span></p>
</div>
<div class="summary-counter counter">
<h5>All-Day All Ranked</h5>
<div class="win-loss-row">
<span class="win-loss-span win-loss" id="all-ranked-win">0</span>
<span class="win-loss-span">-</span>
<span class="win-loss-span win-loss" id="all-ranked-loss">0</span>
</div>
<p>Percentage: <span id="all-ranked-percentage" class="percentage">0.00</span>%</p>
<p>Total Games: <span id="all-ranked-total" class="total">0</span><span class="net-record" id="all-ranked-net-record">(0)</span></p>
</div>
<div class="summary-counter counter">
<h5>All-Day All Play</h5>
<div class="win-loss-row">
<span class="win-loss-span win-loss" id="all-play-win">0</span>
<span class="win-loss-span">-</span>
<span class="win-loss-span win-loss" id="all-play-loss">0</span>
</div>
<p>Percentage: <span id="all-play-percentage" class="percentage">0.00</span>%</p>
<p>Total Games: <span id="all-play-total" class="total">0</span><span class="net-record" id="all-play-net-record">(0)</span></p>
</div>
</div>
<div id="counters"></div>
</main>
</body>
</html>