From 01376362af1b87b71e977e1d9a3c26e6f8923a87 Mon Sep 17 00:00:00 2001 From: lenafx Date: Tue, 2 Dec 2025 21:05:45 +0100 Subject: [PATCH] added update notifier --- src/scripts/updateNotifier.js | 103 ++++++++++++++++++++++++++++++++++ views/anime.html | 15 +++++ views/book.html | 14 +++++ views/books.html | 14 +++++ views/css/updateNotifier.css | 85 ++++++++++++++++++++++++++++ views/gallery-image.html | 14 +++++ views/gallery.html | 14 +++++ views/index.html | 14 +++++ views/read.html | 13 +++++ views/schedule.html | 14 +++++ views/watch.html | 14 +++++ 11 files changed, 314 insertions(+) create mode 100644 src/scripts/updateNotifier.js create mode 100644 views/css/updateNotifier.css diff --git a/src/scripts/updateNotifier.js b/src/scripts/updateNotifier.js new file mode 100644 index 0000000..f292182 --- /dev/null +++ b/src/scripts/updateNotifier.js @@ -0,0 +1,103 @@ +const Gitea_OWNER = 'ItsSkaiya'; +const Gitea_REPO = 'WaifuBoard'; +const CURRENT_VERSION = 'v1.6.3'; +const UPDATE_CHECK_INTERVAL = 5 * 60 * 1000; + +let currentVersionDisplay; +let latestVersionDisplay; +let updateToast; + +document.addEventListener('DOMContentLoaded', () => { + + currentVersionDisplay = document.getElementById('currentVersionDisplay'); + latestVersionDisplay = document.getElementById('latestVersionDisplay'); + updateToast = document.getElementById('updateToast'); + + if (currentVersionDisplay) { + currentVersionDisplay.textContent = CURRENT_VERSION; + } + + checkForUpdates(); + + setInterval(checkForUpdates, UPDATE_CHECK_INTERVAL); +}); + +function showToast(latestVersion) { + + if (latestVersionDisplay && updateToast) { + latestVersionDisplay.textContent = latestVersion; + updateToast.classList.add('update-available'); + updateToast.classList.remove('hidden'); + + } else { + console.error("Error: Cannot display toast because one or more DOM elements were not found."); + } +} + +function hideToast() { + if (updateToast) { + updateToast.classList.add('hidden'); + updateToast.classList.remove('update-available'); + } +} + +function isVersionOutdated(versionA, versionB) { + + const vA = versionA.replace(/^v/, '').split('.').map(Number); + const vB = versionB.replace(/^v/, '').split('.').map(Number); + + for (let i = 0; i < Math.max(vA.length, vB.length); i++) { + const numA = vA[i] || 0; + const numB = vB[i] || 0; + + if (numA < numB) return true; + if (numA > numB) return false; + } + + return false; +} + +async function checkForUpdates() { + console.log(`Checking for updates for ${Gitea_OWNER}/${Gitea_REPO}...`); + + const apiUrl = `https://git.waifuboard.app/api/v1/repos/${Gitea_OWNER}/${Gitea_REPO}/releases/latest`; + + try { + const response = await fetch(apiUrl, { + method: 'GET', + headers: { + 'Accept': 'application/json' + } + }); + + if (!response.ok) { + if (response.status === 404) { + console.info('No releases found for this repository.'); + return; + } + throw new Error(`Gitea API error: ${response.status} ${response.statusText}`); + } + + const data = await response.json(); + + const latestVersion = data.tag_name; + + if (!latestVersion) { + console.warn("Release found but no tag_name present"); + return; + } + + console.log(`Latest Gitea Release: ${latestVersion}`); + + if (isVersionOutdated(CURRENT_VERSION, latestVersion)) { + console.warn('Update available!'); + showToast(latestVersion); + } else { + console.info('Package is up to date.'); + hideToast(); + } + + } catch (error) { + console.error('Failed to fetch Gitea release:', error); + } +} \ No newline at end of file diff --git a/views/anime.html b/views/anime.html index 70d68a4..0230970 100644 --- a/views/anime.html +++ b/views/anime.html @@ -6,6 +6,7 @@ WaifuBoard + @@ -128,6 +129,20 @@ + + + + \ No newline at end of file diff --git a/views/book.html b/views/book.html index c798ec6..de24258 100644 --- a/views/book.html +++ b/views/book.html @@ -7,6 +7,7 @@ WaifuBoard Book + @@ -111,6 +112,19 @@ + + + \ No newline at end of file diff --git a/views/books.html b/views/books.html index 8a41840..6ace8ce 100644 --- a/views/books.html +++ b/views/books.html @@ -6,6 +6,7 @@ WaifuBoard Books + @@ -81,5 +82,18 @@ + + + \ No newline at end of file diff --git a/views/css/updateNotifier.css b/views/css/updateNotifier.css new file mode 100644 index 0000000..958a7d4 --- /dev/null +++ b/views/css/updateNotifier.css @@ -0,0 +1,85 @@ +#updateToast { + position: fixed; + bottom: 20px; + right: 30px; + z-index: 5000; + opacity: 0; + transform: translateY(100px); + pointer-events: none; + transition: opacity 0.4s ease-out, transform 0.4s ease-out; + + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 0.5rem; + + padding: 0.8rem 1.25rem; + border-radius: var(--radius-md); + max-width: 300px; + + background: rgba(18, 18, 21, 0.8); + backdrop-filter: blur(8px); + border: 1px solid rgba(255, 255, 255, 0.1); + box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6); + + color: var(--text-primary); + font-size: 0.9rem; +} + +#updateToast.hidden { + opacity: 0; + transform: translateY(100px); + pointer-events: none; +} + +#updateToast.update-available { + opacity: 1; + transform: translateY(0); + pointer-events: auto; +} + +#updateToast p { + margin: 0; + font-weight: 500; + + width: 100%; + padding-bottom: 0.3rem; +} + +#latestVersionDisplay { + font-weight: 700; + font-size: 0.9rem; + padding: 0.2rem 0.6rem; + border-radius: 6px; + background: var(--accent); + color: var(--bg-base); + display: inline-block; + margin-left: 0.5rem; + box-shadow: 0 0 12px var(--accent-glow); + transition: transform 0.2s; +} + +#downloadButton { + + width: 100%; + + padding: 0.6rem 1rem; + border-radius: 999px; + font-weight: 700; + font-size: 0.9rem; + cursor: pointer; + text-decoration: none; + text-align: center; + + background: var(--accent); + color: white; + border: none; + box-shadow: 0 4px 10px var(--accent-glow); + transition: transform 0.2s, background 0.2s; +} + +#downloadButton:hover { + transform: translateY(-2px); + background: #7c4dff; + box-shadow: 0 6px 15px var(--accent-glow); +} \ No newline at end of file diff --git a/views/gallery-image.html b/views/gallery-image.html index d68fb0d..33b3533 100644 --- a/views/gallery-image.html +++ b/views/gallery-image.html @@ -9,6 +9,7 @@ + @@ -52,6 +53,19 @@ + + + \ No newline at end of file diff --git a/views/gallery.html b/views/gallery.html index fa0f0b0..bcd262f 100644 --- a/views/gallery.html +++ b/views/gallery.html @@ -7,6 +7,7 @@ + @@ -67,6 +68,19 @@ + + + \ No newline at end of file diff --git a/views/index.html b/views/index.html index 5599a89..1b1a80c 100644 --- a/views/index.html +++ b/views/index.html @@ -5,6 +5,7 @@ WaifuBoard + @@ -104,6 +105,19 @@ + + + \ No newline at end of file diff --git a/views/read.html b/views/read.html index 42c7d38..4ebdad9 100644 --- a/views/read.html +++ b/views/read.html @@ -5,6 +5,7 @@ Reader + @@ -177,6 +178,18 @@ + + \ No newline at end of file diff --git a/views/schedule.html b/views/schedule.html index f8a4f70..8fc33f0 100644 --- a/views/schedule.html +++ b/views/schedule.html @@ -9,6 +9,7 @@ + @@ -81,6 +82,19 @@ Syncing Schedule... + + + \ No newline at end of file diff --git a/views/watch.html b/views/watch.html index a25473b..01a1d48 100644 --- a/views/watch.html +++ b/views/watch.html @@ -6,6 +6,7 @@ WaifuBoard Watch + @@ -168,5 +169,18 @@ }); + + + \ No newline at end of file