-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (40 loc) · 1.56 KB
/
index.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
function select () { this.select(); }
var packsUrl = 'https://rawgit.com/bsep/packs/gh-pages/packs.json';
var versionUrl = 'https://api.github.com/repos/bsep/server/releases/latest';
var packList = $('#pack-list');
function insertPack (item) {
var url = location.protocol + '//' + location.hostname + '/packs/' + item.url;
$(`<li class="well"><h3>${item.name}</h3><p>${item.desc}</p><input class="form-control" type="text" readonly></li>`)
.appendTo(packList)
.children('input')
.css('width', '' + (url.length * 9) + 'px')
.val(url)
.click(select);
}
function load (key, url, cb) {
var val = lscache.get(key);
if (val) {
cb(val);
} else {
$.getJSON(url, function (data) {
lscache.set(key, data, 15);
load(key, url, cb);
});
}
}
load('packs', packsUrl, (data) => data.forEach(insertPack));
load('version', versionUrl, function (data) {
var verList = $('#dl-list');
$('#version-label').text(data.tag_name);
data.assets.forEach(function (asset) {
var releaseName = 'Download for ';
if (asset.name.includes('linux')) releaseName += 'Linux';
else if (asset.name.includes('mac')) releaseName += 'Mac';
else if (asset.name.includes('windows')) releaseName += 'Windows';
if (asset.name.includes('amd64')) releaseName += ' (64-bit)';
if (asset.name.includes('checksums')) releaseName = 'Checksums';
verList.append(`<li><a class="btn btn-lg btn-default btn-block" href="${asset.browser_download_url}">
<span class="glyphicon glyphicon-download-alt"></span>
${releaseName}</a></li>`)
})
});