-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (46 loc) · 1.31 KB
/
index.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
function createCookie(name, value, days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
else {
expires = "";
}
document.cookie = name + "=" + value + expires + "; path=/";
}
function getCookie(c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=");
if (c_start != -1) {
c_start = c_start + c_name.length + 1;
c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1) {
c_end = document.cookie.length;
}
return unescape(document.cookie.substring(c_start, c_end));
}
}
return "";
}
window.onload = function() {
var COOKIE_NAME = 'visited';
var visited = getCookie(COOKIE_NAME).split(',');
function upgradeLink(link) {
var slug = link.parentNode.getAttribute('href').replace(/[\.\/]/g, '');
if (visited.indexOf(slug) !== -1) {
link.className = 'visited';
}
link.parentNode.onclick = function(evt) {
createCookie(COOKIE_NAME, visited.concat([ slug ]).join(','));
};
}
var links = document.getElementsByTagName('li');
for (var i=0; i<links.length; ++i) {
var link = links[i];
if (link.parentNode.tagName === 'A') {
upgradeLink(link);
}
}
};