Last active
August 29, 2015 14:23
-
-
Save jackwillis/f32a037a9ea98c5b09ff to your computer and use it in GitHub Desktop.
redirect.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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Time-based Redirect</title> | |
<script> | |
var pageTimes = [ | |
{ begin: "7:30 AM", end: "8:00 AM", href: "http://dfgsdfs" }, | |
{ begin: "8:00 AM", end: "12:00 PM", href: "http://tdddfgdfgdfgs" }, | |
{ begin: "12:00 PM", end: "2:00 PM", href: "http://ertertertertret" } | |
]; | |
var fallback = "http://dsfkhsdfk"; | |
/////////////////////////////////////////////////////////////////////////////// | |
document.addEventListener("DOMContentLoaded", function() { | |
function todayAtTime(timeString) { | |
return new Date(new Date().toDateString() + " " + timeString); | |
} | |
var now = new Date(); | |
var pageTime = pageTimes.find(function(pt) { | |
return todayAtTime(pt.begin) <= now && now < todayAtTime(pt.end); | |
}); | |
var url = pageTime ? pageTime.href : fallback; | |
document.getElementById("where").innerHTML = url; | |
window.location.href = url; | |
}); | |
</script> | |
</head> | |
<body> | |
<p>Redirecting you to <span id="where"></span>...</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment