-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcpealphaversions.js
More file actions
78 lines (66 loc) · 3.18 KB
/
mcpealphaversions.js
File metadata and controls
78 lines (66 loc) · 3.18 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
$(document).ready(function () {
let versions = [];
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
const regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
const results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
const initialType = getUrlParameter('type') || 'All';
$.getJSON('mcpealphaversions.json', function (data) {
versions = data;
displayVersions(initialType);
});
function getTableClasses() {
const isDarkTheme = document.body.classList.contains('dark-theme') ||
document.documentElement.classList.contains('dark-theme') ||
window.matchMedia('(prefers-color-scheme: dark)').matches;
if (isDarkTheme) {
return 'table table-dark table-striped table-hover';
} else {
return 'table table-striped table-hover';
}
}
function displayVersions(type) {
$('#version-list').empty();
const filteredVersions = versions.filter(version => {
const versionTypes = version.type.split(',').map(type => type.trim());
return type === 'All' || versionTypes.includes(type);
});
let tableHTML = `<table class="${getTableClasses()}"><thead class="table-dark"><tr><th class="text-start">Version</th><th class="text-start">Download</th></tr></thead><tbody>`;
filteredVersions.forEach(version => {
tableHTML += `
<tr>
<td class="text-start">${version.version}</td>
<td class="text-start"><a href="${version.download_link}" target="_blank" class="btn btn-primary">Download</a></td>
</tr>
`;
});
tableHTML += '</tbody></table>';
$('#version-list').append(tableHTML);
$('.tab').removeClass('active');
$(`.tab[data-type="${type}"]`).addClass('active');
}
$('.tab').on('click', function () {
const type = $(this).data('type');
displayVersions(type);
const newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?type=' + type;
window.history.pushState({ path: newUrl }, '', newUrl);
});
$('#search-input').on('keyup', function () {
const query = $(this).val().toLowerCase();
$('#version-list').empty();
const filteredVersions = versions.filter(version => version.version.toLowerCase().includes(query));
let tableHTML = `<table class="${getTableClasses()}"><thead class="table-dark"><tr><th class="text-start">Version</th><th class="text-start">Download</th></tr></thead><tbody>`;
filteredVersions.forEach(version => {
tableHTML += `
<tr>
<td class="text-start">${version.version}</td>
<td class="text-start"><a href="${version.download_link}" target="_blank" class="btn btn-primary">Download</a></td>
</tr>
`;
});
tableHTML += '</tbody></table>';
$('#version-list').append(tableHTML);
});
});