Last active
August 29, 2015 14:18
-
-
Save BrandonClapp/78c6f8e3ffaf7bdc9896 to your computer and use it in GitHub Desktop.
Random Homepage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Home</title> | |
<script src="redirect.js"></script> | |
</head> | |
<body> | |
<div>Blah</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
'use strict'; | |
function createCookie(name,value,days) { | |
if (days) { | |
var date = new Date(); | |
date.setTime(date.getTime()+(days*24*60*60*1000)); | |
var expires = "; expires="+date.toGMTString(); | |
} | |
else var expires = ""; | |
document.cookie = name+"="+value+expires+"; path=/"; | |
} | |
function readCookie(name) { | |
var nameEQ = name + "="; | |
var ca = document.cookie.split(';'); | |
for(var i=0;i < ca.length;i++) { | |
var c = ca[i]; | |
while (c.charAt(0)==' ') c = c.substring(1,c.length); | |
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); | |
} | |
return null; | |
} | |
function eraseCookie(name) { | |
createCookie(name,"",-1); | |
} | |
var pages = [ | |
'https://www.ted.com/talks', | |
'http://www.technologyreview.com/', | |
'https://hbr.org/' | |
]; | |
var current = readCookie('homepage'); | |
if(current === null){ | |
createCookie('homepage', 1, 7); | |
window.location.relplace(pages[0]); | |
} else { | |
if(parseInt(current) >= pages.length){ | |
current = 0; | |
createCookie('homepage', 1, 7); | |
} else { | |
createCookie('homepage', parseInt(current) + 1, 7); | |
} | |
window.location.replace(pages[current]); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment