diff options
author | Alex Yatskov <FooSoft@users.noreply.github.com> | 2019-10-13 08:58:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-13 08:58:40 -0700 |
commit | 320af99b7676a37157e2d7207756dd502e6be608 (patch) | |
tree | 5c28a1abba2693b22b1f3f7932f69cabcbaa453c /ext/mixed/js | |
parent | 537d2ef532aa7b7498de13ab039bd23f28d32714 (diff) | |
parent | 57db18c31b117591982795c930cc9f07efc28641 (diff) |
Merge pull request #253 from toasted-nutbread/style-editor
Popup style preview + themes
Diffstat (limited to 'ext/mixed/js')
-rw-r--r-- | ext/mixed/js/display.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index cd9f41bd..51a3dc22 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -29,6 +29,7 @@ class Display { this.audioPlaying = null; this.audioFallback = null; this.audioCache = {}; + this.styleNode = null; this.eventListeners = []; this.persistentEventListeners = []; @@ -194,6 +195,32 @@ class Display { async updateOptions(options) { this.options = options ? options : await apiOptionsGet(this.getOptionsContext()); + this.updateTheme(this.options.general.popupTheme); + this.setCustomCss(this.options.general.customPopupCss); + } + + updateTheme(themeName) { + document.documentElement.dataset.yomichanTheme = themeName; + + const stylesheets = document.querySelectorAll('link[data-yomichan-theme-name]'); + for (const stylesheet of stylesheets) { + const match = (stylesheet.dataset.yomichanThemeName === themeName); + stylesheet.rel = (match ? 'stylesheet' : 'stylesheet alternate'); + } + } + + setCustomCss(css) { + if (this.styleNode === null) { + if (css.length === 0) { return; } + this.styleNode = document.createElement('style'); + } + + this.styleNode.textContent = css; + + const parent = document.head; + if (this.styleNode.parentNode !== parent) { + parent.appendChild(this.styleNode); + } } setInteractive(interactive) { |