You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
function init() {
|
|
// načtení a zobrazení jména
|
|
const savedName = localStorage.getItem("userName")
|
|
if (savedName) {
|
|
document.getElementById("welcomeText").innerText = "Vítej zpět, " + savedName + "!";
|
|
document.getElementById("nameInput").value = savedName
|
|
}
|
|
|
|
//počítadlo návštěv
|
|
let visits = localStorage.getItem("visitCount")
|
|
if (visits == null) {
|
|
//pokud uživatel je tu poprvé
|
|
visits = 1;
|
|
} else {
|
|
//pokud už tu byl
|
|
visits = parseInt(visits) + 1
|
|
}
|
|
//ukladání do localstorage
|
|
localStorage.setItem("visitCount",visits);
|
|
//zobrazíme
|
|
document.getElementById("visitCounter").innerText = "Byl jsi tu " + visits + "x";
|
|
|
|
}
|
|
|
|
function saveName() {
|
|
const input = document.getElementById("nameInput");
|
|
const name = input.value;
|
|
|
|
if (name.trim() !== ""){
|
|
//uložíme do localStorage pod klíčem "userName"
|
|
localStorage.setItem("userName",name);
|
|
document.getElementById("welcomeText").innerText = "Vítej zpět, " + name + "!";
|
|
alert("Jméno uloženo");
|
|
} else {
|
|
alert("Zadej prosím nějaké jméno.");
|
|
}
|
|
}
|
|
|
|
function clearData() {
|
|
if (confirm("Opravdu chceš smazat všechna svá nastavení?")){
|
|
localStorage.clear();
|
|
location.reload();
|
|
}
|
|
}
|
|
|
|
window.onload = init;
|