-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
60 lines (48 loc) · 2.14 KB
/
script.js
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
(function () {
"use strict";
function updateTime() {
ui.info.setTimeAndDate(new Date());
}
updateTime();
setInterval(updateTime, 15000);
function updateWeather() {
util.httpReq("GET", "forecast.json", function (status, response) { // Insert your DarkSky proxy here
if (status === 200) {
var data = JSON.parse(response);
ui.weather.fromDarkSkyObject(data.currently);
var day = data.daily.data[0];
ui.weather.setTemperatureMin(day.temperatureMin);
ui.weather.setTemperatureMax(day.temperatureMax);
}
});
}
updateWeather();
if (!util.isKindle()) { /* Ensure responsiveness™ */
var style = document.createElement("style");
style.appendChild(document.createTextNode("html, body {width: 100%; height: 100%; overflow: initial;}"));
document.head.appendChild(style);
}
var refButton = ui.buttons.createButton("refresh", "Refresh", function () {
window.location.reload();
});
var refBlock = ui.blocks.createBlock("Refresh page", [refButton]);
var lightToggle = ui.buttons.createToggleButton("toggleTest", function (e, value) {
// Do web request here
});
var lightSlider = ui.sliders.createSlider("sliderTest", function(e) {
ui.info.setInfoText(e.target.value);
}, 0, 200, 50);
var lightBlock = ui.blocks.createBlock("Light", [lightToggle]);
var lightBlock2 = ui.blocks.createBlock("", [lightSlider]);
var weatherUpdateButton = ui.buttons.createButton("updateWeather", "Refresh", function () {
updateWeather();
});
var weatherBlock = ui.blocks.createBlock("Update Weather", [weatherUpdateButton]);
var kindleInfo = document.createElement("p");
kindleInfo.appendChild(document.createTextNode("Kindle: " + util.isKindle()));
var kindleInfoBlock = ui.blocks.createBlock("Responsiveness", [kindleInfo]);
ui.blocks.addColumn([refBlock, lightBlock, lightBlock2]);
ui.blocks.addColumn([weatherBlock, kindleInfoBlock]);
ui.blocks.display(); // Update / show blocks
ui.info.setInfoText("");
}());