-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
201 lines (196 loc) · 5.94 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kindle Dashboard</title>
<style type="text/css">
body {
position: relative;
margin: 0 auto;
padding: 0;
max-width: 1072px;
}
a {
color: #000;
text-decoration: none;
}
img {
max-width: 100%;
}
#time {
margin: 0;
padding: 0 10px;
border-bottom: 1px solid #000;
font-size: 6em;
line-height: 1;
}
#time span {
float: right;
margin: 10px 0;
font-size: 0.4em;
text-align: right;
}
p {
margin: 5px 0;
}
#todo {
width: 98%;
height: 85px;
padding-left: 10px;
border: none;
border-bottom: 1px solid #000;
}
#news {
min-height: 90px;
padding-left: 10px;
border-bottom: 1px solid #000;
}
#airly {
min-height: 30px;
text-align: center;
border-bottom: 1px solid #000;
}
#history, #forecast {
margin: 5px 0 0;
vertical-align: middle;
}
#weather {
text-align: center;
overflow-y: hidden;
}
#meteo {
margin-top: -30px;
-webkit-filter: grayscale(100%) contrast(1.2);
filter: grayscale(100%) contrast(1.2);
}
#preview {
display: none;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: 10px;
background-color: #fff;
font-size: 1.25em;
}
#preview:target {
display: block;
}
#close {
position: absolute;
top: 0;
right: 0;
padding: 0 10px;
font-size: 2em;
}
@media (min-width: 601px) {
#todo {
float: right;
width: 36%;
border-left: 1px solid #000;
}
}
</style>
</head>
<body>
<h1 id="time"></h1>
<textarea id="todo"></textarea>
<div id="news"></div>
<div id="airly"></div>
<div id="weather"><img id="meteo" src="" alt=""></div>
<div id="preview"><a id="close" href="#">×</a><div id="article"></div></div>
<script type="text/javascript">
// Clock
var airlyHours = [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]; // when to fetch air quality
var meteoHours = [6, 12, 18]; // when to fetch forecast/news
var offset = 10; // offset in minutes
var days = ['niedziela', 'poniedziałek', 'wtorek', 'środa', 'czwartek', 'piątek', 'sobota'];
var months = ['stycznia', 'lutego', 'marca', 'kwietnia', 'maja', 'czerwca', 'lipca', 'sierpnia', 'września', 'października', 'listopada', 'grudnia'];
function tick() {
var today = new Date();
var mo = months[today.getMonth()];
var d = today.getDate();
var dw = days[today.getDay()];
var h = today.getHours();
var m = today.getMinutes();
document.getElementById('time').innerHTML = h + ':' + (m < 10 ? '0' : '') + m + ' <span>' + dw + '<br>' + d + '. ' + mo + '</span>';
if (m == offset) {
if (airlyHours.indexOf(h) > -1)
fetchAirly();
if (meteoHours.indexOf(h) > -1) {
fetchNews();
fetchMeteo();
}
}
}
tick();
setInterval(tick, 60*1000);
// To-Do
var todo = document.getElementById('todo');
todo.value = decodeURIComponent((document.cookie.match(/(^|;)\s*todo\s*=\s*([^;]+)/) || []).pop() || '');
todo.onchange = function () {
var d = new Date();
d.setTime(d.getTime() + (365*24*60*60*1000));
document.cookie = 'todo=' + encodeURIComponent(this.value) + '; expires=' + d.toUTCString() + '; samesite=strict';
};
// Google News
var newsUrl = 'rss/proxy.php?url=https%3A%2F%2Fnews.google.com%2Frss%3Fhl%3Dpl%26gl%3DPL%26ceid%3DPL%3Apl';
var news = document.getElementById('news');
var article = document.getElementById('article');
var items;
function getTitle(i) {
var title = items[i].getElementsByTagName('title')[0];
return title.textContent.substring(0, title.textContent.lastIndexOf('-') - 1).replace(' - Wiadomości', '');
}
function getDescription(i) {
return items[i].getElementsByTagName('description')[0].textContent.replace(/<img[^>]+>/gi, '');
}
function showPreview(i) {
article.innerHTML = '<h2>' + getTitle(i) + '</h2>' + getDescription(i);
}
function fetchNews() {
var xhr = new XMLHttpRequest();
xhr.open('GET', newsUrl);
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var html = '';
var xml = this.responseXML;
items = xml.getElementsByTagName('item');
for (var i = 0; i < items.length; i++) {
html += '<p><a href="#preview" onclick="showPreview(' + i + ')">' + getTitle(i) + '</a></p>';
}
news.innerHTML = html;
}
};
xhr.send();
}
fetchNews();
// Airly
var airlyUrl = 'proxy.php?type=airly';
function sparkline(a,f,m,b,g) {var c=document.getElementById(a);a=c.getContext("2d");b=b||"#000";g=g||"line";var d=c.height-3,l=c.width;c=f.length;var k=Math.max.apply(Math,f),n=l/c;k/=d;var e=0,h=d-f[0]/k;a.clearRect(0,0,l,d);a.beginPath();a.strokeStyle=b;a.moveTo(e,h);for(b=1;b<c;b+=1)e+=n,h=d-f[b]/k+2,"bar"==g&&a.moveTo(e,d),a.lineTo(e,h);a.stroke();m&&"line"==g&&(a.beginPath(),a.fillStyle="#000",a.arc(e,h,3,0,2*Math.PI),a.fill())}
function fetchAirly() {
var xhr = new XMLHttpRequest();
xhr.open('GET', airlyUrl);
xhr.setRequestHeader('Accept', 'application/json');
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var json = eval('(' + this.responseText + ')');
document.getElementById('airly').innerHTML = '<canvas id="history" width="100" height="25"></canvas><canvas id="forecast" width="100" height="25"></canvas> CAQI: ' + Math.round(json.current.indexes[0].value) + ', PM10: ' + Math.round(json.current.values[2].value) + 'µg/m³, wilg: ' + Math.round(json.current.values[4].value) + '%, temp: ' + Math.round(json.current.values[5].value) + '°C';
sparkline('history', json.history.map(function (m) { return m.indexes[0].value; }), true);
sparkline('forecast', json.forecast.map(function (m) { return m.indexes[0].value; }), false, '#aaa');
}
};
xhr.send();
}
fetchAirly();
// Meteo
var meteoUrl = 'http://www.meteo.pl/um/metco/mgram_pict.php?ntype=0n&row=466&col=232&lang=pl&date=';
function fetchMeteo() {
document.getElementById('meteo').src = meteoUrl + new Date().getTime();
}
fetchMeteo();
</script>
</body>
</html>