ctucx.git: mqtt-webui

webui for mqtt, can be used to control/display data in mqtt-topics

commit 3a1b78bbf8aad83c19d39b45182555a98bd24fc8
parent fcd1f8ccf4bcc6c52a5598b28f0c0fa36f025d56
Author: Leah (ctucx) <git@ctu.cx>
Date: Tue, 13 Dec 2022 16:20:08 +0100

webui.js: add option to load extra css
3 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/config.json b/config.json
@@ -1,6 +1,7 @@
 {
   "appName": "Smart-Home",
   "disableAuth": false,
+  "extraCSS": "./test.css",
   "pages": [
     {
       "icon": "favicon-512x512.png",
diff --git a/config.nix b/config.nix
@@ -40,6 +40,7 @@ in {
 
   appName     = "Smart-Home";
   disableAuth = false;
+  extraCSS    = "./test.css";
   pages =  [
     {
       id        = "mainpage";
diff --git a/src/webui.js b/src/webui.js
@@ -369,6 +369,14 @@ window.addEventListener('DOMContentLoaded', async (event) => {
 		document.querySelector('meta[name="apple-mobile-web-app-title"]').content = config.appName;
 	}
 
+	if (typeof config.extraCSS === 'string') {
+		const link = document.createElement('link');
+		link.href  = config.extraCSS;
+		link.type  = 'text/css';
+		link.rel   = 'stylesheet';
+		document.getElementsByTagName('head')[0].appendChild(link);
+	}
+
 	// create UI
 	render(renderPages(config), document.body);
 	document.getElementById("loading").style.display = 'none';