Repository navigation
Expand file tree
/
Copy pathinclude.js
More file actions
366 lines (340 loc) · 11.1 KB
/
Copy pathinclude.js
File metadata and controls
366 lines (340 loc) · 11.1 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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
function get_cookies() {
const n = "TVHadmin";
let ret;
if (ret = localStorage.getItem(n)) {
return JSON.parse(decodeURIComponent(ret));
}
try {
var b = document.cookie.match('(^|;)\\s*' + n + '\\s*=\\s*([^;]+)');
var c = b ? b.pop() : '';
localStorage.setItem(n, c);
return JSON.parse(decodeURIComponent(c));
}
catch {
var empty = {"Tag_All": "All", "Rec_All": "All", "Now_All": "All", "Tim_All": "All", "selected_channels": [],
"SORT": "1", "CSORT": "0", "TIMESPAN": "2", "EPGSTART": "0", "THEME": "0", "UUID": "None", "CLASHDET": "0"};
return empty;
}
}
var cookies = get_cookies();
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.onload = ()=>document.body.style.display = 'block';
if (cookies.THEME == 1) link.href = 'style.dark.css';
else if (cookies.THEME == 2) link.href = 'style.blue.css';
else link.href = 'style.css';
document.head.appendChild(link);
window.addEventListener('load',function() {
var mytop=document.getElementById("mobmenu");
mytop.addEventListener('click', function() {
var mynav=document.getElementById("navigation");
if (mynav.classList.contains('focus'))
mynav.classList.remove('focus');
else mynav.classList.add('focus');
});
const titles = [ "What's On Now", "Timeline", "Channels", "Favourite Channels", "Timers",
"Recordings", "Series Links", "Status", "Configuration" ];
const links = [ "now.html", "timeline.html", "channels.html", "favourites.html", "timers.html",
"recordings.html", "links.html", "status.html", "config.html" ];
let menu = document.getElementsByClassName("nav_bar");
for (let i = 0; i < titles.length; i++) {
let div = document.createElement("div");
div.className = "navi";
div.innerHTML = `<a href="${links[i]}">${titles[i]}</a>`;
menu[0].appendChild(div);
}
let div = document.createElement("div");
div.className = "navi";
div.innerHTML = "<form action='search.html' method='GET' name='search' class='search' onsubmit='return checkForm()'> \
<input type='text' name='find'><br> \
<input type='submit' name='submit' value='Search'> \
</form>";
menu[0].appendChild(div);
},false);
function checkForm() {
var x = document.forms["search"]["find"].value;
if (x == "") return false;
return true;
}
function create_by_event(event, event_id, element) {
event.preventDefault();
const profile_uuid = cookies.UUID;
fetch(`/api/dvr/entry/create_by_event?event_id=${event_id}&config_uuid=${profile_uuid}`).then(function(response) {
if (response.ok) {
const outer = element.parentNode;
outer.removeChild(outer.childNodes[0]);
const a = document.createElement("a");
a.title = "Remove scheduled recording";
a.href = "channels.html"
a.onclick = event => {delete_new_event(event, event_id, outer)};
const img = document.createElement("img");
img.src = "images/rec.png";
a.appendChild(img);
outer.appendChild(a);
}
});
}
function create_by_series(event, event_id, element) {
event.preventDefault();
const profile_uuid = cookies.UUID;
fetch(`/api/dvr/autorec/create_by_series?event_id=${event_id}&config_uuid=${profile_uuid}`).then(function(response) {
if (response.ok) {
const outer = element.parentNode;
outer.removeChild(outer.childNodes[0]);
outer.previousSibling.removeChild(outer.previousSibling.childNodes[0]);
const a = document.createElement("a");
a.title = "Remove series link";
a.href = "channels.html"
a.onclick = event => {delete_new_series(event, event_id, outer)};
const img = document.createElement("img");
img.src = "images/rec.png";
a.appendChild(img);
outer.appendChild(a);
}
});
}
function delete_by_event(event, title, uuid, element) {
event.preventDefault();
if (confirm(`Delete timer "${title}"?`)) {
fetch(`/api/dvr/entry/cancel?uuid=${uuid}`).then(function(response) {
if (response.ok) {
let outer = element.parentNode;
outer.removeChild(outer.childNodes[0]);
let a = document.createElement("a");
a.title = "Record";
a.href = "channels.html"
let img = document.createElement("img");
img.src = "images/rec_button1.png";
a.appendChild(img);
outer.appendChild(a);
}
});
}
}
function delete_by_series(event, title, uuid, element) {
event.preventDefault();
if (confirm(`Delete series link "${title}"?`)) {
fetch(`/api/idnode/delete?uuid=${uuid}`).then(function(response) {
if (response.ok) {
var outer = element.parentNode;
outer.removeChild(outer.childNodes[0]);
var img = document.createElement("img");
img.src = "images/rec_buttonS.png";
outer.appendChild(img);
}
});
}
}
async function delete_new_event(event, event_id, outer) {
event.preventDefault();
let entry = await get_timer_by_id(event_id);
let uuid = entry.uuid;
let title = htmlspecialchars(entry.disp_title);
if (confirm(`Delete timer "${title}"?`)) {
await fetch(`/api/dvr/entry/cancel?uuid=${uuid}`).then(function(response) {
if (response.ok) {
outer.removeChild(outer.childNodes[0]);
const a = document.createElement("a");
a.title = "Record";
a.href = "channels.html"
const img = document.createElement("img");
img.src = "images/rec_button1.png";
a.appendChild(img);
outer.appendChild(a);
}
});
}
}
async function delete_new_series(event, event_id, outer) {
event.preventDefault();
let entry = await get_timer_by_id(event_id);
let autorec = entry.autorec;
let title = htmlspecialchars(entry.autorec_caption);
if (confirm(`Delete series link "${title}"?`)) {
fetch(`/api/idnode/delete?uuid=${autorec}`).then(function(response) {
if (response.ok) {
outer.removeChild(outer.childNodes[0]);
let a = document.createElement("a");
a.title = "Record series";
a.href = "channels.html"
let img = document.createElement("img");
img.src = "images/rec_buttonS.png";
a.appendChild(img);
outer.appendChild(a);
a = document.createElement("a");
a.title = "Record";
img = document.createElement("img");
img.src = "images/rec_button1.png";
a.appendChild(img);
outer.previousSibling.appendChild(a);
}
});
}
}
async function get_timer_by_id(id) {
let url = "/api/dvr/entry/grid_upcoming?limit=1";
const filter = `[{"field":"broadcast","type":"numeric","value":"${id}","comparison":"eq"}]`;
url += `&filter=${filter}`;
const response = await fetch(url);
const timers = await response.json();
return timers.entries[0];
}
async function get_epg(channel, start, to) {
var url = "/api/epg/events/grid?limit=9999";
if (to > 0) {
const filter = `[{"field":"stop","type":"numeric","value":"${start}","comparison":"gt"},{"field":"start","type":"numeric","value":"${to}","comparison":"lt"}]`;
url += `&filter=${filter}`;
}
if (channel) {
const prog = encodeURIComponent(channel);
url += `&channel=${prog}`;
}
const response = await fetch(url);
const epg = await response.json();
return epg.entries;
}
async function get_epg_now(channel) {
var url = "/api/epg/events/grid?mode=now&limit=9999";
if (channel) {
const prog = encodeURIComponent(channel);
url += `&channel=${prog}`;
}
const response = await fetch(url);
const epg = await response.json();
return epg.entries;
}
async function search_epg(channel, needle) {
const reg = encodeURIComponent(escapeRegExp(needle));
const url = `/api/epg/events/grid?limit=9999&title=${reg}`;
if (channel != "") {
const prog = encodeURIComponent(channel);
url += `&channel=${prog}`;
}
const response = await fetch(url);
const epg = await response.json();
return epg.entries;
}
async function get_timers() {
const response = await fetch("/api/dvr/entry/grid_upcoming?sort=start");
const timers = await response.json();
return timers.entries;
}
async function get_profiles() {
const response = await fetch("/api/dvr/config/grid");
const profiles = await response.json();
return profiles.entries;
}
async function get_channeltags() {
const response = await fetch("/api/channeltag/list");
const tags = await response.json();
let ret = {"All":"All"};
tags.entries.forEach(function(tag) {
ret[tag.val] = tag.key;
});
return ret;
}
async function get_links() {
const response = await fetch("/api/dvr/autorec/grid");
const json = await response.json();
const links = json.entries;
links.sort(function(a, b) {
return sort_title(a.title, b.title);
});
return links;
}
async function get_recordings(sort) {
const response = await fetch("/api/dvr/entry/grid?limit=9999");
const json = await response.json();
const recordings = json.entries;
switch(sort) {
case "0":
recordings.sort(function(a, b) {
return (a.start - b.start);
});
break;
case "1":
recordings.sort(function(a, b) {
return (b.start - a.start);
});
break;
case "2":
recordings.sort(function(a, b) {
var ret = sort_title(a.disp_title, b.disp_title);
if (ret == 0) return (a.start - b.start);
return ret;
});
}
return recordings;
}
async function get_channels(sort) {
const response = await fetch("/api/channel/grid?limit=9999");
const json = await response.json();
const channels = json.entries;
if (sort == 0) {
channels.sort(strcasecmp);
}
else {
channels.sort(function(a,b) {
let ret = a.number - b.number;
if (ret == 0) return strcasecmp(a,b);
else return ret;
});
}
return channels;
}
function sort_title(x, y) {
if (!x || !y) return 0;
if (x.startsWith('New:')) {
if (x[4] == ' ') x = x.substring(5);
else x = x.substring(4);
}
if (y.startsWith('New:')) {
if (y[4] == ' ') y = y.substring(5);
else y = y.substring(4);
}
if (x.endsWith('...')) {
x = x.substring(0, x.length - 3);
}
if (y.endsWith('...')) {
y = y.substring(0, y.length - 3);
}
let n = Math.min(x.length, y.length);
return strncmp(x, y, n);
}
function strcasecmp(a, b) {
let s1 = (a.name + '').toLowerCase();
let s2 = (b.name + '').toLowerCase();
if (s1 > s2) return 1;
else if (s1 === s2) return 0;
return -1;
}
function strncmp(str1, str2, n) {
str1 = str1.substring(0, n);
str2 = str2.substring(0, n);
return ( ( str1 == str2 ) ? 0 : (( str1 > str2 ) ? 1 : -1 ));
}
function intersect(tags, media) {
for (var t in tags) {
if (media[tags[t]]) return 1;
}
return 0;
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
function escapeRegExp(string) {
return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
// https://stackoverflow.com/questions/1787322/what-is-the-htmlspecialchars-equivalent-in-javascript
function htmlspecialchars(string) {
if (string === undefined) return "";
return string.replace(/([&<>"']|\n)/g, function(m) { return specialchars[m]; });
};
// A collection of special characters and their entities.
var specialchars = {
'&': '&' ,
'<': '<' ,
'>': '>' ,
'"': '"' ,
"'": ''' ,
'\n': ' '
};