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;
}
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);

View File

@ -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) {