fix(build): url-encode bookmarklet payload to prevent URI malformed error (v1.1.2)
This commit is contained in:
@@ -161,18 +161,38 @@ print(html)
|
||||
")
|
||||
fi
|
||||
|
||||
# Embed the bookmarklet URL inline
|
||||
echo "document.getElementById('bookmarklet-link').href = " >> "$DIST_DIR/install.html"
|
||||
echo "$JS_CONTENT" | python3 -c "
|
||||
import sys, json
|
||||
js = sys.stdin.read()
|
||||
css = open('$CSS_FILE').read().replace('\\n', ' ').replace(' ', ' ')
|
||||
import sys, json, urllib.parse
|
||||
|
||||
# 1. Read JS and Replace VERSION
|
||||
js_template = sys.stdin.read()
|
||||
# We do replacement here in Python to be safe
|
||||
js = js_template.replace('{{VERSION}}', '$VERSION')
|
||||
|
||||
# 2. Prepare CSS
|
||||
css = open('$CSS_FILE').read().replace('\n', ' ').replace(' ', ' ')
|
||||
escaped_css = css.replace('\\\\', '\\\\\\\\').replace(\"'\", \"\\\\'\").replace('\"', '\\\\\"')
|
||||
|
||||
# Inject Update URL with htmlpreview
|
||||
# 3. Inject CSS and Update URL
|
||||
update_url = 'https://htmlpreview.github.io/?https://github.com/TauNeutrino/kantine-overview/blob/main/dist/install.html'
|
||||
js = js.replace('https://github.com/TauNeutrino/kantine-overview/raw/main/dist/install.html', update_url)
|
||||
js = js.replace('{{CSS_ESCAPED}}', escaped_css)
|
||||
|
||||
print(json.dumps('javascript:(function(){' + js.replace('{{CSS_ESCAPED}}', escaped_css) + '})();'))
|
||||
# 4. Create Bookmarklet Code
|
||||
# Wrap in IIFE
|
||||
bookmarklet_code = 'javascript:(function(){' + js + '})();'
|
||||
|
||||
# 5. URL Encode the body (keeping javascript: prefix)
|
||||
# We accept that simple encoding is better.
|
||||
# But browsers expect encoded URI for href.
|
||||
# However, for bookmarklet usage, user drags the link.
|
||||
# If we encode everything, it's safer.
|
||||
encoded_code = urllib.parse.quote(bookmarklet_code, safe=':/()!;=+,')
|
||||
|
||||
# Output as JSON string for the HTML script to assign to href
|
||||
print(json.dumps(encoded_code) + ';')
|
||||
" >> "$DIST_DIR/install.html"
|
||||
|
||||
# Inject Changelog into Installer HTML (Safe Python replace)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
## v1.1.2 (2026-02-16)
|
||||
- **Fix**: Encoding-Problem beim Bookmarklet behoben (URL Malformed Error). 🔗
|
||||
|
||||
## v1.1.1 (2026-02-16)
|
||||
- **Fix**: Kritischer Fehler behoben, der das Laden des Wrappers verhinderte. 🐛
|
||||
|
||||
|
||||
2
dist/bookmarklet-payload.js
vendored
2
dist/bookmarklet-payload.js
vendored
File diff suppressed because one or more lines are too long
2
dist/bookmarklet.txt
vendored
2
dist/bookmarklet.txt
vendored
File diff suppressed because one or more lines are too long
16
dist/install.html
vendored
16
dist/install.html
vendored
File diff suppressed because one or more lines are too long
222
dist/kantine-standalone.html
vendored
222
dist/kantine-standalone.html
vendored
@@ -1417,7 +1417,7 @@ body {
|
||||
<div class="brand">
|
||||
<span class="material-icons-round logo-icon">restaurant_menu</span>
|
||||
<div class="header-left">
|
||||
<h1>Kantinen Übersicht <small style="font-size: 0.6em; opacity: 0.7; font-weight: 400;">v1.1.1</small></h1>
|
||||
<h1>Kantinen Übersicht <small style="font-size: 0.6em; opacity: 0.7; font-weight: 400;">v1.1.2</small></h1>
|
||||
<div id="last-updated-subtitle" class="subtitle"></div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2015,13 +2015,13 @@ body {
|
||||
// === Highlight Management ===
|
||||
let highlightTags = JSON.parse(localStorage.getItem('kantine_highlightTags') || '[]');
|
||||
|
||||
function saveHighlightTags() {
|
||||
function saveHighlightTags() {
|
||||
localStorage.setItem('kantine_highlightTags', JSON.stringify(highlightTags));
|
||||
renderVisibleWeeks(); // Refresh UI to apply changes
|
||||
updateNextWeekBadge();
|
||||
}
|
||||
}
|
||||
|
||||
function addHighlightTag(tag) {
|
||||
function addHighlightTag(tag) {
|
||||
tag = tag.trim().toLowerCase();
|
||||
if (tag && !highlightTags.includes(tag)) {
|
||||
highlightTags.push(tag);
|
||||
@@ -2029,14 +2029,14 @@ function addHighlightTag(tag) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function removeHighlightTag(tag) {
|
||||
function removeHighlightTag(tag) {
|
||||
highlightTags = highlightTags.filter(t => t !== tag);
|
||||
saveHighlightTags();
|
||||
}
|
||||
}
|
||||
|
||||
function renderTagsList() {
|
||||
function renderTagsList() {
|
||||
const list = document.getElementById('tags-list');
|
||||
list.innerHTML = '';
|
||||
highlightTags.forEach(tag => {
|
||||
@@ -2053,28 +2053,28 @@ function renderTagsList() {
|
||||
renderTagsList();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function checkHighlight(text) {
|
||||
function checkHighlight(text) {
|
||||
if (!text) return false;
|
||||
text = text.toLowerCase();
|
||||
return highlightTags.some(tag => text.includes(tag));
|
||||
}
|
||||
}
|
||||
|
||||
// === Local Menu Cache (localStorage) ===
|
||||
const CACHE_KEY = 'kantine_menuCache';
|
||||
const CACHE_TS_KEY = 'kantine_menuCacheTs';
|
||||
// === Local Menu Cache (localStorage) ===
|
||||
const CACHE_KEY = 'kantine_menuCache';
|
||||
const CACHE_TS_KEY = 'kantine_menuCacheTs';
|
||||
|
||||
function saveMenuCache() {
|
||||
function saveMenuCache() {
|
||||
try {
|
||||
localStorage.setItem(CACHE_KEY, JSON.stringify(allWeeks));
|
||||
localStorage.setItem(CACHE_TS_KEY, new Date().toISOString());
|
||||
} catch (e) {
|
||||
console.warn('Failed to cache menu data:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadMenuCache() {
|
||||
function loadMenuCache() {
|
||||
try {
|
||||
const cached = localStorage.getItem(CACHE_KEY);
|
||||
const cachedTs = localStorage.getItem(CACHE_TS_KEY);
|
||||
@@ -2092,10 +2092,10 @@ function loadMenuCache() {
|
||||
console.warn('Failed to load cached menu:', e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// === Menu Data Fetching (Direct from Bessa API) ===
|
||||
async function loadMenuDataFromAPI() {
|
||||
// === Menu Data Fetching (Direct from Bessa API) ===
|
||||
async function loadMenuDataFromAPI() {
|
||||
const loading = document.getElementById('loading');
|
||||
const progressModal = document.getElementById('progress-modal');
|
||||
const progressFill = document.getElementById('progress-fill');
|
||||
@@ -2288,10 +2288,10 @@ async function loadMenuDataFromAPI() {
|
||||
} finally {
|
||||
loading.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Last Updated Display ===
|
||||
function updateLastUpdatedTime(isoTimestamp) {
|
||||
// === Last Updated Display ===
|
||||
function updateLastUpdatedTime(isoTimestamp) {
|
||||
const subtitle = document.getElementById('last-updated-subtitle');
|
||||
if (!isoTimestamp) return;
|
||||
try {
|
||||
@@ -2302,10 +2302,10 @@ function updateLastUpdatedTime(isoTimestamp) {
|
||||
} catch (e) {
|
||||
subtitle.textContent = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Toast Notification ===
|
||||
function showToast(message, type = 'info') {
|
||||
// === Toast Notification ===
|
||||
function showToast(message, type = 'info') {
|
||||
let container = document.getElementById('toast-container');
|
||||
if (!container) {
|
||||
container = document.createElement('div');
|
||||
@@ -2322,10 +2322,10 @@ function showToast(message, type = 'info') {
|
||||
toast.classList.remove('show');
|
||||
setTimeout(() => toast.remove(), 300);
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
// === Next Week Badge ===
|
||||
function updateNextWeekBadge() {
|
||||
// === Next Week Badge ===
|
||||
function updateNextWeekBadge() {
|
||||
const btnNextWeek = document.getElementById('btn-next-week');
|
||||
let nextWeek = currentWeekNumber + 1;
|
||||
let nextYear = currentYear;
|
||||
@@ -2407,10 +2407,10 @@ function updateNextWeekBadge() {
|
||||
} else if (badge) {
|
||||
badge.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Weekly Cost ===
|
||||
function updateWeeklyCost(days) {
|
||||
// === Weekly Cost ===
|
||||
function updateWeeklyCost(days) {
|
||||
let totalCost = 0;
|
||||
if (days && days.length > 0) {
|
||||
days.forEach(day => {
|
||||
@@ -2432,10 +2432,10 @@ function updateWeeklyCost(days) {
|
||||
} else {
|
||||
costDisplay.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Render Weeks ===
|
||||
function renderVisibleWeeks() {
|
||||
// === Render Weeks ===
|
||||
function renderVisibleWeeks() {
|
||||
const menuContainer = document.getElementById('menu-container');
|
||||
if (!menuContainer) return;
|
||||
menuContainer.innerHTML = '';
|
||||
@@ -2493,10 +2493,10 @@ function renderVisibleWeeks() {
|
||||
|
||||
menuContainer.appendChild(grid);
|
||||
setTimeout(() => syncMenuItemHeights(grid), 0);
|
||||
}
|
||||
}
|
||||
|
||||
// === Sync Item Heights ===
|
||||
function syncMenuItemHeights(grid) {
|
||||
// === Sync Item Heights ===
|
||||
function syncMenuItemHeights(grid) {
|
||||
const cards = grid.querySelectorAll('.menu-card');
|
||||
if (cards.length === 0) return;
|
||||
let maxItems = 0;
|
||||
@@ -2516,10 +2516,10 @@ function syncMenuItemHeights(grid) {
|
||||
});
|
||||
itemsAtPos.forEach(item => { item.style.height = `${maxHeight}px`; });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Create Day Card ===
|
||||
function createDayCard(day) {
|
||||
// === Create Day Card ===
|
||||
function createDayCard(day) {
|
||||
if (!day.items || day.items.length === 0) return null;
|
||||
|
||||
const card = document.createElement('div');
|
||||
@@ -2746,22 +2746,70 @@ function createDayCard(day) {
|
||||
|
||||
card.appendChild(body);
|
||||
return card;
|
||||
}
|
||||
}
|
||||
|
||||
// === Version Check ===
|
||||
async function checkForUpdates() {
|
||||
icon.className = 'update-icon';
|
||||
icon.href = url;
|
||||
icon.target = '_blank';
|
||||
icon.innerHTML = '🆕'; // User requested icon
|
||||
icon.title = `Neue Version verfügbar (${newVersion}). Klick für download`;
|
||||
// === Version Check ===
|
||||
async function checkForUpdates() {
|
||||
const CurrentVersion = 'v1.1.2';
|
||||
const VersionUrl = 'https://raw.githubusercontent.com/TauNeutrino/kantine-overview/main/version.txt';
|
||||
const InstallerUrl = 'https://htmlpreview.github.io/?https://github.com/TauNeutrino/kantine-overview/blob/main/dist/install.html';
|
||||
|
||||
headerTitle.appendChild(icon);
|
||||
showToast(`Update verfügbar: ${newVersion}`, 'info');
|
||||
}
|
||||
console.log(`[Kantine] Checking for updates... (Current: ${CurrentVersion})`);
|
||||
|
||||
// === Order Countdown ===
|
||||
function updateCountdown() {
|
||||
try {
|
||||
const response = await fetch(VersionUrl, { cache: 'no-cache' });
|
||||
if (!response.ok) return;
|
||||
|
||||
const remoteVersion = (await response.text()).trim();
|
||||
|
||||
if (remoteVersion && remoteVersion !== CurrentVersion) {
|
||||
console.log(`[Kantine] New version available: ${remoteVersion}`);
|
||||
|
||||
// Fetch Changelog content
|
||||
let changeSummary = '';
|
||||
try {
|
||||
const clResp = await fetch('https://raw.githubusercontent.com/TauNeutrino/kantine-overview/main/changelog.md');
|
||||
if (clResp.ok) {
|
||||
const clText = await clResp.text();
|
||||
const match = clText.match(/## (v[^\n]+)\n((?:-[^\n]+\n)+)/);
|
||||
if (match && match[1].includes(remoteVersion)) {
|
||||
changeSummary = match[2].replace(/- /g, '• ').trim();
|
||||
}
|
||||
}
|
||||
} catch (e) { console.warn('No changelog', e); }
|
||||
|
||||
// Create Banner
|
||||
const updateBanner = document.createElement('div');
|
||||
updateBanner.className = 'update-banner';
|
||||
updateBanner.innerHTML = `
|
||||
<div class="update-content">
|
||||
<strong>Update verfügbar: ${remoteVersion}</strong>
|
||||
${changeSummary ? `<pre class="change-summary">${changeSummary}</pre>` : ''}
|
||||
<a href="${InstallerUrl}" target="_blank" class="update-link">
|
||||
<span class="material-icons-round">system_update_alt</span>
|
||||
Jetzt aktualisieren
|
||||
</a>
|
||||
</div>
|
||||
<button class="icon-btn-small close-update">×</button>
|
||||
`;
|
||||
|
||||
document.body.appendChild(updateBanner);
|
||||
updateBanner.querySelector('.close-update').addEventListener('click', () => updateBanner.remove());
|
||||
|
||||
// Highlight Header Icon
|
||||
const lastUpdatedIcon = document.querySelector('.material-icons-round.logo-icon');
|
||||
if (lastUpdatedIcon) {
|
||||
lastUpdatedIcon.style.color = 'var(--accent-color)';
|
||||
lastUpdatedIcon.parentElement.title = `Update verfügbar: ${remoteVersion}`;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('[Kantine] Version check failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// === Order Countdown ===
|
||||
function updateCountdown() {
|
||||
const now = new Date();
|
||||
const currentDay = now.getDay();
|
||||
// Skip weekends (0=Sun, 6=Sat)
|
||||
@@ -2840,69 +2888,69 @@ function updateCountdown() {
|
||||
} else {
|
||||
countdownEl.classList.remove('urgent');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeCountdown() {
|
||||
function removeCountdown() {
|
||||
const el = document.getElementById('order-countdown');
|
||||
if (el) el.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Update countdown every minute
|
||||
setInterval(updateCountdown, 60000);
|
||||
// Also update on load
|
||||
setTimeout(updateCountdown, 1000);
|
||||
// Update countdown every minute
|
||||
setInterval(updateCountdown, 60000);
|
||||
// Also update on load
|
||||
setTimeout(updateCountdown, 1000);
|
||||
|
||||
// === Helpers ===
|
||||
function getISOWeek(date) {
|
||||
// === Helpers ===
|
||||
function getISOWeek(date) {
|
||||
const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
||||
const dayNum = d.getUTCDay() || 7;
|
||||
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
||||
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
||||
return Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
|
||||
}
|
||||
}
|
||||
|
||||
function getWeekYear(d) {
|
||||
function getWeekYear(d) {
|
||||
const date = new Date(d.getTime());
|
||||
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
|
||||
return date.getFullYear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function translateDay(englishDay) {
|
||||
function translateDay(englishDay) {
|
||||
const map = { Monday: 'Montag', Tuesday: 'Dienstag', Wednesday: 'Mittwoch', Thursday: 'Donnerstag', Friday: 'Freitag', Saturday: 'Samstag', Sunday: 'Sonntag' };
|
||||
return map[englishDay] || englishDay;
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text || '';
|
||||
return div.innerHTML;
|
||||
}
|
||||
}
|
||||
|
||||
// === Bootstrap ===
|
||||
injectUI();
|
||||
bindEvents();
|
||||
updateAuthUI();
|
||||
cleanupExpiredFlags();
|
||||
// === Bootstrap ===
|
||||
injectUI();
|
||||
bindEvents();
|
||||
updateAuthUI();
|
||||
cleanupExpiredFlags();
|
||||
|
||||
// Load cached data first for instant UI, then refresh from API
|
||||
const hadCache = loadMenuCache();
|
||||
if (hadCache) {
|
||||
// Load cached data first for instant UI, then refresh from API
|
||||
const hadCache = loadMenuCache();
|
||||
if (hadCache) {
|
||||
// Hide loading spinner since cache is shown
|
||||
document.getElementById('loading').classList.add('hidden');
|
||||
}
|
||||
loadMenuDataFromAPI();
|
||||
}
|
||||
loadMenuDataFromAPI();
|
||||
|
||||
// Auto-start polling if already logged in
|
||||
if (authToken) {
|
||||
// Auto-start polling if already logged in
|
||||
if (authToken) {
|
||||
startPolling();
|
||||
}
|
||||
}
|
||||
|
||||
// Check for updates
|
||||
checkForUpdates();
|
||||
// Check for updates
|
||||
checkForUpdates();
|
||||
|
||||
console.log('Kantine Wrapper loaded ✅');
|
||||
}) ();
|
||||
console.log('Kantine Wrapper loaded ✅');
|
||||
})();
|
||||
|
||||
// === Error Modal ===
|
||||
function showErrorModal(title, htmlContent, btnText, url) {
|
||||
|
||||
220
kantine.js
220
kantine.js
@@ -664,13 +664,13 @@
|
||||
// === Highlight Management ===
|
||||
let highlightTags = JSON.parse(localStorage.getItem('kantine_highlightTags') || '[]');
|
||||
|
||||
function saveHighlightTags() {
|
||||
function saveHighlightTags() {
|
||||
localStorage.setItem('kantine_highlightTags', JSON.stringify(highlightTags));
|
||||
renderVisibleWeeks(); // Refresh UI to apply changes
|
||||
updateNextWeekBadge();
|
||||
}
|
||||
}
|
||||
|
||||
function addHighlightTag(tag) {
|
||||
function addHighlightTag(tag) {
|
||||
tag = tag.trim().toLowerCase();
|
||||
if (tag && !highlightTags.includes(tag)) {
|
||||
highlightTags.push(tag);
|
||||
@@ -678,14 +678,14 @@ function addHighlightTag(tag) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function removeHighlightTag(tag) {
|
||||
function removeHighlightTag(tag) {
|
||||
highlightTags = highlightTags.filter(t => t !== tag);
|
||||
saveHighlightTags();
|
||||
}
|
||||
}
|
||||
|
||||
function renderTagsList() {
|
||||
function renderTagsList() {
|
||||
const list = document.getElementById('tags-list');
|
||||
list.innerHTML = '';
|
||||
highlightTags.forEach(tag => {
|
||||
@@ -702,28 +702,28 @@ function renderTagsList() {
|
||||
renderTagsList();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function checkHighlight(text) {
|
||||
function checkHighlight(text) {
|
||||
if (!text) return false;
|
||||
text = text.toLowerCase();
|
||||
return highlightTags.some(tag => text.includes(tag));
|
||||
}
|
||||
}
|
||||
|
||||
// === Local Menu Cache (localStorage) ===
|
||||
const CACHE_KEY = 'kantine_menuCache';
|
||||
const CACHE_TS_KEY = 'kantine_menuCacheTs';
|
||||
// === Local Menu Cache (localStorage) ===
|
||||
const CACHE_KEY = 'kantine_menuCache';
|
||||
const CACHE_TS_KEY = 'kantine_menuCacheTs';
|
||||
|
||||
function saveMenuCache() {
|
||||
function saveMenuCache() {
|
||||
try {
|
||||
localStorage.setItem(CACHE_KEY, JSON.stringify(allWeeks));
|
||||
localStorage.setItem(CACHE_TS_KEY, new Date().toISOString());
|
||||
} catch (e) {
|
||||
console.warn('Failed to cache menu data:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadMenuCache() {
|
||||
function loadMenuCache() {
|
||||
try {
|
||||
const cached = localStorage.getItem(CACHE_KEY);
|
||||
const cachedTs = localStorage.getItem(CACHE_TS_KEY);
|
||||
@@ -741,10 +741,10 @@ function loadMenuCache() {
|
||||
console.warn('Failed to load cached menu:', e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// === Menu Data Fetching (Direct from Bessa API) ===
|
||||
async function loadMenuDataFromAPI() {
|
||||
// === Menu Data Fetching (Direct from Bessa API) ===
|
||||
async function loadMenuDataFromAPI() {
|
||||
const loading = document.getElementById('loading');
|
||||
const progressModal = document.getElementById('progress-modal');
|
||||
const progressFill = document.getElementById('progress-fill');
|
||||
@@ -937,10 +937,10 @@ async function loadMenuDataFromAPI() {
|
||||
} finally {
|
||||
loading.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Last Updated Display ===
|
||||
function updateLastUpdatedTime(isoTimestamp) {
|
||||
// === Last Updated Display ===
|
||||
function updateLastUpdatedTime(isoTimestamp) {
|
||||
const subtitle = document.getElementById('last-updated-subtitle');
|
||||
if (!isoTimestamp) return;
|
||||
try {
|
||||
@@ -951,10 +951,10 @@ function updateLastUpdatedTime(isoTimestamp) {
|
||||
} catch (e) {
|
||||
subtitle.textContent = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Toast Notification ===
|
||||
function showToast(message, type = 'info') {
|
||||
// === Toast Notification ===
|
||||
function showToast(message, type = 'info') {
|
||||
let container = document.getElementById('toast-container');
|
||||
if (!container) {
|
||||
container = document.createElement('div');
|
||||
@@ -971,10 +971,10 @@ function showToast(message, type = 'info') {
|
||||
toast.classList.remove('show');
|
||||
setTimeout(() => toast.remove(), 300);
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
// === Next Week Badge ===
|
||||
function updateNextWeekBadge() {
|
||||
// === Next Week Badge ===
|
||||
function updateNextWeekBadge() {
|
||||
const btnNextWeek = document.getElementById('btn-next-week');
|
||||
let nextWeek = currentWeekNumber + 1;
|
||||
let nextYear = currentYear;
|
||||
@@ -1056,10 +1056,10 @@ function updateNextWeekBadge() {
|
||||
} else if (badge) {
|
||||
badge.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Weekly Cost ===
|
||||
function updateWeeklyCost(days) {
|
||||
// === Weekly Cost ===
|
||||
function updateWeeklyCost(days) {
|
||||
let totalCost = 0;
|
||||
if (days && days.length > 0) {
|
||||
days.forEach(day => {
|
||||
@@ -1081,10 +1081,10 @@ function updateWeeklyCost(days) {
|
||||
} else {
|
||||
costDisplay.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Render Weeks ===
|
||||
function renderVisibleWeeks() {
|
||||
// === Render Weeks ===
|
||||
function renderVisibleWeeks() {
|
||||
const menuContainer = document.getElementById('menu-container');
|
||||
if (!menuContainer) return;
|
||||
menuContainer.innerHTML = '';
|
||||
@@ -1142,10 +1142,10 @@ function renderVisibleWeeks() {
|
||||
|
||||
menuContainer.appendChild(grid);
|
||||
setTimeout(() => syncMenuItemHeights(grid), 0);
|
||||
}
|
||||
}
|
||||
|
||||
// === Sync Item Heights ===
|
||||
function syncMenuItemHeights(grid) {
|
||||
// === Sync Item Heights ===
|
||||
function syncMenuItemHeights(grid) {
|
||||
const cards = grid.querySelectorAll('.menu-card');
|
||||
if (cards.length === 0) return;
|
||||
let maxItems = 0;
|
||||
@@ -1165,10 +1165,10 @@ function syncMenuItemHeights(grid) {
|
||||
});
|
||||
itemsAtPos.forEach(item => { item.style.height = `${maxHeight}px`; });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Create Day Card ===
|
||||
function createDayCard(day) {
|
||||
// === Create Day Card ===
|
||||
function createDayCard(day) {
|
||||
if (!day.items || day.items.length === 0) return null;
|
||||
|
||||
const card = document.createElement('div');
|
||||
@@ -1395,22 +1395,70 @@ function createDayCard(day) {
|
||||
|
||||
card.appendChild(body);
|
||||
return card;
|
||||
}
|
||||
}
|
||||
|
||||
// === Version Check ===
|
||||
async function checkForUpdates() {
|
||||
icon.className = 'update-icon';
|
||||
icon.href = url;
|
||||
icon.target = '_blank';
|
||||
icon.innerHTML = '🆕'; // User requested icon
|
||||
icon.title = `Neue Version verfügbar (${newVersion}). Klick für download`;
|
||||
// === Version Check ===
|
||||
async function checkForUpdates() {
|
||||
const CurrentVersion = '{{VERSION}}';
|
||||
const VersionUrl = 'https://raw.githubusercontent.com/TauNeutrino/kantine-overview/main/version.txt';
|
||||
const InstallerUrl = 'https://htmlpreview.github.io/?https://github.com/TauNeutrino/kantine-overview/blob/main/dist/install.html';
|
||||
|
||||
headerTitle.appendChild(icon);
|
||||
showToast(`Update verfügbar: ${newVersion}`, 'info');
|
||||
}
|
||||
console.log(`[Kantine] Checking for updates... (Current: ${CurrentVersion})`);
|
||||
|
||||
// === Order Countdown ===
|
||||
function updateCountdown() {
|
||||
try {
|
||||
const response = await fetch(VersionUrl, { cache: 'no-cache' });
|
||||
if (!response.ok) return;
|
||||
|
||||
const remoteVersion = (await response.text()).trim();
|
||||
|
||||
if (remoteVersion && remoteVersion !== CurrentVersion) {
|
||||
console.log(`[Kantine] New version available: ${remoteVersion}`);
|
||||
|
||||
// Fetch Changelog content
|
||||
let changeSummary = '';
|
||||
try {
|
||||
const clResp = await fetch('https://raw.githubusercontent.com/TauNeutrino/kantine-overview/main/changelog.md');
|
||||
if (clResp.ok) {
|
||||
const clText = await clResp.text();
|
||||
const match = clText.match(/## (v[^\n]+)\n((?:-[^\n]+\n)+)/);
|
||||
if (match && match[1].includes(remoteVersion)) {
|
||||
changeSummary = match[2].replace(/- /g, '• ').trim();
|
||||
}
|
||||
}
|
||||
} catch (e) { console.warn('No changelog', e); }
|
||||
|
||||
// Create Banner
|
||||
const updateBanner = document.createElement('div');
|
||||
updateBanner.className = 'update-banner';
|
||||
updateBanner.innerHTML = `
|
||||
<div class="update-content">
|
||||
<strong>Update verfügbar: ${remoteVersion}</strong>
|
||||
${changeSummary ? `<pre class="change-summary">${changeSummary}</pre>` : ''}
|
||||
<a href="${InstallerUrl}" target="_blank" class="update-link">
|
||||
<span class="material-icons-round">system_update_alt</span>
|
||||
Jetzt aktualisieren
|
||||
</a>
|
||||
</div>
|
||||
<button class="icon-btn-small close-update">×</button>
|
||||
`;
|
||||
|
||||
document.body.appendChild(updateBanner);
|
||||
updateBanner.querySelector('.close-update').addEventListener('click', () => updateBanner.remove());
|
||||
|
||||
// Highlight Header Icon
|
||||
const lastUpdatedIcon = document.querySelector('.material-icons-round.logo-icon');
|
||||
if (lastUpdatedIcon) {
|
||||
lastUpdatedIcon.style.color = 'var(--accent-color)';
|
||||
lastUpdatedIcon.parentElement.title = `Update verfügbar: ${remoteVersion}`;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('[Kantine] Version check failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// === Order Countdown ===
|
||||
function updateCountdown() {
|
||||
const now = new Date();
|
||||
const currentDay = now.getDay();
|
||||
// Skip weekends (0=Sun, 6=Sat)
|
||||
@@ -1489,69 +1537,69 @@ function updateCountdown() {
|
||||
} else {
|
||||
countdownEl.classList.remove('urgent');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeCountdown() {
|
||||
function removeCountdown() {
|
||||
const el = document.getElementById('order-countdown');
|
||||
if (el) el.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Update countdown every minute
|
||||
setInterval(updateCountdown, 60000);
|
||||
// Also update on load
|
||||
setTimeout(updateCountdown, 1000);
|
||||
// Update countdown every minute
|
||||
setInterval(updateCountdown, 60000);
|
||||
// Also update on load
|
||||
setTimeout(updateCountdown, 1000);
|
||||
|
||||
// === Helpers ===
|
||||
function getISOWeek(date) {
|
||||
// === Helpers ===
|
||||
function getISOWeek(date) {
|
||||
const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
||||
const dayNum = d.getUTCDay() || 7;
|
||||
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
||||
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
||||
return Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
|
||||
}
|
||||
}
|
||||
|
||||
function getWeekYear(d) {
|
||||
function getWeekYear(d) {
|
||||
const date = new Date(d.getTime());
|
||||
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
|
||||
return date.getFullYear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function translateDay(englishDay) {
|
||||
function translateDay(englishDay) {
|
||||
const map = { Monday: 'Montag', Tuesday: 'Dienstag', Wednesday: 'Mittwoch', Thursday: 'Donnerstag', Friday: 'Freitag', Saturday: 'Samstag', Sunday: 'Sonntag' };
|
||||
return map[englishDay] || englishDay;
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text || '';
|
||||
return div.innerHTML;
|
||||
}
|
||||
}
|
||||
|
||||
// === Bootstrap ===
|
||||
injectUI();
|
||||
bindEvents();
|
||||
updateAuthUI();
|
||||
cleanupExpiredFlags();
|
||||
// === Bootstrap ===
|
||||
injectUI();
|
||||
bindEvents();
|
||||
updateAuthUI();
|
||||
cleanupExpiredFlags();
|
||||
|
||||
// Load cached data first for instant UI, then refresh from API
|
||||
const hadCache = loadMenuCache();
|
||||
if (hadCache) {
|
||||
// Load cached data first for instant UI, then refresh from API
|
||||
const hadCache = loadMenuCache();
|
||||
if (hadCache) {
|
||||
// Hide loading spinner since cache is shown
|
||||
document.getElementById('loading').classList.add('hidden');
|
||||
}
|
||||
loadMenuDataFromAPI();
|
||||
}
|
||||
loadMenuDataFromAPI();
|
||||
|
||||
// Auto-start polling if already logged in
|
||||
if (authToken) {
|
||||
// Auto-start polling if already logged in
|
||||
if (authToken) {
|
||||
startPolling();
|
||||
}
|
||||
}
|
||||
|
||||
// Check for updates
|
||||
checkForUpdates();
|
||||
// Check for updates
|
||||
checkForUpdates();
|
||||
|
||||
console.log('Kantine Wrapper loaded ✅');
|
||||
}) ();
|
||||
console.log('Kantine Wrapper loaded ✅');
|
||||
})();
|
||||
|
||||
// === Error Modal ===
|
||||
function showErrorModal(title, htmlContent, btnText, url) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
v1.1.1
|
||||
v1.1.2
|
||||
|
||||
Reference in New Issue
Block a user