-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
107 lines (83 loc) · 3.52 KB
/
Copy pathscript.js
File metadata and controls
107 lines (83 loc) · 3.52 KB
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
function fillOptions(elementID, nadArray, subElementID) {
optionsArray = Object.keys(nadArray);
var select = document.getElementById(elementID);
select.innerHTML = "";
for (var i = 0; i < optionsArray.length; i++) {
var opt = optionsArray[i];
select.innerHTML += "<option value=\"" + opt + "\">" + opt + "</option>";
}
fillSuboption(nadArray[optionsArray[0]], subElementID)
};
function fillSuboption(subArray, subElementID) {
var select = document.getElementById(subElementID);
select.innerHTML = "";
for (var i = 0; i < subArray.length; i++) {
var opt = subArray[i];
select.innerHTML += "<option value=\"" + opt + "\">" + opt + "</option>";
}
}
function selectImage() {
var network = document.getElementById("network").value;
var station = document.getElementById("station").value;
var day = document.getElementById("day").value;
var month = document.getElementById("month").value;
var year = document.getElementById("year").value;
var imagePath = "./" + year + "/" + network + "/" + station + "/" + month + "/" + day + ".png";
//var imagePath = "./" + year + "/" + month + "/" + day + "/" + station + ".spec.png";
var image = document.getElementById("selectedImage");
var noImageText = document.getElementById("noImageText");
image.src = imagePath;
/*
image.onerror = function () {
image.style.display = "none";
noImageText.style.display = "block";
};
image.style.display = "block";
noImageText.style.display = "none"; */
document.date.setUTCFullYear(Number(document.getElementById("year").value))
document.date.setUTCMonth(Number(document.getElementById("month").value) - 1)
document.date.setUTCDate(Number(document.getElementById("day").value))
}
function handleKeyPress(event) {
if (event.keyCode === 37) { // Left arrow key
update(-1); // Move to the previous day
selectImage();
} else if (event.keyCode === 39) { // Right arrow key
update(1); // Move to the next day
selectImage();
} else if (event.keyCode === 38) { // Up arrow key
changeChannel(-1); // Move to the previous station
selectImage();
} else if (event.keyCode === 40) { // Down arrow key
changeChannel(1); // Move to the next station
selectImage();
}
}
function changeChannel(direction) {
var channelSelect = document.getElementById("station");
var selectedIndex = channelSelect.selectedIndex;
var newIndex = selectedIndex + direction;
var optionsCount = channelSelect.options.length;
if (newIndex < 0) {
newIndex = optionsCount - 1; // Wrap to the last option
} else if (newIndex >= optionsCount) {
newIndex = 0; // Wrap to the first option
}
channelSelect.selectedIndex = newIndex;
currentChannel = channelSelect.value;
document.getElementById("station").value = currentChannel
}
function update(toadd) {
document.date.setDate(document.date.getUTCDate() + toadd);
document.getElementById("day").value = String(document.date.getUTCDate());
document.getElementById("month").value = String(document.date.getUTCMonth() + 1);
document.getElementById("year").value = String(document.date.getUTCFullYear());
}
function setDefaultImage() {
document.date = new Date();
update(-1);
fillOptions("network", networks, 'station');
selectImage(); // Select default image
}
document.addEventListener('keydown', handleKeyPress);
window.onload = setDefaultImage;