MINT-Projekt/assets/js/main.js

69 lines
No EOL
2.1 KiB
JavaScript

/*
* 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 <http://www.gnu.org/licenses/>.
*/
document.addEventListener('DOMContentLoaded', init);
function init() {
//forceHttps();
actrivateMessage();
setTimeout(hideMessage, 3000);
windowReload();
}
function forceHttps() {
if (location.protocol != 'https:') {
location.href = 'https://' + location.hostname + location.pathname;
}
}
function actrivateMessage() {
document.querySelectorAll('.modal').forEach((modal)=>{modal.style.position = 'fixed'});
}
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];
}
function hideMessage() {
if (getFileName() != 'check.php') {
document.querySelectorAll('.modal').forEach((modal) => { modal.style.display = 'none' });
}
}
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
}
}
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);
}