-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
77 lines (67 loc) · 2.42 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function setCookie(name, value, days) {
const d = new Date();
d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000));
let expires = "expires=" + d.toUTCString();
document.cookie = name + "=" + encodeURIComponent(value) + ";" + expires + ";path=/";
}
function getCookie(name) {
let cookieArr = document.cookie.split(";");
for (let i = 0; i < cookieArr.length; i++) {
let cookiePair = cookieArr[i].split("=");
if (name == cookiePair[0].trim()) {
return decodeURIComponent(cookiePair[1]);
}
}
return null;
}
function deleteCookie(name) {
document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
}
let visitCount = getCookie("visitCount");
visitCount = visitCount ? parseInt(visitCount) : 0;
function updateCookieDisplay() {
document.getElementById("count").textContent = visitCount;
}
document.getElementById("saveInfo").addEventListener("click", function() {
let login = document.getElementById("login").value;
let password = document.getElementById("password").value;
if (login && password) {
setCookie("login", login, 365);
setCookie("password", password, 365);
alert("Informacje zapisane!");
} else {
alert("Proszę wprowadzić zarówno login, jak i hasło.");
}
});
document.getElementById("increase").addEventListener("click", function() {
visitCount++;
setCookie("visitCount", visitCount, 365);
updateCookieDisplay();
animateButton(this);
});
document.getElementById("decrease").addEventListener("click", function() {
if (visitCount > 0) {
visitCount--;
setCookie("visitCount", visitCount, 365);
}
updateCookieDisplay();
animateButton(this);
});
document.getElementById("show").addEventListener("click", function() {
let currentCookieValue = getCookie("visitCount");
let login = getCookie("login");
let password = getCookie("password");
if (login && password) {
alert("Odwiedziłeś stronę " + currentCookieValue + " razy.\nLogin: " + login + "\nHasło: " + password);
} else {
alert("Nie zapisano jeszcze informacji o użytkowniku.");
}
animateButton(this);
});
function animateButton(button) {
button.style.transform = "scale(1.2)";
setTimeout(function() {
button.style.transform = "scale(1)";
}, 200);
}
updateCookieDisplay();