Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (61 loc) · 2.62 KB
/
Copy pathscript.js
File metadata and controls
76 lines (61 loc) · 2.62 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
const REPO = 'wiqis/Sketchable';
const API_URL = `https://api.github.com/repos/${REPO}/releases/latest`;
// Theme Switching
const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
themeToggle.addEventListener('click', () => {
if (body.classList.contains('light-theme')) {
body.classList.replace('light-theme', 'dark-theme');
localStorage.setItem('sketchable-theme', 'dark');
} else {
body.classList.replace('dark-theme', 'light-theme');
localStorage.setItem('sketchable-theme', 'light');
}
});
// Restore Theme
if (localStorage.getItem('sketchable-theme') === 'dark') {
body.classList.replace('light-theme', 'dark-theme');
}
// Release Fetching
async function initReleases() {
const statusMsg = document.getElementById('status-msg');
if (!statusMsg) return;
try {
console.log('Fetching latest release from:', API_URL);
const response = await fetch(API_URL);
if (response.status === 404) {
statusMsg.textContent = "Note: Public desktop releases are currently being prepared.";
return;
}
if (!response.ok) throw new Error(`API Error: ${response.status}`);
const data = await response.json();
console.log('Latest release data:', data);
let foundPlatforms = [];
data.assets.forEach(asset => {
const name = asset.name.toLowerCase();
const url = asset.browser_download_url;
console.log('Checking asset:', name);
if (name.endsWith('.msi')) { bindLink('dl-win', url); foundPlatforms.push('Windows'); }
if (name.endsWith('.dmg')) { bindLink('dl-mac', url); foundPlatforms.push('macOS'); }
if (name.endsWith('.deb')) { bindLink('dl-linux', url); foundPlatforms.push('Linux'); }
if (name.endsWith('.apk')) { bindLink('dl-apk', url); foundPlatforms.push('Android (Direct)'); }
});
if (foundPlatforms.length > 0) {
statusMsg.textContent = `Latest version found for: ${foundPlatforms.join(', ')}.`;
} else {
statusMsg.textContent = "Latest version found, but no matching desktop binaries were detected yet.";
}
} catch (e) {
console.error('Release fetch error:', e);
statusMsg.textContent = "Note: Public desktop releases are currently being prepared.";
}
}
function bindLink(id, url) {
const el = document.getElementById(id);
if (el) {
el.href = url;
el.classList.remove('disabled');
el.classList.add('active');
}
}
document.addEventListener('DOMContentLoaded', initReleases);