Skip to content

Instantly share code, notes, and snippets.

@BrandonClapp
Last active August 29, 2015 14:18
Show Gist options
  • Save BrandonClapp/78c6f8e3ffaf7bdc9896 to your computer and use it in GitHub Desktop.
Save BrandonClapp/78c6f8e3ffaf7bdc9896 to your computer and use it in GitHub Desktop.
Random Homepage
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<script src="redirect.js"></script>
</head>
<body>
<div>Blah</div>
</body>
</html>
(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