MaketTahta/assets/js/old_main.js

139 lines
No EOL
3.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 2023 Aliberk Sandıı
// VARIABLES
var FlagSecond = 0;
var FlagSettings = 0;
var FlagTimers = 1;
var MidItems = ["timers", "stopwatch", "timer", "yemek-listesi", "animations"]
// RUN FUNCTIONS ON START
updateTime();
if (FlagSettings) { toggleSettings() }
if (FlagTimers) { toggleTimers() }
// RUN FUNCTIONS PERIODICALLY
var t = setInterval(updateTime, 1000);
//
// MAIN FUNCTIONS
//
function updateTime() {
var d = new Date();
var curHour = getDigits(d.getHours(), 2);
var curMin = getDigits(d.getMinutes(), 2);
var curSeconds = getDigits(d.getSeconds(), 2);
if (FlagSecond) {
document.getElementById("time").innerHTML = curHour + "." + curMin + "." + curSeconds;
} else {
document.getElementById("time").innerHTML = curHour + "." + curMin;
}
if (curHour == 12 && (curMin >= 24 && curMin <= 30)) {
document.getElementById("time").style.color = "red";
document.getElementById("rainbow").style.display = "inherit";
} else {
document.getElementById("time").style.color = "inherit";
document.getElementById("rainbow").style.display = "none";
}
}
function toggleClockSeconds() {
let chx = document.getElementById("chx-clockSecond");
if (chx.checked) {
FlagSecond = 1;
} else {
FlagSecond = 0;
}
updateTime();
}
function toggleDevVersion() {
let chx = document.getElementById("chx-devVersion");
if (chx.checked) {
window.location.replace("dev.html" + window.location.search);
} else {
window.location.replace("index.html" + window.location.search);
}
}
function toggleSettings() {
let settings = document.getElementById("settings");
console.log(settings.style.display);
if (settings.style.display == "flex") {
settings.style.display = "none";
} else {
settings.style.display = "flex";
}
}
function toggleTimers(typ = "display") {
switch (typ) {
case "stopwatch":
hideMidAll("stopwatch", "timers");
toggleItem("id", "stopwatch");
break;
case "timer":
hideMidAll("timer", "timers");
toggleItem("id", "timer");
break;
default: // "display"
hideMidAll("timers");
toggleItem("id", "timers");
break;
}
}
function toggleYemekListesi() {
hideMidAll("yemek-listesi");
toggleItem("id", "yemek-listesi");
}
function toggleAnimations() {
hideMidAll("animations");
toggleItem("id", "animations");
}
// -----------------------------------------
// UTILITIES
//
function getDigits(str, num) {
return ("0" + str).slice(-num);
}
/**
*
* @param {...any} except
*/
function hideMidAll(...except) {
MidItems.forEach(element => {
if (!except.includes(element)) {
document.getElementById(element).style.display = "none";
}
});
}
/** type: id, class
*
* name: id or class name
*/
function toggleItem(type, name) {
switch (type) {
case "id":
let item = document.getElementById(name);
if (item.style.display == "flex") {
item.style.display = "none";
} else {
item.style.display = "flex";
}
break;
default:
console.error("no toggle item except ids!");
break;
}
}