164 lines
No EOL
3.5 KiB
JavaScript
164 lines
No EOL
3.5 KiB
JavaScript
// 2023 Aliberk Sandıkçı
|
||
|
||
// VARIABLES
|
||
var FlagSecond = 0;
|
||
var FlagSettings = 0;
|
||
var FlagTimers = 1;
|
||
var FlagExtras = 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");
|
||
}
|
||
|
||
|
||
function toggleExtra() {
|
||
let chx = document.getElementById("chx-closeExtra");
|
||
if (chx.checked) {
|
||
FlagExtras = 0;
|
||
} else {
|
||
FlagExtras = 1;
|
||
}
|
||
updateExtras();
|
||
|
||
}
|
||
|
||
// -----------------------------------------
|
||
// 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;
|
||
}
|
||
}
|
||
|
||
function updateExtras() {
|
||
var arr = document.getElementsByClassName("extraItem");
|
||
for (let i = 0; i < arr.length; i++) {
|
||
const element = arr[i];
|
||
if (FlagExtras) {
|
||
element.style.display = "inherit";
|
||
}
|
||
else {
|
||
element.style.display = "none";
|
||
}
|
||
}
|
||
} |