option to set theme to dark by default by customizing application_config.js, independent of browser/system theme

This commit is contained in:
zuzanna-maria 2023-01-08 18:28:47 +01:00
parent 86c7b42aae
commit 7872c9ff92

View file

@ -1,17 +1,31 @@
(function () {
try {
define([
'/common/requireconfig.js',
'/customize/application_config.js'
], function (RequireConfig, AppConfig) {
var checkDefaultDarkTheme = function () {
if (AppConfig.defaultDarkTheme) {
return os = 'dark';
} else {
var isDarkOS = function () {
try {
return window.matchMedia('(prefers-color-scheme: dark)').matches;
} catch (e) { return false; }
};
return os = isDarkOS() ? 'dark' : 'light';
}
};
var os = checkDefaultDarkTheme()
try {
var flush = window.CryptPad_flushCache = function () {
Object.keys(localStorage).forEach(function (k) {
if (k.indexOf('CRYPTPAD_CACHE|') !== 0 && k.indexOf('LESS_CACHE') !== 0) { return; }
delete localStorage[k];
});
};
var os = isDarkOS() ? 'dark' : 'light';
var key = 'CRYPTPAD_STORE|colortheme';
window.CryptPad_theme = localStorage[key] || os;
if (!localStorage[key]) {
@ -27,14 +41,11 @@ try {
s.innerHTML = 'body { background: black; }';
document.body.appendChild(s);
}
} catch (e) { console.error(e); }
})();
} catch (e) { console.error(e); }
// This is stage 1, it can be changed but you must bump the version of the project.
define([
'/common/requireconfig.js'
], function (RequireConfig) {
// This is stage 1, it can be changed but you must bump the version of the project.
require.config(RequireConfig());
// most of CryptPad breaks if you don't support isArray