mirror of
https://github.com/Matewoo/pdf-writer.git
synced 2026-11-18 18:42:50 +01:00
add weeklyFeed scrolling + minor fixes
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
|
||||
<head>
|
||||
@@ -8,6 +7,9 @@
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Fira Sans', sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
h1 {
|
||||
@@ -15,7 +17,12 @@
|
||||
font-size: 50px;
|
||||
font-weight: 300;
|
||||
font-style: italic;
|
||||
margin-top: 0;
|
||||
margin: 0;
|
||||
padding: 10px;
|
||||
background: #ffffff;
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
h2 {
|
||||
@@ -52,24 +59,53 @@
|
||||
.side {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
margin-left:17px;
|
||||
margin-left: 17px;
|
||||
font-size: 23px;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 0;
|
||||
border-top: 0.5px solid #707070;
|
||||
border-top: 1px solid #2b2b2b;
|
||||
width: 80%;
|
||||
margin-left: 0;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.ticker-wrapper {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
padding-top: 80px;
|
||||
}
|
||||
|
||||
.ticker-content {
|
||||
padding: 20px;
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.content {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
z-index: 1;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Freuen Sie sich auf:</h1>
|
||||
<h2></h2>
|
||||
<script>
|
||||
setInterval(() => {
|
||||
window.location.reload();
|
||||
}, 3600000);
|
||||
|
||||
</script>
|
||||
|
||||
<script src="../src/weeklyFeed.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -1,40 +1,108 @@
|
||||
let currentWeek = new Date();
|
||||
if (currentWeek.getDay() >= 5) { // 5 = Freitag
|
||||
currentWeek.setDate(currentWeek.getDate() + 7);
|
||||
}
|
||||
currentWeek.setDate(currentWeek.getDate() - currentWeek.getDay() + 1);
|
||||
|
||||
let currentDayIndex = 0; // 0 = Monday, 4 = Friday
|
||||
|
||||
function getWeekNumber(date) {
|
||||
const target = new Date(date.valueOf());
|
||||
const dayNumber = (date.getDay() + 6) % 7;
|
||||
target.setDate(target.getDate() - dayNumber + 3);
|
||||
const firstThursday = target.valueOf();
|
||||
target.setMonth(0, 1);
|
||||
if (target.getDay() !== 4) {
|
||||
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
|
||||
}
|
||||
return 1 + Math.ceil((firstThursday - target) / 604800000);
|
||||
}
|
||||
|
||||
function loadWeek(week) {
|
||||
fetch(`/load-week?week=${encodeURIComponent(week)}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const sortedData = data.sort((a, b) => a.day_index - b.day_index);
|
||||
// Default-Werte für leere Tage
|
||||
const defaultData = {
|
||||
date_title: 'WOCHENTAG',
|
||||
meat_main: 'Eintrag fehlt',
|
||||
meat_side: '',
|
||||
veggi_main: 'Eintrag fehlt',
|
||||
veggi_side: '',
|
||||
halal: false,
|
||||
day_index: 0
|
||||
};
|
||||
|
||||
let sortedData = [];
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const dayData = data.find(item => item.day_index === i);
|
||||
sortedData.push(dayData || { ...defaultData, day_index: i });
|
||||
}
|
||||
|
||||
sortedData.sort((a, b) => a.day_index - b.day_index);
|
||||
|
||||
const container = document.querySelector('body');
|
||||
container.innerHTML = `
|
||||
<h1>Freuen Sie sich auf:</h1>
|
||||
<div class="content">
|
||||
<div class="ticker-wrapper">
|
||||
<div class="ticker-content">
|
||||
${sortedData.map(item => `
|
||||
<div class="menu-item">
|
||||
<p class="category">— ${item.date_title} ${item.halal ? '<span class="halal">„HALAL"</span>' : ''}</p>
|
||||
<p class="main">~ ${item.meat_main}</p>
|
||||
<p class="side">${item.meat_side}</p>
|
||||
|
||||
<p class="main">~ ${item.veggi_main}</p>
|
||||
<p class="side">${item.veggi_side}</p>
|
||||
<hr>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
<div class="ticker-content">
|
||||
${sortedData.map(item => `
|
||||
<div class="menu-item">
|
||||
<p class="category">— ${item.date_title} ${item.halal ? '<span class="halal">„HALAL"</span>' : ''}</p>
|
||||
<p class="main">~ ${item.meat_main}</p>
|
||||
<p class="side">${item.meat_side}</p>
|
||||
<p class="main">~ ${item.veggi_main}</p>
|
||||
<p class="side">${item.veggi_side}</p>
|
||||
<hr>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
startScrolling();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error loading week:', error);
|
||||
});
|
||||
}
|
||||
|
||||
// Get current week number and year
|
||||
function getCurrentWeek() {
|
||||
const now = new Date();
|
||||
const start = new Date(now.getFullYear(), 0, 1);
|
||||
const week = Math.ceil((((now - start) / 86400000) + start.getDay() + 1) / 7);
|
||||
return `KW${week} ${now.getFullYear()}`;
|
||||
function startScrolling() {
|
||||
const tickerWrapper = document.querySelector('.ticker-wrapper');
|
||||
const tickerContents = document.querySelectorAll('.ticker-content');
|
||||
|
||||
let currentPosition = 0;
|
||||
const contentHeight = tickerContents[0].offsetHeight;
|
||||
|
||||
function scroll() {
|
||||
currentPosition -= 0.5;
|
||||
|
||||
if (Math.abs(currentPosition) >= contentHeight) {
|
||||
currentPosition = 0;
|
||||
}
|
||||
|
||||
tickerWrapper.style.transform = `translateY(${currentPosition}px)`;
|
||||
requestAnimationFrame(scroll);
|
||||
}
|
||||
|
||||
requestAnimationFrame(scroll);
|
||||
}
|
||||
|
||||
// Load current week's menu on page load
|
||||
loadWeek(getCurrentWeek());
|
||||
|
||||
// Reload page every 15 seconds
|
||||
setInterval(() => {
|
||||
window.location.reload();
|
||||
}, 15000);
|
||||
const weekNumber = getWeekNumber(currentWeek);
|
||||
const year = currentWeek.getFullYear();
|
||||
const week = `KW${weekNumber} ${year}`;
|
||||
console.log(week);
|
||||
loadWeek(week);
|
||||
Reference in New Issue
Block a user