const params = new URLSearchParams(window.location.search); const isApple = /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent) && !window.MSStream; var actId; var liveStreamAvailable = false; var storiesBarSize = 0; var storiesBarStepsPercent = 0; var loadStoriesBarInterval; var loadStoriesTimeout; var loadStoryInterval; let globalSoundEnabled = false; let stories = window.stories || []; // your page pushes ids into this earlier let storiesTimeout = window.storiesTimeout || 7000; // default image duration (ms) let storyTimers = { loadStoryInterval: null, loadStoriesBarInterval: null, loadStoriesTimeout: null }; let storiesWorkaround = []; let previousStory = null; let actualStory = null; function isAndroid() { return /Android/i.test(navigator.userAgent); } function isInApp() { return typeof AndroidInterface !== "undefined"; } function showToast(message) { const toast = document.getElementById("toast"); toast.textContent = message; toast.classList.add("show"); setTimeout(() => { toast.classList.remove("show"); }, 5000); } var menuStatus = 0; function switchMenu(){ if(menuStatus == 0){ document.getElementById('menu').style.display = 'flex'; document.getElementById('menu-btn').classList.toggle("active"); menuStatus = 1; return true; } if(window.menuStatus == 1){ document.getElementById('menu').style.display = 'none'; document.getElementById('menu-btn').classList.toggle("active"); menuStatus = 0; return true; } } window.onscroll = function() {shrinkHeader();shrinkBottom()}; document.addEventListener("DOMContentLoaded", function() { const bottom = document.getElementById("bottom"); if (bottom) { bottom.onmouseout = function() { console.log("Mouse left footer"); shrinkBottom(); }; } }); function shrinkHeader() { var topdiv = document.getElementById("top"); var sheet = document.getElementById("sheet"); if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) { sheet.style.paddingTop = "80px"; topdiv.classList.add("shrink"); } else { sheet.style.paddingTop = "0px"; topdiv.classList.remove("shrink"); } } function adjustSheetPadding() { const bottom = document.getElementById("bottom"); const sheet = document.getElementById("sheet"); sheet.style.paddingBottom = bottom.offsetHeight + "px"; } function enableAttachedOnInteract() { var bottomdiv = document.getElementById("bottom"); if (bottomdiv.classList.contains("shrink")) { bottomdiv.classList.remove("shrink"); bottomdiv.classList.add("attached"); } } document.addEventListener("DOMContentLoaded", () => { var bottomdiv = document.getElementById("bottom"); bottomdiv.addEventListener("click", enableAttachedOnInteract); bottomdiv.addEventListener("mouseover", enableAttachedOnInteract); }); function shrinkBottom() { var bottomdiv = document.getElementById("bottom"); var sheet = document.getElementById("sheet"); // Scroll-Position prüfen var scrolled = document.body.scrollTop || document.documentElement.scrollTop; if (scrolled > 50) { sheet.style.paddingBottom = "120px"; bottomdiv.classList.add("shrink"); } else { sheet.style.paddingBottom = "0px"; bottomdiv.classList.remove("shrink"); } // Prüfen, ob das Ende der Seite erreicht ist var scrollTop = window.scrollY || document.documentElement.scrollTop; var viewportH = window.innerHeight; var fullHeight = document.documentElement.scrollHeight; if (scrollTop + viewportH >= fullHeight) { bottomdiv.classList.add("attached"); adjustSheetPadding(); } else { bottomdiv.classList.remove("attached"); } } function scrollToElementWithOffset(elementId, offset) { var topdiv = document.getElementById("top"); //if(topdiv.classList.contains('shrink')){ // offset += 100; //} const element = document.getElementById(elementId); const elementPosition = element.getBoundingClientRect().top; const offsetPosition = elementPosition + window.scrollY + offset; window.scrollTo({ top: offsetPosition, behavior: 'smooth' // Für sanftes Scrollen }); } function animateWidth(element, duration) { let targetWidth = parseFloat(element.style.width); element.style.width = "0%"; let stepTime = 10; let steps = duration / stepTime; let stepSize = targetWidth / steps; let currentWidth = 0; let interval = setInterval(() => { currentWidth += stepSize; if (currentWidth >= targetWidth) { currentWidth = targetWidth; clearInterval(interval); } element.style.width = currentWidth + "%"; }, stepTime); } document.addEventListener("DOMContentLoaded", function() { document.querySelectorAll(".viewbar-indicator, .viewbar-indicator-g").forEach(el => { animateWidth(el, 1500); }); }); function makeRequest(parameters) { httpRequest = new XMLHttpRequest(); if (!httpRequest) { alert('Problem creating connection.'); return false; } httpRequest.onreadystatechange = makeContents; httpRequest.open('GET','/handler.php?unique=1763888258' + parameters); httpRequest.send(); } function makeContents(htmlId) { if (httpRequest.readyState === XMLHttpRequest.DONE) { if (httpRequest.status === 200) { if(httpRequest.responseText.length == 0){ liveStreamAvailable = false; if(document.getElementById(actId)){ document.getElementById(actId).innerHTML = " "; } if(document.getElementById("nxtLive")){ document.getElementById("nxtLive").style.display = "block"; } }else{ liveStreamAvailable = true; if(document.getElementById(actId)){ document.getElementById(actId).innerHTML = httpRequest.responseText; } if(document.getElementById("nxtLive")){ document.getElementById("nxtLive").style.display = "none"; } } } } } function getCWD(){ actId = "cwd"; var parameters = "&a=checkLiveAvailable"; makeRequest(parameters); } function checkLiveAvailable(){ if(liveStreamAvailable == true){ document.getElementById('headLiveEye').style.display = "block"; }else{ document.getElementById('headLiveEye').style.display = "none"; } } function initScan(){ getCWD(); setInterval(getCWD, 5000); setInterval(checkLiveAvailable, 1000); } function clearAllStoryTimers() { // clear both timeouts and intervals that we may have set Object.keys(storyTimers).forEach(k => { if (storyTimers[k]) { try { clearTimeout(storyTimers[k]); } catch(e){} try { clearInterval(storyTimers[k]); } catch(e){} storyTimers[k] = null; } }); } /* ======== UI helpers ======== */ function hideStories(){ clearAllStoryTimers(); // hide UI const storyRoot = document.getElementById('story'); if (storyRoot) storyRoot.style.display = 'none'; // reset bar quickly const bar = document.getElementById('storiesbar'); if (bar) { bar.style.transition = 'none'; bar.style.width = '0%'; } // hide content previousStory = null; storiesWorkaround = []; document.querySelectorAll('.story-content').forEach(el => el.style.display = 'none'); } function loadStoriesBar(){ // Legacy: this is kept for compatibility but uses central timers if (typeof storiesBarSize === 'undefined') window.storiesBarSize = 0; if (typeof storiesBarStepsPercent === 'undefined') window.storiesBarStepsPercent = 1; window.storiesBarSize = window.storiesBarSize + window.storiesBarStepsPercent; document.getElementById("storiesbar").style.width = window.storiesBarSize + "%"; } /* ======== Video helpers ======== */ function safePlay(video) { if (!video) return Promise.resolve(); // respect globalSoundEnabled video.muted = !globalSoundEnabled; return new Promise(resolve => { const attempt = () => { const p = video.play(); if (!p || typeof p.then !== "function") { // play invoked synchronously or not promise-based resolve(); return; } p.then(() => resolve()).catch(() => { // retry a few times setTimeout(attempt, 150); }); }; attempt(); }); } function waitForVideoToActuallyPlay(video, timeoutMs = 5000) { return new Promise(resolve => { if (!video) { resolve(); return; } let done = false; const finish = () => { if (!done) { done = true; resolve(); } }; if (!video.paused && !video.seeking && video.currentTime > 0) { finish(); return; } video.addEventListener('playing', finish, { once: true }); video.addEventListener('timeupdate', finish, { once: true }); setTimeout(finish, timeoutMs); // fallback }); } function animateProgressBarForSegment(segmentIndex, durationMs) { const bar = document.getElementById("storiesbar"); if (!bar) return; const totalSegments = stories.length || 1; const segmentWidth = 100 / totalSegments; const startWidth = segmentIndex * segmentWidth; bar.style.transition = 'none'; bar.style.width = startWidth + '%'; // Animate mit CSS-Transition requestAnimationFrame(() => { bar.style.transition = `width ${durationMs}ms linear`; bar.style.width = (startWidth + segmentWidth) + '%'; }); } function animateVideoProgressBar(video, segmentIndex) { const bar = document.getElementById("storiesbar"); if (!bar || !video) return; const totalSegments = stories.length || 1; const segmentWidth = 100 / totalSegments; const startWidth = segmentIndex * segmentWidth; bar.style.transition = 'none'; bar.style.width = startWidth + '%'; // Stopp vorheriger Animationsloops für Sicherheit if (video._progressAnim) cancelAnimationFrame(video._progressAnim); function update() { if (video.ended) return; const progress = video.currentTime / video.duration; // 0..1 bar.style.width = startWidth + segmentWidth * progress + '%'; video._progressAnim = requestAnimationFrame(update); } video._progressAnim = requestAnimationFrame(update); } function initHLSForVideo(video) { if (!video) return; if (video.dataset.hlsInitialized === "1") return; const src = video.dataset.hlsSrc; const id = parseInt(video.dataset.id || 0); if (!src) { video.dataset.hlsInitialized = "1"; return; } // defensive: remove src if present try { if (video.hasAttribute('src')) { video.removeAttribute('src'); video.load(); } } catch(e){} if (window.Hls && Hls.isSupported()) { // create and attach const hls = new Hls(); video._hlsInstance = hls; hls.on(Hls.Events.ERROR, function(ev, data) { console.warn("HLS error", data); // try simple recovery for network/media errors if (data && data.fatal) { try { hls.destroy(); } catch(e){} video.dataset.hlsInitialized = ""; // allow retry later } }); hls.loadSource(src); hls.attachMedia(video); // duration may come later; listen for durationchange video.addEventListener('durationchange', () => { if (!isNaN(video.duration) && video.duration !== Infinity && video.duration > 0) { window.videoDurations = window.videoDurations || {}; window.videoDurations[id] = Math.round(video.duration * 1000); } }); video.dataset.hlsInitialized = "1"; return; } // native Safari HLS if (video.canPlayType && video.canPlayType('application/vnd.apple.mpegurl')) { video.src = src; video.dataset.hlsInitialized = "1"; } else { video.dataset.hlsInitialized = "1"; } } function unmuteStoryVideo(id) { const story = document.getElementById("story-" + id); if (!story) return; const vid = story.querySelector("video"); if (!vid) return; vid.muted = false; globalSoundEnabled = true; const btn = story.querySelector(".story-sound-btn"); if (btn) btn.style.display = "none"; safePlay(vid); } function showStory() { clearAllStoryTimers(); if (!storiesWorkaround || storiesWorkaround.length === 0) { hideStories(); return; } actualStory = storiesWorkaround.shift(); if (!actualStory) { hideStories(); return; } if (previousStory) { const prevEl = document.getElementById('story-' + previousStory); if (prevEl) prevEl.style.display = 'none'; } const container = document.getElementById('story-' + actualStory); if (!container) { previousStory = null; return showStory(); } container.style.display = 'block'; previousStory = actualStory; const storyRoot = document.getElementById('story'); storyRoot.style.opacity = 1; storyRoot.style.pointerEvents = 'auto'; document.querySelectorAll(".story-sound-btn").forEach(b => b.style.display = "none"); const soundBtn = container.querySelector(".story-sound-btn"); const vid = container.querySelector("video"); const segIndex = stories.indexOf(actualStory); if (vid) { vid.muted = !globalSoundEnabled; if (!globalSoundEnabled && soundBtn) soundBtn.style.display = 'block'; initHLSForVideo(vid); safePlay(vid).then(() => waitForVideoToActuallyPlay(vid, 4000)) .then(() => { const segIndex = stories.indexOf(actualStory); const bar = document.getElementById("storiesbar"); const totalSegments = stories.length || 1; const segmentWidth = 100 / totalSegments; const startWidth = segIndex * segmentWidth; // vorherige Animation abbrechen if (vid._progressAnim) cancelAnimationFrame(vid._progressAnim); function update() { if (vid.ended) return; const progress = vid.currentTime / vid.duration; bar.style.width = startWidth + segmentWidth * progress + '%'; vid._progressAnim = requestAnimationFrame(update); } vid._progressAnim = requestAnimationFrame(update); storyTimers.loadStoriesTimeout = setTimeout(showStory, vid.duration * 1000); }); return; } const duration = window.videoDurations && window.videoDurations[actualStory] ? window.videoDurations[actualStory] : storiesTimeout; animateProgressBarForSegment(segIndex, duration); storyTimers.loadStoriesTimeout = setTimeout(showStory, duration); } function skipStory() { // reset current video if any const currentVid = document.querySelector('#story-' + actualStory + ' video'); if (currentVid) { try { currentVid.pause(); currentVid.currentTime = 0; } catch(e){} } // immediately clear timers and show next clearAllStoryTimers(); // jump progress bar one step visually const segIndex = stories.indexOf(actualStory); const totalSegments = stories.length || 1; const segmentWidth = 100 / totalSegments; const bar = document.getElementById("storiesbar"); if (bar) { const startWidth = segIndex * segmentWidth; bar.style.transition = "none"; bar.style.width = (startWidth + segmentWidth) + "%"; } // show next story showStory(); } function showStories() { // Reset everything hideStories(); storiesWorkaround = stories.slice(); const root = document.getElementById('story'); if (root) root.style.display = 'flex'; // reset progress internal vars window.storiesBarSize = 0; window.storiesBarStepsPercent = 1; // start first showStory(); } function reinitAllStoryVideos() { // Instead of forcing HLS re-init (which can break), gently pause + reset time document.querySelectorAll(".story-video").forEach(video => { try { video.pause(); video.currentTime = 0; } catch(e){} // don't force re-init here — init is done when the story is shown }); } /* ======== Boot / attach global handlers ======== */ window.addEventListener("load", () => { // if you have a persisted last-story marker, keep UI small if (document.getElementById('stories')) { document.getElementById('stories').style.opacity = '0.35'; } }); if(typeof AndroidInterface !== 'undefined'){ document.addEventListener('touchstart', handleTouchStart, false); document.addEventListener('touchmove', handleTouchMove, false); var xDown = null; var yDown = null; var sensitivityThreshold = 10; function getTouches(evt) { return evt.touches || evt.originalEvent.touches; } function handleTouchStart(evt) { const firstTouch = getTouches(evt)[0]; xDown = firstTouch.clientX; yDown = firstTouch.clientY; }; function handleTouchMove(evt) { if ( ! xDown || ! yDown ) { return; } var xUp = evt.touches[0].clientX; var yUp = evt.touches[0].clientY; var xDiff = xDown - xUp; var yDiff = yDown - yUp; if (Math.abs(xDiff) > Math.abs(yDiff) && Math.abs(xDiff) > sensitivityThreshold) { if (xDiff > 0) { // Handle swipe to the left } else if (xDiff < -sensitivityThreshold) { history.back(); } } xDown = null; yDown = null; }; } function adjustScrollForStickyHead(elName) { const top = document.getElementById('top'); const header = document.getElementById('header'); if (top.classList.contains('shrink')) { const elementHeight = header.offsetHeight; window.scrollBy({ top: -elementHeight, behavior: 'smooth' }); }else{ var c = document.getElementById(elName); c.scrollIntoView({behavior:'smooth',block:'start'}); } } function initialScrollTo(elName) { var c = document.getElementById(elName); c.scrollIntoView({behavior:'smooth',block:'start'}); setTimeout(function(){adjustScrollForStickyHead(elName);}, 500); } function customConfirm(message) { return new Promise((resolve) => { const overlay = document.createElement("div"); overlay.style.position = "fixed"; overlay.style.top = 0; overlay.style.left = 0; overlay.style.width = "100%"; overlay.style.height = "100%"; overlay.style.backgroundColor = "rgba(0, 0, 0, 0.5)"; overlay.style.display = "flex"; overlay.style.alignItems = "center"; overlay.style.justifyContent = "center"; document.body.appendChild(overlay); const dialog = document.createElement("div"); dialog.style.width = "300px"; dialog.style.padding = "20px"; dialog.style.backgroundColor = "white"; dialog.style.borderRadius = "8px"; dialog.style.boxShadow = "0 4px 8px rgba(0, 0, 0, 0.2)"; overlay.appendChild(dialog); const messageText = document.createElement("p"); messageText.innerText = message; messageText.style.marginBottom = "20px"; dialog.appendChild(messageText); const okButton = document.createElement("button"); okButton.innerText = "OK"; okButton.style.marginRight = "10px"; dialog.appendChild(okButton); const cancelButton = document.createElement("button"); cancelButton.innerText = "Abbrechen"; dialog.appendChild(cancelButton); okButton.addEventListener("click", () => { document.body.removeChild(overlay); resolve(true); }); cancelButton.addEventListener("click", () => { document.body.removeChild(overlay); resolve(false); }); }); } /* Verwenden der Funktion customConfirm("Möchten Sie fortfahren?").then((result) => { if (result) { console.log("Bestätigt"); } else { console.log("Abgelehnt"); } });*/ function openNewWindow(url2) { if (typeof AndroidInterface !== 'undefined' && AndroidInterface.openExternalBrowser) { AndroidInterface.openExternalBrowser(url2); } else { window.open(url2, '_blank'); } } function openNewWindowIfInApp(url2) { if (typeof AndroidInterface !== 'undefined'){ if (typeof AndroidInterface !== 'undefined' && AndroidInterface.openExternalBrowser) { AndroidInterface.openExternalBrowser(url2); } else { window.open(url2, '_blank'); } }else{ location.href=url2; } } function handleAdClick(wrapper) { const video = wrapper.querySelector('video'); const link = wrapper.dataset.link; if (!video.muted) { video.muted = true; const label = wrapper.closest('.ad-container').querySelector('.adSoundStatus'); if (label) { label.textContent = 'Ton an'; } } openNewWindow(link); } function toggleAdSound(el) { const video = el.closest('.ad-container').querySelector('video'); video.muted = !video.muted; el.textContent = video.muted ? 'Ton an' : 'Ton aus'; } function initAdVideos() { document.querySelectorAll('.ad-container').forEach(container => { const video = container.querySelector('video'); const label = container.querySelector('.adSoundStatus'); if (video && label) { label.textContent = video.muted ? 'Ton an' : 'Ton aus'; } }); } function preventWidowText(selector) { document.querySelectorAll(selector).forEach(el => { const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false); let lastTextNode = null; // Letzten nicht-leeren Textknoten finden while (walker.nextNode()) { const node = walker.currentNode; if (node.nodeValue.trim().length > 0) { lastTextNode = node; } } if (lastTextNode) { const text = lastTextNode.nodeValue.trimEnd(); const lastSpace = text.lastIndexOf(' '); if (lastSpace !== -1) { lastTextNode.nodeValue = text.substring(0, lastSpace) + '\u00A0' + text.substring(lastSpace + 1); } } }); } document.addEventListener('DOMContentLoaded', initAdVideos); document.addEventListener("DOMContentLoaded", function() { preventWidowText("p"); });