Last active
October 5, 2015 01:08
-
-
Save gaomd/2729316 to your computer and use it in GitHub Desktop.
make anchor by week day
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
<a href="#" id="goto">Link</a> | |
<script> | |
/* For http://www.v2ex.com/t/36493 | |
* DEMO: http://jsfiddle.net/gaomd/asD58/3/ | |
* by Mengdi Gao 2012 | |
* Dedicated to the public domain | |
*/ | |
(function(doc) { | |
"use strict"; | |
var a = doc.getElementById("goto"); | |
var d = new Date(); | |
var day = d.getDay(); | |
var hr = d.getHours(); | |
var pre = "http://www.example.com/"; | |
var page = ""; | |
var post = ".html"; | |
var getDayPostfix = function(hr) { | |
var name = ""; | |
if (8 <= hr && hr < 12) { | |
name = "morning"; | |
} else if (12 <= hr && hr < 14) { | |
name = "noon"; | |
} else if (14 <= hr && hr < 18) { | |
name = "afternoon"; | |
} else if (18 <= hr && hr < 23) { | |
name = "evening"; | |
} else { | |
name = "night"; | |
} | |
return name; | |
}; | |
var map = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]; | |
// 0 for sunday and 1 for monday and so forth. | |
if (d === 0) { | |
page = "weekend"; | |
} else { | |
page = map[day] + "_" + getDayPostfix(hr); | |
} | |
a.href = pre + page + post; | |
})(document); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment