1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-11 08:30:55 +00:00
FrankerFaceZ/src/sites/twitch-twilight/modules/theme/index.js

84 lines
2 KiB
JavaScript
Raw Normal View History

2017-11-13 01:23:39 -05:00
'use strict';
// ============================================================================
// Menu Module
// ============================================================================
import Module from 'utilities/module';
import {createElement as e} from 'utilities/dom';
2017-11-14 18:48:05 -05:00
import THEME_CSS_URL from 'site/styles/theme.scss';
2017-11-13 01:23:39 -05:00
export default class ThemeEngine extends Module {
constructor(...args) {
super(...args);
this.inject('site');
this.inject('settings');
this.should_enable = true;
2017-11-14 18:48:05 -05:00
this.settings.add('theme.dark', {
requires: ['context.ui.theme'],
2017-11-13 01:23:39 -05:00
default: false,
2017-11-14 18:48:05 -05:00
process(ctx, val) {
return ctx.get('context.ui.theme') === 1 ? val : false
},
2017-11-13 01:23:39 -05:00
ui: {
2017-11-14 18:48:05 -05:00
path: 'Appearance @{"description": "Personalize the appearance of Twitch. Change the color scheme and fonts and tune the layout to optimize your experience."} > Theme >> General',
title: 'Gray (no Purple)',
description: '<em>Requires Dark Theme to be Enabled.</em><br>I see my website and I want it painted black...<br>This is a very early feature and will change as there is time.',
2017-11-13 01:23:39 -05:00
component: 'setting-check-box'
2017-11-14 18:48:05 -05:00
},
changed: val => this.updateSetting(val)
});
2017-11-13 01:23:39 -05:00
this.settings.add('theme.is-dark', {
requires: ['context.ui.theme'],
process(ctx) {
return ctx.get('context.ui.theme') === 1;
}
});
this.settings.add('theme.tooltips-dark', {
requires: ['theme.is-dark'],
process(ctx) {
return ! ctx.get('theme.is-dark')
}
});
2017-11-13 01:23:39 -05:00
this._style = null;
}
2017-11-14 18:48:05 -05:00
toggleStyle(enable) {
if ( ! this._style ) {
if ( ! enable )
return;
this._style = e('link', {
rel: 'stylesheet',
type: 'text/css',
href: THEME_CSS_URL
});
} else if ( ! enable ) {
if ( this._style.parentElement === document.head )
document.head.removeChild(this._style);
return;
}
2017-11-13 01:23:39 -05:00
document.head.appendChild(this._style);
}
2017-11-14 18:48:05 -05:00
updateSetting(enable) {
this.toggleStyle(enable);
document.body.classList.toggle('theme--ffz', enable);
2017-11-13 01:23:39 -05:00
}
2017-11-14 18:48:05 -05:00
onEnable() {
this.updateSetting(this.settings.get('theme.dark'));
2017-11-13 01:23:39 -05:00
}
}