forked from toebbel/wdotwiit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
135 lines (122 loc) · 5.93 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
132
133
134
<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'>
<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>
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://0xabc.de/analytics/";
_paq.push(["setTrackerUrl", u+"piwik.php"]);
_paq.push(["setSiteId", "3"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Piwik Code -->
</html>