From d34cf89aaa7105ceee0ef0add7cd150eb43636a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Sun, 10 Jan 2016 11:37:27 +0100 Subject: [PATCH] Add support for custom CSS Fixes #647 --- index.html | 11 +++++++++++ js/glowingbear.js | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/index.html b/index.html index 48c54ea..6ca73a5 100644 --- a/index.html +++ b/index.html @@ -352,6 +352,17 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel +
  • +
    +
    + +
    + +
    +
    +
    +
  • +
  • diff --git a/js/glowingbear.js b/js/glowingbear.js index 2233448..271916a 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -46,6 +46,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', 'readlineBindings': false, 'enableJSEmoji': (utils.isMobileUi() ? false : true), 'enableMathjax': false, + 'customCSS': '', }); $scope.settings = settings; @@ -424,6 +425,24 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', })(); }); + settings.addCallback('customCSS', function(css) { + // We need to delete the old tag and add a new one so that the browser + // notices the change. Thus, first remove old custom CSS. + var old_css = document.getElementById('custom-css-tag'); + if (old_css) { + old_css.parentNode.removeChild(old_css); + } + + // Create new CSS tag + var new_css = document.createElement("style"); + new_css.type = "text/css"; + new_css.id = "custom-css-tag"; + new_css.appendChild(document.createTextNode(css)); + // Append it to the tag + var heads = document.getElementsByTagName("head"); + heads[0].appendChild(new_css); + }); + // Update font family when changed settings.addCallback('fontfamily', function(fontfamily) {