-
Notifications
You must be signed in to change notification settings - Fork 0
/
vanilla.html
251 lines (206 loc) · 7.43 KB
/
vanilla.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fabulously Optimized for Minecraft Launcher</title>
<link rel="stylesheet" href="./assets/css/bulma.min.css">
</head>
<body>
<style>
#title {
padding: 0.5em;
font-size: 2em;
}
button{
min-width: 20vw;
}
#versionListDiv {
padding: 1em;
}
#downloadLatest {
font-size: 1.5em;
}
#versionsList > li
{
padding-top: 1em;
}
#olderVersions {
margin-top: 1em;
}
#versionsList > li > button {
font-size: 1em;
}
#footer {
padding: 1em;
}
</style>
<h1 id="title">Fabulously Optimized for Minecraft Launcher</h1>
<div id="versionListDiv">
<button id="downloadLatest">Download latest</button>
<ul id="versionsList">
</ul>
<p><button id="olderVersions" onclick="window.open('https://www.curseforge.com/minecraft/modpacks/fabulously-optimized/files?showAlphaFiles=show')">Older
versions (Additional Files)</button></p>
</div>
<div id="footer">
<p><b>Important:</b> Please allow popups and multiple downloads when asked - sometimes mods must be downloaded
separately and placed to the mods folder manually.</p>
<a href="https://wiki.download.fo/readme/install-instructions#minecraft-launcher-vanilla">How to install?</a>
</div>
<div id="loading-modal" class="modal">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Downloading pack</p>
</header>
<section class="modal-card-body">
<p>
Files required for the modpack are currently being downloaded, please wait.
</p>
</section>
<footer class="modal-card-foot">
<progress id="loading-progress" class="progress is-primary" value="0" max="100">0%</progress>
</footer>
</div>
</div>
<script>
async function loadVersionsFromURL(url) {
try {
const response = await fetch(url);
const data = await response.json();
return data;
} catch (error) {
console.error('Error loading data:', error);
return null;
}
}
function getLatestVersionsForAllGameVersions(versions) {
const latestVersionsMap = {};
versions.forEach(version => {
const versionGameVersions = version.game_versions; // Assuming multiple game versions in the array
versionGameVersions.forEach(gameVersion => {
if (isVersionAllowed(gameVersion) && (!latestVersionsMap[gameVersion] || compareVersions(
version.version_number, latestVersionsMap[gameVersion].version_number) > 0)) {
latestVersionsMap[gameVersion] = version;
}
});
});
const sortedVersions = Object.values(latestVersionsMap).sort((a, b) => compareVersions(b.version_number, a
.version_number));
return sortedVersions;
}
function normalizeVersion(version) {
const parts = version.split('.');
// Ensure version has three parts [major, minor, patch]
while (parts.length < 3) {
parts.push('0'); // Append '0' for missing minor/patch numbers
}
return parts.join('.');
}
function isVersionAllowed(version) {
const allowedFromVersion = '1.19.4';
const normalizedVersion = normalizeVersion(version);
return compareVersions(normalizedVersion, allowedFromVersion) >= 0;
}
function compareVersions(versionA, versionB) {
const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
const parseVersion = (version) => {
const match = version.match(semverRegex);
if (!match) {
console.error("Invalid version format:", version);
return null;
}
return {
major: parseInt(match[1], 10),
minor: parseInt(match[2], 10),
patch: parseInt(match[3], 10),
preRelease: match[4] || '',
buildMetadata: match[5] || ''
};
};
const a = parseVersion(versionA);
const b = parseVersion(versionB);
if (!a || !b) return 0; // Error case handled by parseVersion
if (a.major !== b.major) return a.major > b.major ? 1 : -1;
if (a.minor !== b.minor) return a.minor > b.minor ? 1 : -1;
if (a.patch !== b.patch) return a.patch > b.patch ? 1 : -1;
// If both versions have no pre-release, they are equal at this point
if (!a.preRelease && !b.preRelease) return 0;
// A version without a pre-release field (stable version) should be considered newer than one with a pre-release field
if (!a.preRelease) return 1;
if (!b.preRelease) return -1;
// Compare pre-release identifiers
// Split pre-release into parts and compare each part
const prePartsA = a.preRelease.split('.');
const prePartsB = b.preRelease.split('.');
for (let i = 0; i < Math.max(prePartsA.length, prePartsB.length); i++) {
const partA = prePartsA[i];
const partB = prePartsB[i];
// When one pre-release part is undefined, the other is considered greater
if (partA === undefined) return -1;
if (partB === undefined) return 1;
// Numeric comparison for numeric parts, lexicographic for strings
const numPartA = parseInt(partA, 10);
const numPartB = parseInt(partB, 10);
if (!isNaN(numPartA) && !isNaN(numPartB)) {
if (numPartA !== numPartB) return numPartA > numPartB ? 1 : -1;
} else {
if (partA !== partB) return partA > partB ? 1 : -1;
}
}
// If all parts of pre-release identifiers are equal, the versions are considered equal
return 0;
}
function printVersionsAsHTML(versions) {
const versionsList = document.getElementById('versionsList');
versions.forEach(version => {
const listItem = document.createElement('li');
const button = document.createElement('button');
const versionName = version.name;
button.textContent = versionName;
button.onclick = () => downloadPack(version.files[0].url); // Assuming always one file in files array
listItem.appendChild(button);
versionsList.appendChild(listItem);
});
}
const jsonURL = 'https://api.modrinth.com/v2/project/1KVo5zza/version';
urlParams = new URLSearchParams(window.location.search);
const downloadParam = urlParams.get('download');
const downloadLatestButtonVanilla = document.getElementById('downloadLatest');
loadVersionsFromURL(jsonURL)
.then(data => {
if (data) {
let versionsToDisplay = getLatestVersionsForAllGameVersions(data);
printVersionsAsHTML(versionsToDisplay);
if (downloadParam === 'latest') {
// Download the first (newest) item
downloadPack(versionsToDisplay[0].files[0].url);
} else if (downloadParam) {
// Download specific version based on query parameter
const foundVersion = versionsToDisplay.find(version => version.game_versions[0] === downloadParam);
if (foundVersion) {
downloadPack(foundVersion.files[0].url);
} else {
alert('Requested version not found');
}
}
downloadLatestButtonVanilla.addEventListener('click', () => {
if (versionsToDisplay.length > 0) {
downloadPack(versionsToDisplay[0].files[0].url);
} else {
alert('No versions available to download');
}
});
} else {
console.error('Failed to load data');
}
})
.catch(error => console.error('Error:', error));
</script>
<script src="./assets/js/FileSaver.min.js"></script>
<script src="./assets/js/jszip.min.js"></script>
<script src="./assets/js/jszip-utils.min.js"></script>
<script src="./assets/js/converter.js"></script>
</body>
</html>