-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
114 lines (101 loc) · 4.33 KB
/
index.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cookies!</title>
<style>
.cookieBody {
background-color: black;
text-align: center;
}
.cookieText {
color: white;
font-size: 32px;
}
.cookieButton {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 25px;
text-align: center;
font-size: 32px;
cursor: pointer;
}
.cookieButton:hover {
background-color: green;
}
.cookieImpressum {
color: grey;
font-size: 10px;
margin-top: 1cm;
}
</style>
</head>
<body class="cookieBody">
<p id="mainText" class="cookieText">This page requires Javascript.</p>
<button id="cookieButton" class="cookieButton">This button requires Javascript</button>
<p class="cookieImpressum">Impressum: Tobias Borgert, Sonnenbergstr. 44, 88045 Friedrichshafen, Telefon +49 175 9741856</p>
<script>
function eatCookie() {
setCookie("cookie_type", "", 0);
document.getElementById("mainText").innerHTML = "You have eaten your cookie. Reload the page to get a new one.";
document.getElementById("cookieButton").hidden = true;
}
function setCookie(cname, cvalue, exdays) {
let d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
const expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
const name = cname + "=";
const ca = document.cookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function checkCookie() {
const cookie_types = ["a traditional spicy Christmas",
"a half-baked dark chocolate",
"a half-baked white chocolate",
"a half-baked hazelnut",
"a crispy chocolate",
"a shortbread",
"a shortbread with chocolate coating",
"a soft cake with orange filling",
"a soft cake with cherry filling",
"an Oreo"];
let cookie_type = getCookie("cookie_type");
if (cookie_type != "") {
document.getElementById("mainText").innerHTML = "You already have " + cookie_type + " cookie!";
document.getElementById("cookieButton").innerHTML = "Eat cookie";
document.getElementById("cookieButton").onclick = eatCookie;
} else {
cookie_type = cookie_types[Math.floor(Math.random() * 10)];
if (cookie_type != "" && cookie_type != null) {
document.getElementById("mainText").innerHTML = "Please confirm the cookie!";
document.getElementById("cookieButton").innerHTML = "This is not the confirmation button";
if(confirm("This page will give you a cookie. The cookie is not used for aynthing, it is just for you. Accept the cookie?")) {
setCookie("cookie_type", cookie_type, 1);
document.getElementById("mainText").innerHTML = "You now have " + cookie_type + " cookie!";
document.getElementById("cookieButton").innerHTML = "Eat cookie";
document.getElementById("cookieButton").onclick = eatCookie;
}
else {
document.getElementById("mainText").innerHTML = "You refused the cookie. Reload the page if you change your mind.";
document.getElementById("cookieButton").hidden = true;
}
}
}
}
window.onload = checkCookie;
</script>
</body>
</html>