-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
353 lines (309 loc) · 14.4 KB
/
script.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
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
document.addEventListener('DOMContentLoaded', function() {
let table_index = document.getElementById('table-index');
// onClick's logic below:
table_index.addEventListener('click', function() {
sortTable(-1,'number');
});
});
document.addEventListener('DOMContentLoaded', function() {
let table_artist = document.getElementById('table-artist');
// onClick's logic below:
table_artist.addEventListener('click', function() {
sortTable(0,'string');
});
});
document.addEventListener('DOMContentLoaded', function() {
let table_date = document.getElementById('table-date');
// onClick's logic below:
table_date.addEventListener('click', function() {
sortTable(1,'date');
});
});
document.addEventListener('DOMContentLoaded', function() {
let table_location = document.getElementById('table-location');
// onClick's logic below:
table_location.addEventListener('click', function() {
sortTable(2,'string');
});
});
url_proxy = "https://qvrw15vfsi.execute-api.eu-central-1.amazonaws.com/getWebsiteDom?url="
let count = 1;
function getYellow(url){
$.get(url_proxy + url, function(resp){
let yellowDoc = new DOMParser().parseFromString(resp, "text/html");
let artists = yellowDoc.getElementsByClassName("b-artist");
for (let i=0; i<artists.length; i++){
let artistName = artists[i].getElementsByClassName("b-artist__info-title")[0].innerHTML;
let showDate = artists[i].getElementsByClassName("b-artist__info")[1].getElementsByTagName("span")[0].innerHTML;
let tickets = artists[i].getElementsByClassName('abs-link')[0].href;
let showLocation = "Yellow Submarine";
let tr = document.createElement("tr");
let thScope = document.createElement("th");
thScope.setAttribute("scope","row");
thScope.innerHTML = String(count);
let tdArtist = document.createElement("td")
tdArtist.innerHTML = artistName;
let tdShowDate = document.createElement("td");
tdShowDate.innerHTML = String(showDate);
let tdTickets = document.createElement("td");
let ticketsButton = document.createElement("a")
ticketsButton.className = "btn btn-primary btn-sm"
ticketsButton.href = tickets
ticketsButton.role = "button"
ticketsButton.innerHTML = "Get Tickets";
ticketsButton.target = "_blank"
tdTickets.appendChild(ticketsButton)
let tdShowLocation = document.createElement("td");
tdShowLocation.innerHTML = showLocation;
tr.appendChild(thScope);
tr.appendChild(tdArtist);
tr.appendChild(tdShowDate);
tr.appendChild(tdShowLocation);
tr.appendChild(tdTickets);
document.getElementById('artists-table-body').appendChild(tr);
count += 1;
}
})
}
function getZappaPage(url){
$.get(url_proxy + url, function(resp){
let zappaDoc = new DOMParser().parseFromString(resp, "text/html");
let artists = zappaDoc.getElementsByClassName("event-listing-item");
for (let i=0; i<artists.length; i++){
let artistName = artists[i].getElementsByClassName("event-listing-city")[0].innerHTML;
let showDate = new Date(artists[i].getElementsByClassName("event-listing-date")[0].getAttribute('datetime'));
let tickets = "https://www.zappa-club.co.il/" + artists[i].getElementsByTagName('a')[0].getAttribute('href');
let showLocation = "Zappa JLM"
let tr = document.createElement("tr");
let thScope = document.createElement("th");
thScope.setAttribute("scope","row");
thScope.innerHTML = String(count);
let tdArtist = document.createElement("td")
tdArtist.innerHTML = artistName;
let tdShowDate = document.createElement("td");
tdShowDate.innerHTML = String(showDate.getUTCDate()) + "." + String(showDate.getUTCMonth() + 1);
let tdShowLocation = document.createElement("td");
tdShowLocation.innerHTML = showLocation;
let tdTickets = document.createElement("td");
let ticketsButton = document.createElement("a")
ticketsButton.className = "btn btn-primary btn-sm"
ticketsButton.href = tickets
ticketsButton.role = "button"
ticketsButton.innerHTML = "Get Tickets";
ticketsButton.target = "_blank"
let availability = artists[i].getElementsByClassName('event-not-available')
availability = availability.length === 0;
if (availability){
tdTickets.appendChild(ticketsButton)
}
else {
ticketsButton.innerHTML = "Tickets Unavailable";
ticketsButton.className = "btn btn-primary btn-sm disabled";
ticketsButton.setAttribute("aria-disabled","true");
tdTickets.appendChild(ticketsButton);
}
tr.appendChild(thScope);
tr.appendChild(tdArtist);
tr.appendChild(tdShowDate);
tr.appendChild(tdShowLocation);
tr.appendChild(tdTickets);
document.getElementById('artists-table-body').appendChild(tr);
count += 1;
}
})
}
function getJLMTheater(url){
$.get(url_proxy + url, function(resp){
let doc = new DOMParser().parseFromString(resp, "text/html");
let events = doc.getElementsByTagName('table')[0].getElementsByTagName('tbody')[0].getElementsByTagName('tr');
let tableBody = new DOMParser().parseFromString(doc.getElementsByTagName('table')[0].getElementsByTagName('tbody')[0].getElementsByTagName('template')[0].innerHTML, "text/html");
console.log(tableBody);
for (let i=0; i<events.length; i++){
let event=events[i];
let eventNameAndLink = event.getElementsByClassName('name')[0];
let eventName = eventNameAndLink.getElementsByTagName('a')[0].innerHTML;
let eventLink = eventNameAndLink.getElementsByTagName('a')[0].href;
let eventDate = event.getElementsByClassName('date')[0].getElementsByTagName('time')[0].getAttribute('datetime');
let eventLocation = "Jerusalem Theater";
let tr = document.createElement("tr");
let thScope = document.createElement("th");
thScope.setAttribute("scope","row");
thScope.innerHTML = String(count);
let tdArtist = document.createElement("td")
tdArtist.innerHTML = eventName;
let tdShowDate = document.createElement("td");
tdShowDate.innerHTML = String(eventDate);
let tdTickets = document.createElement("td");
let ticketsButton = document.createElement("a")
ticketsButton.className = "btn btn-primary btn-sm"
ticketsButton.href = eventLink
ticketsButton.role = "button"
ticketsButton.innerHTML = "Get Tickets";
ticketsButton.target = "_blank"
tdTickets.appendChild(ticketsButton)
let tdShowLocation = document.createElement("td");
tdShowLocation.innerHTML = eventLocation;
tr.appendChild(thScope);
tr.appendChild(tdArtist);
tr.appendChild(tdShowDate);
tr.appendChild(tdShowLocation);
tr.appendChild(tdTickets);
document.getElementById('artists-table-body').appendChild(tr);
count += 1;
}
})
}
async function getAllConcerts(){
await getYellow("https://yellowsubmarine.org.il/event")
await getZappaPage("https://www.zappa-club.co.il/city/%D7%99%D7%A8%D7%95%D7%A9%D7%9C%D7%99%D7%9D-306/venue/%D7%96%D7%90%D7%A4%D7%94-%D7%99%D7%A8%D7%95%D7%A9%D7%9C%D7%99%D7%9D-25736/")
await getZappaPage("https://www.zappa-club.co.il/city/%D7%99%D7%A8%D7%95%D7%A9%D7%9C%D7%99%D7%9D-306/venue/%D7%96%D7%90%D7%A4%D7%94-%D7%99%D7%A8%D7%95%D7%A9%D7%9C%D7%99%D7%9D-25736/?pnum=2")
await getZappaPage("https://www.zappa-club.co.il/city/%D7%99%D7%A8%D7%95%D7%A9%D7%9C%D7%99%D7%9D-306/venue/%D7%96%D7%90%D7%A4%D7%94-%D7%99%D7%A8%D7%95%D7%A9%D7%9C%D7%99%D7%9D-25736/?pnum=3")
await getZappaPage("https://www.zappa-club.co.il/city/%D7%99%D7%A8%D7%95%D7%A9%D7%9C%D7%99%D7%9D-306/venue/%D7%96%D7%90%D7%A4%D7%94-%D7%99%D7%A8%D7%95%D7%A9%D7%9C%D7%99%D7%9D-25736/?pnum=4")
//await getJLMTheater("https://www.jerusalem-theatre.co.il/%D7%9C%D7%95%D7%97_%D7%90%D7%99%D7%A8%D7%95%D7%A2%D7%99%D7%9D")
}
function dateCompare(x,y){
let xSplit = x.split(".")
let ySplit = y.split(".")
if (Number(xSplit[1]) > Number(ySplit[1])){
return true;
}
if (Number(xSplit[1])===Number(ySplit[1])){
if (Number(xSplit[0]) > Number(ySplit[0])){
return true;
}
}
return false;
}
function sortTable(n,dataType) {
var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
table = document.getElementById("artists-table");
switching = true;
// Set the sorting direction to ascending:
dir = "asc";
/* Make a loop that will continue until
no switching has been done: */
while (switching) {
// Start by saying: no switching is done:
switching = false;
rows = table.rows;
/* Loop through all table rows (except the
first, which contains table headers): */
if (dataType === "string"){
for (i = 1; i < (rows.length - 1); i++) {
// Start by saying there should be no switching:
shouldSwitch = false;
/* Get the two elements you want to compare,
one from current row and one from the next: */
x = rows[i].getElementsByTagName("td")[n];
y = rows[i + 1].getElementsByTagName("td")[n];
if (n === -1){
x = rows[i].getElementsByTagName("th")[0];
y = rows[i + 1].getElementsByTagName("th")[0];
}
/* Check if the two rows should switch place,
based on the direction, asc or desc: */
if (dir === "asc") {
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
} else if (dir === "desc") {
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
}
}
}
if (dataType === "number"){
for (i = 1; i < (rows.length - 1); i++) {
// Start by saying there should be no switching:
shouldSwitch = false;
/* Get the two elements you want to compare,
one from current row and one from the next: */
x = rows[i].getElementsByTagName("td")[n];
y = rows[i + 1].getElementsByTagName("td")[n];
if (n === -1){
x = rows[i].getElementsByTagName("th")[0];
y = rows[i + 1].getElementsByTagName("th")[0];
}
/* Check if the two rows should switch place,
based on the direction, asc or desc: */
if (dir === "asc") {
if (Number(x.innerHTML) > Number(y.innerHTML)) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
} else if (dir === "desc") {
if (Number(x.innerHTML) < Number(y.innerHTML)) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
}
}
}
if (dataType === "date"){
for (i = 1; i < (rows.length - 1); i++) {
// Start by saying there should be no switching:
shouldSwitch = false;
/* Get the two elements you want to compare,
one from current row and one from the next: */
x = rows[i].getElementsByTagName("td")[n];
y = rows[i + 1].getElementsByTagName("td")[n];
if (n === -1){
x = rows[i].getElementsByTagName("th")[0];
y = rows[i + 1].getElementsByTagName("th")[0];
}
/* Check if the two rows should switch place,
based on the direction, asc or desc: */
if (dir === "asc") {
if (dateCompare(x.innerHTML, y.innerHTML)) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
} else if (dir === "desc") {
if (dateCompare(y.innerHTML, x.innerHTML)) {
// If so, mark as a switch and break the loop:
shouldSwitch = true;
break;
}
}
}
}
if (shouldSwitch) {
/* If a switch has been marked, make the switch
and mark that a switch has been done: */
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
// Each time a switch is done, increase this count by 1:
switchcount ++;
} else {
/* If no switching has been done AND the direction is "asc",
set the direction to "desc" and run the while loop again. */
if (switchcount === 0 && dir === "asc") {
dir = "desc";
switching = true;
}
}
}
}
async function renderWebPage(){
await getAllConcerts().then(function() {
document.getElementById('spinnerIcon').hidden=true;
document.getElementById('main-website').hidden=false;
});
}
function filterLocation(loc){
let table = document.getElementById('artists-table');
for (let i = 1; i<count; i++){
let row = table.rows[i];
if (row.getElementsByTagName('td')[2].innerHTML === loc){
row.hidden = !row.hidden;
}
}
}