forked from scrollback/scrollback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomization-client.es6
50 lines (36 loc) · 1.32 KB
/
customization-client.es6
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
/* eslint-env browser */
"use strict";
module.exports = (core, config, store) => {
let customStyle = {
removeCss: function() {
let styleSheet = document.getElementById("scrollback-custom-css");
if (styleSheet && document.head.contains(styleSheet)) {
document.head.removeChild(styleSheet);
}
},
applyCss: function() {
this.removeCss();
let roomObj = store.getRoom();
if (!(roomObj && roomObj.guides && roomObj.guides.customization && roomObj.guides.customization.css)) {
return;
}
let styleSheet = document.createElement("style");
styleSheet.setAttribute("id", "scrollback-custom-css");
styleSheet.appendChild(document.createTextNode("")); // fix webkit not recognizing styles
document.head.appendChild(styleSheet);
styleSheet.appendChild(document.createTextNode(roomObj.guides.customization.css.replace("<", "\\3c").replace(">", "\\3e")));
}
};
core.on("statechange", changes => {
let roomId = store.get("nav", "room");
if ((changes.nav && ("room" in changes.nav || "mode" in changes.nav)) || (changes.entities && roomId in changes.entities)) {
let mode = store.get("nav", "mode"),
thread = store.get("nav", "thread");
if (mode === "room" || (mode === "chat" && !thread)) {
customStyle.applyCss();
} else {
customStyle.removeCss();
}
}
}, 100);
};