-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
83 lines (70 loc) · 2.34 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
Future remainder !
<div id="dateSetter" style="visibility: collapse">
<input type="date" id="dateInput">
<button type="button" id="buttonSetDate">SetDate !</button>
</div>
<div>
<button type="button" id="buttonClear">clear</button>
</div>
target date is : <label id="displayedValue">no date set</label>
<div id="remainder">
to set
</div> <label>days to go !</label>
<script>
document.getElementById("buttonSetDate").onclick = function f(){
setCookie("expectedDate",document.getElementById("dateInput").value,150);
alert("value set !");
document.location.reload();
}
document.getElementById("buttonClear").onclick = function f(){
deleteCookie("expectedDate");
alert("clear");
document.location.reload();
}
var dateCookies = document.cookie;
var cookie = getCookie("expectedDate");
if(cookie !== ""){
console.log(cookie);
document.getElementById("displayedValue").innerHTML = cookie.valueOf();
var diff = new Date(cookie.valueOf()).getTime() - Date.now();
var days = diff/1000/60/60/24;
document.getElementById("remainder").innerHTML = Math.trunc(days).toString();
}else{
document.getElementById("dateSetter").setAttribute("style","visibility: visible");
}
console.log(dateCookies);
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function deleteCookie(cname){
document.cookie = cname+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
}
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.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 "";
}
</script>
</body>
</html>