Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
511 lines (431 loc) · 15.4 KB
/
Copy pathscript.js
File metadata and controls
511 lines (431 loc) · 15.4 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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
/* ============================================================
FERNODE — site behaviour
Vanilla JavaScript (ES6+)
============================================================ */
'use strict';
/* ---------- Release data ---------- */
/* Newest first. `zip` and `exe` are absolute URLs or paths relative to this page.
Set them to null for versions that are not uploaded yet. */
const RELEASES = [
{
version: '1.2.1',
date: '2026-10-30',
latest: true,
zip: 'https://github.com/FerKunG/server-tool/releases/download/v1.2.1/Server-Tool-1.2.1-win-x64.zip',
exe: 'https://github.com/FerKunG/server-tool/releases/download/v1.2.1/Server.Tool.Setup.1.2.1.exe',
format: 'ZIP · portable',
size: '157 MB',
sha256: '72CEF577C9A8B3747F57BA0C78CC67BA0CD840C1E8033045243786242625C580',
note: 'Portable build. Extract the folder, then run the app.',
noteHtml: 'Portable build. Extract the folder, then run the app.'
},
{
version: '1.2.0',
date: '2026-09-18',
latest: false,
zip: null,
exe: null,
format: 'ZIP · archived',
size: null,
sha256: null,
note: 'This build is archived and its installer has not been uploaded yet. Choose v1.2.1 from the version menu.',
noteHtml: 'This build is archived and its installer has not been uploaded yet. Choose v1.2.1 from the version menu.'
},
{
version: '1.1.0',
date: '2026-08-02',
latest: false,
zip: null,
exe: null,
format: 'ZIP · archived',
size: null,
sha256: null,
note: 'This build is archived and its installer has not been uploaded yet. Choose v1.2.1 from the version menu.',
noteHtml: 'This build is archived and its installer has not been uploaded yet. Choose v1.2.1 from the version menu.'
},
{
version: '1.0.0',
date: '2026-07-11',
latest: false,
zip: null,
exe: null,
format: 'ZIP · archived',
size: null,
sha256: null,
note: 'The first public release is archived and no longer distributed. Choose v1.2.1 from the version menu.',
noteHtml: 'The first public release is archived and no longer distributed. Choose v1.2.1 from the version menu.'
}
];
const latestRelease = RELEASES.find((release) => release.latest) || RELEASES[0];
/* ---------- Helpers ---------- */
const $ = (selector, root = document) => root.querySelector(selector);
const $$ = (selector, root = document) => Array.from(root.querySelectorAll(selector));
const getRelease = (version) => RELEASES.find((release) => release.version === version) || latestRelease;
const isAvailable = (release) => Boolean(release && (release.zip || release.exe));
const fileName = (path) => path.split('/').pop();
let toastTimer = null;
function toast(message) {
const element = $('#toast');
if (!element) return;
element.textContent = message;
element.classList.add('is-visible');
window.clearTimeout(toastTimer);
toastTimer = window.setTimeout(() => element.classList.remove('is-visible'), 2600);
}
/* ---------- Version picker ---------- */
let currentVersion = latestRelease.version;
function renderVersionOptions() {
const select = $('#version-select');
if (!select) return;
select.innerHTML = RELEASES.map((release) => {
const state = release.latest
? ' (latest)'
: isAvailable(release) ? '' : ' (archived)';
return `<option value="${release.version}">v${release.version}${state}</option>`;
}).join('');
}
function setDownloadLink(link, path, availableLabel, unavailableLabel) {
if (!link) return;
const text = $('span', link);
if (path) {
link.setAttribute('href', path);
link.setAttribute('download', fileName(path));
link.classList.remove('is-disabled');
link.removeAttribute('aria-disabled');
if (text) text.textContent = availableLabel;
} else {
link.removeAttribute('href');
link.removeAttribute('download');
link.classList.add('is-disabled');
link.setAttribute('aria-disabled', 'true');
if (text) text.textContent = unavailableLabel;
}
}
function applyVersion(version, options = {}) {
const release = getRelease(version);
currentVersion = release.version;
const select = $('#version-select');
if (select && select.value !== release.version) select.value = release.version;
const metaVersion = $('#meta-version');
const metaSize = $('#meta-size');
const metaFormat = $('#meta-format');
const hashValue = $('#hash-value');
const note = $('#download-note');
const copyButton = $('#copy-hash');
if (metaVersion) metaVersion.textContent = 'v' + release.version;
if (metaSize) metaSize.textContent = release.size || 'Not uploaded';
if (metaFormat) metaFormat.textContent = release.format;
if (hashValue) {
hashValue.textContent = release.sha256 || 'No checksum on file';
hashValue.title = release.sha256 || '';
}
if (copyButton) {
copyButton.disabled = !release.sha256;
copyButton.setAttribute('aria-disabled', String(!release.sha256));
}
setDownloadLink($('#download-zip'), release.zip, 'Download tool', 'Not uploaded');
setDownloadLink($('#download-exe'), release.exe, 'Installer (.exe)', 'Installer not uploaded');
if (note) {
// Static strings from RELEASES only — safe to use for the inline detail.
note.innerHTML = release.noteHtml || release.note;
note.classList.toggle('is-warn', !isAvailable(release));
}
try {
localStorage.setItem('fernode-version', release.version);
} catch (error) { /* private mode — ignore */ }
if (options.updateUrl !== false) {
try {
const params = new URLSearchParams(window.location.search);
params.set('v', release.version);
history.replaceState(null, '', window.location.pathname + '?' + params.toString() + window.location.hash);
} catch (error) {
/* file:// in some browsers blocks replaceState — ignore */
}
}
}
function initialVersion() {
const params = new URLSearchParams(window.location.search);
const fromUrl = params.get('v');
if (fromUrl && RELEASES.some((release) => release.version === fromUrl)) return fromUrl;
try {
// Only restore versions that still have a downloadable file.
const saved = localStorage.getItem('fernode-version');
if (saved && RELEASES.some((release) => release.version === saved && isAvailable(release))) return saved;
} catch (error) { /* ignore */ }
return latestRelease.version;
}
function wireVersionPicker() {
const select = $('#version-select');
if (select) {
select.addEventListener('change', (event) => applyVersion(event.target.value));
}
const zip = $('#download-zip');
const installer = $('#download-exe');
[zip, installer].forEach((link) => {
if (!link) return;
link.addEventListener('click', (event) => {
if (link.classList.contains('is-disabled')) {
event.preventDefault();
toast(`v${currentVersion} is not uploaded yet`);
return;
}
if (link.id === 'download-zip') {
toast(`Starting download · FerNode v${currentVersion}`);
link.classList.add('is-downloading');
window.setTimeout(() => link.classList.remove('is-downloading'), 1700);
}
});
});
const copyButton = $('#copy-hash');
if (copyButton) {
copyButton.addEventListener('click', () => {
const release = getRelease(currentVersion);
if (release.sha256) copyText(release.sha256, 'SHA-256 checksum');
else toast('No checksum on file for this version');
});
}
}
/* ---------- Clipboard ---------- */
async function copyText(text, label) {
try {
await navigator.clipboard.writeText(text);
toast(label + ' copied');
} catch (error) {
const area = document.createElement('textarea');
area.value = text;
area.setAttribute('readonly', '');
area.style.position = 'fixed';
area.style.top = '-1000px';
document.body.appendChild(area);
area.select();
try {
document.execCommand('copy');
toast(label + ' copied');
} catch (fallbackError) {
toast('Could not copy — select the checksum manually');
}
area.remove();
}
}
/* ---------- Plugin library ---------- */
let activeCategory = 'all';
function updatePluginCards() {
const grid = $('#plugin-grid');
const empty = $('#plugin-empty');
const count = $('#plugin-count');
const search = $('#plugin-search');
const versionSelect = $('#mc-version');
if (!grid || !empty || !count || !search || !versionSelect) return;
const query = search.value.trim().toLowerCase();
const version = versionSelect.value;
const cards = $$('.plugin-card', grid);
let shown = 0;
cards.forEach((card) => {
const categories = (card.dataset.category || '').toLowerCase().split(/\s+/);
const versions = (card.dataset.versions || '').split(/\s+/);
const haystack = (card.dataset.search || '').toLowerCase();
const matchesCategory = activeCategory === 'all' || categories.includes(activeCategory.toLowerCase());
const matchesVersion = versions.includes(version);
const matchesQuery = !query || haystack.includes(query);
const visible = matchesCategory && matchesVersion && matchesQuery;
card.hidden = !visible;
if (visible) {
shown += 1;
} else {
const video = $('.plugin-video', card);
if (video && !video.paused) video.pause();
}
});
count.textContent = `Showing ${shown} of ${cards.length} plugins`;
empty.hidden = shown !== 0;
}
function setCategory(category) {
activeCategory = category;
$$('.chip[data-category]').forEach((chip) => {
const active = chip.dataset.category === category;
chip.classList.toggle('is-active', active);
chip.setAttribute('aria-pressed', String(active));
});
updatePluginCards();
}
function resetPluginFilters() {
const search = $('#plugin-search');
const version = $('#mc-version');
if (search) search.value = '';
if (version) version.value = '1.21.x';
setCategory('all');
}
function wirePluginLibrary() {
const search = $('#plugin-search');
const version = $('#mc-version');
const reset = $('#reset-filters');
search?.addEventListener('input', updatePluginCards);
version?.addEventListener('change', updatePluginCards);
$$('.chip[data-category]').forEach((chip) => {
chip.addEventListener('click', () => setCategory(chip.dataset.category || 'all'));
});
reset?.addEventListener('click', resetPluginFilters);
$$('.plugin-download').forEach((link) => {
link.addEventListener('click', () => {
const card = link.closest('.plugin-card');
const name = $('h3', card)?.textContent || 'plugin';
const label = $('.download-label', link);
if (label) {
const original = label.textContent;
label.textContent = 'Starting…';
link.classList.add('is-downloading');
window.setTimeout(() => {
label.textContent = original;
link.classList.remove('is-downloading');
}, 1600);
}
toast(`Downloading ${name}`);
});
});
$('.bundle-link')?.addEventListener('click', () => toast('Downloading all 3 FerNode plugins'));
$('.bundle-download')?.addEventListener('click', () => toast('Downloading the FerNode plugin bundle'));
updatePluginCards();
}
/* ---------- Plugin demos ---------- */
function wirePluginVideos() {
const videos = $$('.plugin-video');
if (!videos.length) return;
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const canAutoplay = !reduceMotion && 'IntersectionObserver' in window;
if (!canAutoplay) {
// Leave the preview paused and let the visitor start it themselves.
videos.forEach((video) => { video.controls = true; });
return;
}
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
const video = entry.target;
const card = video.closest('.plugin-card');
const visible = !card || !card.hidden;
if (entry.isIntersecting && visible && !document.hidden) {
const play = video.play();
if (play && typeof play.catch === 'function') play.catch(() => {});
} else {
video.pause();
}
});
}, {
rootMargin: '120px 0px',
threshold: 0.3
});
videos.forEach((video) => {
video.muted = true;
video.loop = true;
observer.observe(video);
});
document.addEventListener('visibilitychange', () => {
if (document.hidden) videos.forEach((video) => video.pause());
});
}
/* ---------- Mobile menu ---------- */
function wireMenu() {
const toggle = $('#menu-toggle');
const nav = $('#mobile-nav');
if (!toggle || !nav) return;
const query = window.matchMedia('(max-width: 700px)');
const setMenu = (open) => {
nav.hidden = !open;
toggle.classList.toggle('is-open', open);
toggle.setAttribute('aria-expanded', String(open));
toggle.setAttribute('aria-label', open ? 'Close menu' : 'Open menu');
};
toggle.addEventListener('click', () => setMenu(nav.hidden));
$$('a', nav).forEach((link) => {
link.addEventListener('click', () => setMenu(false));
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape' && !nav.hidden) {
setMenu(false);
toggle.focus();
}
});
const handleViewportChange = () => {
if (!query.matches) setMenu(false);
};
if (typeof query.addEventListener === 'function') {
query.addEventListener('change', handleViewportChange);
} else if (typeof query.addListener === 'function') {
query.addListener(handleViewportChange);
}
}
/* ---------- FAQ ---------- */
function wireFaq() {
const items = $$('.faq-item');
if (!items.length) return;
const setItem = (item, open) => {
const button = $('button', item);
item.classList.toggle('open', open);
button?.setAttribute('aria-expanded', String(open));
};
items.forEach((item) => {
const button = $('button', item);
if (!button) return;
button.addEventListener('click', () => {
const isOpen = item.classList.contains('open');
items.forEach((other) => setItem(other, false));
if (!isOpen) setItem(item, true);
});
});
}
/* ---------- Scroll reveal ---------- */
function wireReveal() {
const elements = $$('.reveal');
if (!elements.length) return;
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (reduceMotion || !('IntersectionObserver' in window)) {
elements.forEach((element) => element.classList.add('is-visible'));
return;
}
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) return;
entry.target.classList.add('is-visible');
observer.unobserve(entry.target);
});
}, {
threshold: 0.12,
rootMargin: '0px 0px -8% 0px'
});
elements.forEach((element) => observer.observe(element));
}
/* ---------- Misc ---------- */
function wireMisc() {
// Deep links: re-align after fonts and dynamic content have settled.
if (window.location.hash.length > 1) {
let target = null;
try {
target = document.querySelector(window.location.hash);
} catch (error) {
target = null;
}
if (target) {
const root = document.documentElement;
const previous = root.style.scrollBehavior;
root.style.scrollBehavior = 'auto';
target.scrollIntoView({ block: 'start' });
root.style.scrollBehavior = previous;
}
}
}
/* ---------- Boot ---------- */
function init() {
renderVersionOptions();
wireVersionPicker();
applyVersion(initialVersion());
wirePluginLibrary();
wirePluginVideos();
wireMenu();
wireFaq();
wireReveal();
wireMisc();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}