-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
132 lines (119 loc) · 5.86 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<html>
<head>
<title>What day of the week is today</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,800&subset=latin,cyrillic,greek,vietnamese' rel='stylesheet' type='text/css'>
<link href='style.css' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="jquery.cookie.js"></script>
<script type="text/javascript">
var langFile = {"weekdays": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], "or": "or", "nativeName": "English", "name": "English", "languageCode": "en", "today": "Today is"};
var userLang = ((navigator.language) ? navigator.language : navigator.userLanguage).substring(0, 2);
var day = (new Date()).getDay();
var geoDay = day;
jQuery(document).ajaxError(function(event, request, settings){
console.log("Ajax error for request " + request + ", event " + event);
});
$(document).ready(function() {
refresh(); //display any language
if($.cookie("lang") != undefined) { //detect if there are user settings stored
userLang = $.cookie("lang");
console.log("go ya' cookie :) you want " + userLang);
}
populateLangSelection(); //load available languages
loadLanguage(); //load desired language
detectGeoDay(); //check for time difference
});
function loadLanguage() {
console.log("loading language file " + userLang);
$.getJSON('languages/' + userLang + '.json',
function(data) {
if(data != null) {
langFile = data;
console.log("loaded language file: " + langFile);
} else {
console.log("language file is empty. Using fallback");
userLang = userLang + 'unsupported';
}
refresh();
}
);
}
function detectGeoDay() {
jQuery.getScript('http://www.geoplugin.net/javascript.gp', function()
{
var lon = geoplugin_longitude();
var lat = geoplugin_latitude();
var USER = "toebbel";
console.log("Your location is: " + lon + ", " + lat);
$.getJSON("http://api.geonames.org/timezoneJSON?lat=" + lat + "&lng=" + lon + "&username=" + USER,
function(data) {
if(data != null && data != undefined) {
console.log("received timezone data: " + data);
geoDay = (new Date(data.time)).getDay();
if (!isFinite(geoDay)) {
geoDay = day; //fallback
}
refresh();
} else {
console.log("timezone data is empty.");
}
});
});
}
function refresh() {
var dsp = langFile.weekdays[day];
if(geoDay != day)
dsp += " " + langFile.or + " " + langFile.weekdays[geoDay];
$("#dotw").text(dsp);
$("h1").text(langFile.today);
}
function populateLangSelection() {
$.getJSON('languages/list.json',
function(data) {
if(data == null) {
console.log("could not load language list");
$("#langSelection").hide();
} else {
console.log("got language list");
var list = $("#langSelection");
var option = "";
for (var i = 0; i < data.length; i++) {
if(data[i].languageCode == userLang)
option = " selected ";
else
option = "";
list.append('<option value="' + data[i].languageCode + '"' + option + '>' + data[i].nativeName + ' / ' + data[i].name + '</option>');
}
$("#langSelect").show();
}});
}
function updateLang() {
userLang = $("#langSelection").val();
console.log("You've selected " + userLang);
$.cookie("lang", userLang, { expires: 365, path: '/' , raw: true});
loadLanguage();
}
</script>
</head>
<body>
<div id="container">
<h1>Today is</h1>
<div id="dotw"></div>
</div>
<div id="langSelect" style="display: none">
<select onchange="updateLang()" id="langSelection">
</select> | <a href="https://github.com/toebbel/wdotwiit/blob/master/README.md">wtf?</a>
</div>
</body>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-53556302-1', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
</html>