-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.js
68 lines (58 loc) · 1.52 KB
/
table.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
var base_url = "https://raw.githubusercontent.com/Blankscreen-exe/The-Save-Stash/refs/heads/main/";
var data_url = base_url + "data.json";
$(document).ready(function () {
function formatNameString(input) {
return input
.split('_')
.map((word) =>
word === word.toUpperCase()
? word
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
)
.join(' ');
}
fetch(data_url)
.then(async data => {
let save_data = await data.text();
save_data = JSON.parse(save_data);
const platformCounts = save_data.data.reduce((acc, item) => {
let count = (acc[item.platform] || 0) + 1;
acc[item.platform] = count;
return acc;
}, {});
let chart_bars = '';
for (const [key, item] of Object.entries(platformCounts)) {
chart_bars += `<span>${key.toUpperCase()} ( ${item} )</span>`;
}
// populate chart section
$('#chart-section').html(chart_bars);
})
.catch(error => {
console.error("Error fetching data:", error);
alert(error);
});
$("#saveStashTable").DataTable({
ajax: data_url,
columns: [
{
data: "game",
render: function (data, type) {
return `<strong>${formatNameString(data)}</strong>`;
},
},
{
data: "platform",
render: function (data, type) {
return `<span>${data.toUpperCase()}</span>`;
},
},
{
data: "fileName",
render: function (data, type, row) {
return `<a href="${base_url+"saves/"+row.platform+"/"+row.game+"/"+data}" class="save-file-link"><img src="assets/download.svg" width="20px"/></span>`;
},
sortable:false
},
],
});
});