diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-13 10:50:56 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-13 12:12:51 -0400 |
commit | 118f200500b3a27afc873a896b8304387456e2e7 (patch) | |
tree | 783fbb7763fb893575d18619a3bd3951a370e026 | |
parent | 320af99b7676a37157e2d7207756dd502e6be608 (diff) |
Simplified how the auto theme works
-rw-r--r-- | ext/fg/css/client.css | 3 | ||||
-rw-r--r-- | ext/fg/js/popup.js | 19 |
2 files changed, 10 insertions, 12 deletions
diff --git a/ext/fg/css/client.css b/ext/fg/css/client.css index 84098653..4b824da3 100644 --- a/ext/fg/css/client.css +++ b/ext/fg/css/client.css @@ -29,7 +29,8 @@ iframe#yomichan-float { box-sizing: border-box; } -iframe#yomichan-float[data-yomichan-theme=dark] { +iframe#yomichan-float[data-yomichan-theme=dark], +iframe#yomichan-float[data-yomichan-theme=auto][data-yomichan-site-color=dark] { background-color: #1e1e1e; border: 1px solid #666; box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index ef4cdb67..880e3efe 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -271,19 +271,16 @@ class Popup { } updateTheme() { - this.container.dataset.yomichanTheme = this.getTheme(this.options.general.popupOuterTheme); + this.container.dataset.yomichanTheme = this.options.general.popupOuterTheme; + this.container.dataset.yomichanSiteColor = this.getSiteColor(); } - getTheme(themeName) { - if (themeName === 'auto') { - const color = [255, 255, 255]; - Popup.addColor(color, Popup.getColorInfo(window.getComputedStyle(document.documentElement).backgroundColor)); - Popup.addColor(color, Popup.getColorInfo(window.getComputedStyle(document.body).backgroundColor)); - const dark = (color[0] < 128 && color[1] < 128 && color[2] < 128); - themeName = dark ? 'dark' : 'default'; - } - - return themeName; + getSiteColor() { + const color = [255, 255, 255]; + Popup.addColor(color, Popup.getColorInfo(window.getComputedStyle(document.documentElement).backgroundColor)); + Popup.addColor(color, Popup.getColorInfo(window.getComputedStyle(document.body).backgroundColor)); + const dark = (color[0] < 128 && color[1] < 128 && color[2] < 128); + return dark ? 'dark' : 'light'; } static addColor(target, color) { |