-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
276 lines (248 loc) · 11.5 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GitHub Release Notes Watcher</title>
<script>
// Fallback if CDN fails
if (typeof marked === 'undefined') {
console.warn('Marked library not loaded. Falling back to plain text.');
window.marked = function(text) { return text; };
}
</script>
<link rel="stylesheet" href="styles.css">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.3.3/purify.min.js" defer></script>
<script defer>
window.addEventListener('DOMContentLoaded', (event) => {
if (typeof marked !== 'undefined') {
marked.setOptions({
breaks: true,
gfm: true
});
}
init();
});
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
</head>
<body>
<div class="header">
<a href="https://github.com/joelmnz/github-release-notes-watcher" class="github-icon" target="_blank" title="View on GitHub">
<i class="fab fa-github"></i>
</a>
<h1>GitHub Release Notes Watcher</h1>
</div>
<div id="loading-message">Loading...</div>
<div id="content" style="display: none;">
<p>Last updated: <span id="last-updated"></span></p>
<button onclick="handleUpdate()" class="update-button">
<i class="fas fa-sync-alt"></i> Check for Updates
</button>
<button onclick="showSettings()" class="settings-button">
<i class="fas fa-cog"></i> Settings
</button>
<button onclick="clearCache()" class="clear-cache-button">
<i class="fas fa-trash-alt"></i> Clear Cache
</button>
<h2>Table of Contents</h2>
<ul id="toc" class="toc"></ul>
<div id="releases"></div>
</div>
<div id="settings" style="display: none;">
<h2>Settings</h2>
<p class="settings-description">Enter GitHub repositories, one per line, in the format: <code>owner/repo</code> or a full GitHub URL.</p>
<p class="settings-example">Example: <code>https://github.com/microsoft/vscode</code></p>
<textarea id="repos-list" rows="10" cols="50" placeholder="owner1/repo1 https://github.com/owner2/repo2 https://github.com/owner3/repo3"></textarea>
<br>
<button onclick="saveSettings()" class="settings-button">Save</button>
<button onclick="cancelSettings()" class="settings-button">Cancel</button>
</div>
<script>
let watchedRepos = [];
let cachedData = {};
function init() {
loadWatchedRepos();
loadCache();
if (typeof DOMPurify !== 'undefined') {
renderContent();
} else {
const checkDOMPurify = setInterval(() => {
if (typeof DOMPurify !== 'undefined') {
clearInterval(checkDOMPurify);
renderContent();
}
}, 100);
}
}
function loadWatchedRepos() {
const repos = localStorage.getItem('watchedRepos');
watchedRepos = repos ? repos.split('\n').filter(repo => repo.trim() !== '').map(repo => {
const match = repo.match(/https:\/\/github\.com\/([^\/]+\/[^\/]+)/);
return match ? match[1] : repo;
}) : [];
}
function loadCache() {
cachedData = JSON.parse(localStorage.getItem('releaseNotesCache') || '{}');
}
function saveCache() {
localStorage.setItem('releaseNotesCache', JSON.stringify(cachedData));
}
async function fetchReleaseNotes(repo) {
const url = `https://api.github.com/repos/${repo}/releases/latest`;
try {
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
return {
repo: repo,
version: data.tag_name,
body: data.body,
published_at: data.published_at,
age_in_days: calculateAgeInDays(data.published_at)
};
} else {
const errorData = await response.json();
return {
repo: repo,
error: `HTTP ${response.status}: ${errorData.message || 'Unknown error'}`
};
}
} catch (error) {
return {
repo: repo,
error: `Network error: ${error.message}`
};
}
}
function calculateAgeInDays(dateString) {
const publishedDate = new Date(dateString);
const now = new Date();
return Math.floor((now - publishedDate) / (1000 * 60 * 60 * 24));
}
function calculateTimeDifference(dateString) {
const lastUpdatedDate = new Date(dateString);
const now = new Date();
const diffInMs = now - lastUpdatedDate;
const diffInMinutes = Math.floor(diffInMs / (1000 * 60));
const diffInHours = Math.floor(diffInMs / (1000 * 60 * 60));
const diffInDays = Math.floor(diffInMs / (1000 * 60 * 60 * 24));
if (diffInMinutes < 60) {
return `${diffInMinutes} minutes ago`;
} else if (diffInHours < 24) {
return `${diffInHours} hours ago`;
} else {
return `${diffInDays} days ago`;
}
}
async function handleUpdate() {
const button = document.querySelector('.update-button');
button.classList.add('loading');
button.disabled = true;
button.textContent = 'Updating';
try {
const newReleaseNotes = [];
const failedRepos = [];
for (const repo of watchedRepos) {
const result = await fetchReleaseNotes(repo);
if (result.error) {
failedRepos.push({ repo: result.repo, error: result.error });
} else {
newReleaseNotes.push(result);
}
}
cachedData = {
last_updated: new Date().toISOString(),
release_notes: newReleaseNotes.sort((a, b) => new Date(b.published_at) - new Date(a.published_at)),
failed_repos: failedRepos
};
saveCache();
renderContent();
if (failedRepos.length > 0) {
showErrorDialog(failedRepos);
}
} catch (error) {
console.error('Error during update:', error);
alert('An error occurred while updating. Please try again.');
} finally {
button.classList.remove('loading');
button.disabled = false;
button.textContent = 'Check for Updates';
}
}
function showErrorDialog(failedRepos) {
let message = "Failed to update the following repositories:\n\n";
failedRepos.forEach(({ repo, error }) => {
message += `${repo}: ${error}\n`;
});
message += "\nPossible solutions:\n";
message += "1. Check if the repository names are correct.\n";
message += "2. Ensure you have an active internet connection.\n";
message += "3. The repository might not have any releases yet.\n";
message += "4. There might be a temporary issue with GitHub's API.\n";
message += "5. If the error persists, try again later or remove the problematic repository.";
alert(message);
}
function renderContent() {
document.getElementById('loading-message').style.display = 'none';
document.getElementById('content').style.display = 'block';
const lastUpdated = cachedData.last_updated ? new Date(cachedData.last_updated).toLocaleString() : 'Never';
const timeDifference = cachedData.last_updated ? calculateTimeDifference(cachedData.last_updated) : '';
document.getElementById('last-updated').textContent = `${lastUpdated} (${timeDifference})`;
const toc = document.getElementById('toc');
const releases = document.getElementById('releases');
toc.innerHTML = '';
releases.innerHTML = '';
for (const release of cachedData.release_notes || []) {
const tocItem = document.createElement('li');
tocItem.innerHTML = `<a href="#${release.repo}-${release.version}" title="${release.published_at}">${release.age_in_days} days ago - ${release.repo} - ${release.version}</a>`;
toc.appendChild(tocItem);
const releaseDiv = document.createElement('div');
releaseDiv.className = 'release';
releaseDiv.id = `${release.repo}-${release.version}`;
let bodyHtml;
try {
// Use DOMPurify to sanitize the HTML output from marked
bodyHtml = DOMPurify.sanitize(marked.parse(release.body));
} catch (error) {
console.warn('Error parsing Markdown:', error);
bodyHtml = DOMPurify.sanitize(release.body); // Fallback to sanitized plain text
}
releaseDiv.innerHTML = `
<h2><a href="https://github.com/${release.repo}/releases/tag/${release.version}" target="_blank">${release.repo} - ${release.version}</a></h2>
<p class="date">Published on: <span title="${release.published_at}">${release.age_in_days} days ago</span></p>
<div class="release-body">${bodyHtml}</div>
`;
releases.appendChild(releaseDiv);
}
}
function showSettings() {
document.getElementById('content').style.display = 'none';
document.getElementById('settings').style.display = 'block';
document.getElementById('repos-list').value = watchedRepos.join('\n');
}
function saveSettings() {
const reposList = document.getElementById('repos-list').value;
watchedRepos = reposList.split('\n').filter(repo => repo.trim() !== '').map(repo => {
const match = repo.match(/https:\/\/github\.com\/([^\/]+\/[^\/]+)/);
return match ? match[1] : repo;
});
localStorage.setItem('watchedRepos', watchedRepos.join('\n'));
document.getElementById('settings').style.display = 'none';
document.getElementById('content').style.display = 'block';
handleUpdate();
}
function cancelSettings() {
document.getElementById('settings').style.display = 'none';
document.getElementById('content').style.display = 'block';
}
function clearCache() {
localStorage.removeItem('releaseNotesCache');
cachedData = {};
renderContent();
alert('Cache cleared. Click "Check for Updates" to fetch fresh data.');
}
</script>
</body>
</html>