-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_service.js
54 lines (48 loc) · 1.8 KB
/
config_service.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
/* Tell the JS Helper to load the config */
window.Twitch.ext.configuration.onChanged(() => {
loadSegment('global');
loadSegment('broadcaster');
loadSegment('developer');
});
function loadSegment(segment) {
let el = document.getElementById('config_' + segment);
let elr = document.getElementById('config_' + segment + '_raw');
if (window.Twitch.ext.configuration[segment]) {
if (window.Twitch.ext.configuration[segment].content) {
let this_config = '';
try {
this_config = JSON.parse(window.Twitch.ext.configuration[segment].content);
} catch (e) {
console.log('Config', segment, e);
el.textContent = 'Failed to parse JSON';
return;
}
let textarea = document.createElement('textarea');
elr.textContent = '';
elr.append(textarea);
textarea.setAttribute('readonly', 'readonly');
textarea.value = window.Twitch.ext.configuration[segment].content;
let table = document.createElement('table');
el.textContent = '';
el.append(table);
for (var k in this_config) {
let r = document.createElement('tr');
table.append(r);
let d = document.createElement('td');
r.append(d);
d.textContent = k;
let v = document.createElement('td');
r.append(v);
if (typeof this_config[k] != 'string') {
v.textContent = JSON.stringify(k);
} else {
v.textContent = k;
}
}
} else {
el.textContent = 'No Config Content';
}
} else {
el.textContent = 'No Config';
}
}