-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (57 loc) · 2.51 KB
/
script.js
File metadata and controls
61 lines (57 loc) · 2.51 KB
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
'use strict';
function exit() { window.location = 'https://sqdexe.github.io'; }
function loadPage() {
const URL = 'https://api.github.com/repos/SQDexe/ee09-sheets/contents/sheets';
let content = null;
$.getJSON(URL)
.done(data => {
let list = $('<ul></ul>');
data.sort((a, b) => {
let names = [a, b].map(elem => elem.name.split('-')),
dates = names.map(elem => new Date([2000 + Number(elem[0]), Number(elem[1]), Number(elem[2])].join('-')));
return dates[0].getTime() < dates[1].getTime() ?
-1 :
1;
});
for (let folder of data) {
let idNumber = folder.name.split('-'),
details = $('<details></details>')
.append($('<summary></summary>')
.text(`${ idNumber[1].padStart(2, '0') }.20${ idNumber[0] } - ${ idNumber[2] }`));
let innerContent = null;
$.getJSON(`${URL}/${folder.name}`)
.done(innerData => {
let innerList = $('<ul></ul>');
for (let file of innerData) {
innerList.append($('<li></li>')
.append($('<a></a>')
.attr({
href: `https://sqdexe.github.io/ee09-sheets/${file.path}`,
download: file.name,
target: '_blank'
})
.text(file.name)));
}
details.append(innerList);
})
.fail((jqXHR) => innerContent = $('<div></div>')
.addClass('error')
.text(`< Błąd - ${jqXHR.status} >`))
.always(() => list.append($('<li></li>')
.append(details
.append(innerContent))));
}
content = list;
})
.fail((jqXHR)=> content = $('<div></div>')
.addClass('error')
.text(`< Błąd - ${jqXHR.status} >`))
.always(() => $('#list')
.empty()
.append(content));
}
function load() {
$('#exit button').click(exit);
load();
}
$(document).ready(load);