-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
55 lines (47 loc) · 1.26 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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Snake</title>
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
<link href="public/app.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="app"></div>
<script src="public/app.js" ></script>
<script>
var app = Elm.Main.init({
node: document.getElementById("app")
});
var cookieName = 'highscore';
function storeHighscoreInCookie(highscore) {
document.cookie = cookieName + "=" + highscore;
}
// store high score in cookie (elm to js)
app.ports.saveHighscore.subscribe(function(highscore) {
storeHighscoreInCookie(highscore);
});
function loadCookie (name) {
var dc = document.cookie;
var cname = name + "=";
var end, begin = null;
if (dc.length > 0) {
begin = dc.indexOf(cname);
if (begin !== -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end === -1) {
end = dc.length;
}
console.log(decodeURI(dc.substring(begin, end)))
return decodeURI(dc.substring(begin, end));
}
}
return "";
};
var highscore = loadCookie(cookieName);
// send stored high score to elm
app.ports.loadHighscore.send(highscore)
</script>
</body>
</html>