-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
161 lines (139 loc) · 6.29 KB
/
script.js
File metadata and controls
161 lines (139 loc) · 6.29 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
const GITHUB_API = 'https://api.github.com/repos/macos26/logos/releases';
function extractVersion(filename) {
if (!filename) return '';
var match = filename.match(/(\d+\.\d+\.\d+)/);
return match ? match[1] : '';
}
function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
var k = 1024;
var sizes = ['Bytes', 'KB', 'MB', 'GB'];
var i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function formatDate(date) {
var options = { year: 'numeric', month: 'long', day: 'numeric' };
return date.toLocaleDateString('en-US', options);
}
async function autoDiscoverReleases() {
try {
var response = await fetch(GITHUB_API);
if (!response.ok) return;
var releases = await response.json();
if (!releases.length) return;
// Find the latest release with a DMG asset
var latestDmg = null;
for (var r = 0; r < releases.length; r++) {
var release = releases[r];
for (var a = 0; a < release.assets.length; a++) {
var asset = release.assets[a];
if (asset.name.endsWith('.dmg')) {
if (!latestDmg) {
latestDmg = {
url: asset.browser_download_url,
version: extractVersion(asset.name),
tag: release.tag_name
};
}
break;
}
}
}
// Update download button and links
if (latestDmg) {
var downloadBtn = document.getElementById('download-btn');
if (downloadBtn) {
downloadBtn.href = latestDmg.url;
downloadBtn.textContent = 'Download v' + latestDmg.version;
}
var descLink = document.getElementById('desc-download-link');
if (descLink) {
descLink.href = latestDmg.url;
descLink.textContent = 'v' + latestDmg.version + ' available for download';
}
var whatsNewHeader = document.getElementById('whats-new-header');
if (whatsNewHeader) {
whatsNewHeader.textContent = "WHAT'S NEW IN " + latestDmg.version;
}
var mainTitle = document.getElementById('main-title');
if (mainTitle) {
mainTitle.textContent = 'Logos InkPen ' + latestDmg.version;
}
}
// Render What's New from latest release notes
renderReleaseNotes(releases[0].body);
// Build the release history table
var tbody = document.getElementById('release-history-body');
if (!tbody) return;
var rows = '';
for (var r = 0; r < releases.length; r++) {
var release = releases[r];
for (var a = 0; a < release.assets.length; a++) {
var asset = release.assets[a];
if (!asset.name.endsWith('.dmg')) continue;
var version = extractVersion(asset.name);
var date = formatDate(new Date(release.published_at || release.created_at));
var size = formatFileSize(asset.size);
var url = asset.browser_download_url;
rows += '<tr>'
+ '<td><a href="' + url + '" style="text-decoration: none;"><span class="version-badge">' + version + '</span></a></td>'
+ '<td>' + date + '</td>'
+ '<td>' + size + '</td>'
+ '<td>' + asset.download_count.toLocaleString() + '</td>'
+ '</tr>';
}
}
tbody.innerHTML = rows || '<tr><td colspan="4" style="text-align: center; color: #999;">No releases found.</td></tr>';
} catch (e) {
// Silently fail — the page still works with fallback links
}
}
function renderReleaseNotes(body) {
var container = document.getElementById('whats-new-content');
if (!container || !body) return;
var lines = body.split(/\r?\n/);
var html = '';
var inList = false;
var bullet = '<span style="font-size: 1.7rem; vertical-align: -3.5px; line-height: 0; color: #999;">\u2022</span>';
var listStyle = 'list-style: none; padding-left: 0; line-height: 1.8; font-size: 0.85rem; color: #000; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;';
function cleanText(t) {
t = t.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
t = t.replace(/\*([^*]+)\*/g, '<em>$1</em>');
t = t.replace(/`([^`]+)`/g, '<code>$1</code>');
t = t.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1');
return t;
}
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim();
// Skip images, horizontal rules, empty lines, top title/bold summary
if (!line || line === '---' || line.match(/^<img /)) continue;
if (line.match(/^##\s+\*\*Logos InkPen/)) continue;
if (line.match(/^\*\*A massive update/)) continue;
if (line.match(/^\*\*Full Changelog\*\*/)) continue;
if (line.match(/^https?:\/\//)) continue;
// Section headers (### or ####)
var sectionMatch = line.match(/^#{2,4}\s+(.*)/);
if (sectionMatch) {
if (inList) { html += '</ul>'; inList = false; }
var title = sectionMatch[1].replace(/\*+/g, '').replace(/[#]+/g, '').trim();
title = title.replace(/[\u{1F000}-\u{1FFFF}]/gu, '').trim();
if (title) {
html += '<h4 style="font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: #333; margin: 1.2rem 0 0.5rem 0;">' + title + '</h4>';
}
continue;
}
// List item
var itemMatch = line.match(/^-\s+(.*)/);
if (itemMatch) {
if (!inList) {
html += '<ul style="' + listStyle + '">';
inList = true;
}
html += '<li style="padding-top: 7.5px; padding-bottom: 0;">' + bullet + ' ' + cleanText(itemMatch[1]) + '</li>';
continue;
}
}
if (inList) html += '</ul>';
container.innerHTML = html || '<p style="font-size: 0.85rem; color: #999;">No release notes available.</p>';
}
autoDiscoverReleases();