-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
161 lines (140 loc) · 5.9 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>I Want Crazyhouse</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.css">
<style>
[v-cloak] {
display: none;
}
</style>
</head>
<body>
<h2 id="header1" class="ui header centered">
<br/>
<br/>
<span v-cloak>Redirecting you to the current hourly crazyhouse tournament.</span>
<br/>
<span>Please wait...</span>
</h2>
<div class="table ui header centered">See list of all ZH arenas:<br/><a href="https://iwantzh.github.io/list.html">https://iwantzh.github.io/list.html</a></div>
<div id="table1" class="ui celled padded table">
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.js"></script>
<!--script src="https://unpkg.com/vue"></script-->
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="fetchParseSortAndLoadTournaments.js"></script>
<script>
//TODO: currently this is copy pasted from iwantzh.vue.js and slightly modified
var Tournament = function(json) {
this.json = json;
}
var header1 = new Vue({
el: '#header1',
data: {
message: 'I Want Crazyhouse!'
}
});
var tournaments1 = [];
var table1 = new Vue({
el: '#table1',
data: {
tournamentsTmp: [],
tournaments: tournaments1,
fetches: [
{promise: undefined, loading:false, f: function() { console.log('a'); this.loading = true; return fetchParseSortAndLoadTournamentsOfLichess(
tournaments1, () => this.loading = false );}},
{promise: undefined, loading:false, f: function() { console.log('b'); this.loading = true; return fetchParseSortAndLoadTournamentsForUser(
"https://lichess.org/api/user/blunderman1/tournament/created?status=10&status=20",
tournaments1, () => this.loading = false );}},
{promise: undefined, loading:false, f: function() { console.log('d'); this.loading = true; return fetchParseSortAndLoadTournamentsForUser(
"https://lichess.org/api/user/TheFinnisher/tournament/created?status=10&status=20",
tournaments1, () => this.loading = false );}},
{promise: undefined, loading:false, f: function() { console.log('c'); this.loading = true; return fetchParseSortAndLoadTournamentsForUser(
"https://lichess.org/api/user/CyberShredder/tournament/created?status=10&status=20",
tournaments1, () => this.loading = false );}},
{promise: undefined, loading:false, f: function() { console.log('e'); this.loading = true; return fetchParseSortAndLoadTournamentsForUser(
"https://lichess.org/api/user/OFBC_Nigeria/tournament/created?status=10&status=20",
tournaments1, () => this.loading = false );}},
{promise: undefined, loading:false, f: function() { console.log('f'); this.loading = true; return fetchParseSortAndLoadTournamentsForUser(
"https://lichess.org/api/user/adet2510/tournament/created?status=10&status=20",
tournaments1, () => this.loading = false );}},
{promise: undefined, loading:false, f: function() { console.log('g'); this.loading = true; return fetchParseSortAndLoadTournamentsForUser(
"https://lichess.org/api/user/ajedrezconzeta/tournament/created?status=10&status=20",
tournaments1, () => this.loading = false );}}
]
},
created: async function() {
let this1 = this;
let promises = [];
let maxConcurrentRequests = 1;
// if (Promise.any){ todo: not so important anymore and complicates things in case of redirect, because have to wait for all fetches in the end to do the redirect
// maxConcurrentRequests = 2;
// }
for (x in this.$data.fetches) {
this.$data.fetches[x].promise = this.$data.fetches[x].f();
promises.push(this.$data.fetches[x].promise);//keep adding until we can
if (promises.length == maxConcurrentRequests) {
//if promises contains max amount of fetch promises we wait for any to finish:
console.log('waiting any of these promises to finish: ', promises);
if (maxConcurrentRequests > 1){
await Promise.any(promises);
} else {
await promises[0];
}
//at least on of the fetches has finished - lets re-init that array with currently non-finished promises:
promises = [];
//if any of the remaining pending promises also finishes while we do this it will be cleaned next loop even if we add it now
for (y in this.$data.fetches) {
console.log(">",y,">",this.$data.fetches[y]);
if (this.$data.fetches[y].loading){
promises.push(this.$data.fetches[y].promise);
}
}
}
//at this point it is guaranteed promises contains less than maxConcurrentRequests so we can loop again
}
var tid = this.$data.tournaments[0].json["id"];
console.log(tid);
window.location.replace('https://lichess.org/tournament/'+tid);
console.log(promises);
},
mounted: function() {
},
updated(){
//alert('Updated hook has been called');
},
methods: {
moment : moment,
colorTournament : function(t){
if (t.json["createdBy"]=="lichess"){
return "#bce5dc";
}
if (t.json["createdBy"]=="blunderman1"){
return "#c0e5bc";
}
if (t.json["createdBy"]=="thefinnisher"){
return "#e5bce4";
}
if (t.json["createdBy"]=="cybershredder"){
return "#e5d2bc";
}
if (t.json["createdBy"]=="ofbc_nigeria"){
return "#bccde5";
}
if (t.json["createdBy"]=="adet2510"){
return "#acbdd5";
}
if (t.json["createdBy"]=="ajedrezconzeta"){
return "#d9b3a3";
}
return "yellow";
}
}
});
</script>
</body>
</html>