Simplified how the auto theme works

This commit is contained in:
toasted-nutbread 2019-10-13 10:50:56 -04:00
parent 320af99b76
commit 118f200500
2 changed files with 10 additions and 12 deletions

View File

@ -29,7 +29,8 @@ iframe#yomichan-float {
box-sizing: border-box; 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; background-color: #1e1e1e;
border: 1px solid #666; border: 1px solid #666;
box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);

View File

@ -271,19 +271,16 @@ class Popup {
} }
updateTheme() { 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) { getSiteColor() {
if (themeName === 'auto') { const color = [255, 255, 255];
const color = [255, 255, 255]; Popup.addColor(color, Popup.getColorInfo(window.getComputedStyle(document.documentElement).backgroundColor));
Popup.addColor(color, Popup.getColorInfo(window.getComputedStyle(document.documentElement).backgroundColor)); Popup.addColor(color, Popup.getColorInfo(window.getComputedStyle(document.body).backgroundColor));
Popup.addColor(color, Popup.getColorInfo(window.getComputedStyle(document.body).backgroundColor)); const dark = (color[0] < 128 && color[1] < 128 && color[2] < 128);
const dark = (color[0] < 128 && color[1] < 128 && color[2] < 128); return dark ? 'dark' : 'light';
themeName = dark ? 'dark' : 'default';
}
return themeName;
} }
static addColor(target, color) { static addColor(target, color) {