Skip to content

Instantly share code, notes, and snippets.

@jackwillis
Last active August 29, 2015 14:23
Show Gist options
  • Save jackwillis/f32a037a9ea98c5b09ff to your computer and use it in GitHub Desktop.
Save jackwillis/f32a037a9ea98c5b09ff to your computer and use it in GitHub Desktop.
redirect.html
<!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