/* * Copyright (C) 2021 Eichehome * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ document.addEventListener('DOMContentLoaded', init); /** * Initiale Methode, die alles startet */ function init() { //forceHttps();//Da Https nicht funktioniert actrivateMessage(); setTimeout(hideMessage, 3000); windowReload(); } /** * Diese Methode stellt das Protokoll fals nötig auf https:// um */ function forceHttps() { if (location.protocol != 'https:') { location.href = 'https://' + location.hostname + location.pathname; } } /** * Diese Methode lässt die Status-/Fehlermeldung(en) erscheinen */ function actrivateMessage() { document.querySelectorAll('.modal').forEach((modal) => { modal.style.position = 'fixed' }); } /** * Diese Methode extrahiert den Dateinamen aus der Adresse * @returns {string} Der Dateinamen */ function getFileName() { let pathname = location.pathname; let fileNameRegEx = /[a-z]+\.[a-z]+/i; let fileName = pathname.match(fileNameRegEx); return (fileName === null)?'index.php':fileName[0]; } /** * Diese Methode lässt die Status-/Fehlermeldung(en) verschwinden */ function hideMessage() { if (getFileName() != 'check.php') { document.querySelectorAll('.modal').forEach((modal) => { modal.style.display = 'none' }); } } /** * Diese Methode startet auf der Seite check.php den Countdown */ function windowReload() { if (getFileName() == 'check.php') { let message = document.querySelector('.message p').innerHTML; let timeRegEx = /[0-9]/; let time = message.match(timeRegEx); time = time[0]; setTimeout(updateMessage, 1000, time, message);//Starte Countdown } } /** * Diese Funktion ändert die Zeit in der Anzeige des Countdowns und das neuladen der Seite am Ende * @param {int} time Zeit des Countdowns * @param {string} message Statusnachricht * @returns {empty} */ function updateMessage(time, message) { let newTime = time-1; message = message.replace(time, newTime); document.querySelector('.message p').innerHTML = message; if (newTime == 1) { setTimeout(() => {location.reload()}, 1000); return; } setTimeout(updateMessage, 1000, newTime, message); }