mirror of
https://github.com/mue/mue.git
synced 2026-07-21 07:54:13 +02:00
fix: improve welcome modal text, cleanup settings helpers slightly
This commit is contained in:
@@ -30,8 +30,7 @@ export function setDefaultSettings(reset) {
|
||||
export function loadSettings(hotreload) {
|
||||
document.getElementById('widgets').style.zoom = localStorage.getItem('widgetzoom') + '%';
|
||||
|
||||
const theme = localStorage.getItem('theme');
|
||||
switch (theme) {
|
||||
switch (localStorage.getItem('theme')) {
|
||||
case 'dark':
|
||||
document.body.classList.add('dark');
|
||||
break;
|
||||
@@ -46,16 +45,16 @@ export function loadSettings(hotreload) {
|
||||
document.body.classList.remove('dark');
|
||||
}
|
||||
|
||||
const tabName = localStorage.getItem('tabName') || window.language.tabname;
|
||||
document.title = tabName;
|
||||
document.title = localStorage.getItem('tabName') || window.language.tabname;
|
||||
|
||||
if (hotreload === true) {
|
||||
const custom = ['customcss', 'customjs', 'customfont'];
|
||||
// remove old custom stuff and add new
|
||||
const custom = ['customcss', 'customfont'];
|
||||
custom.forEach((element) => {
|
||||
try {
|
||||
document.head.removeChild(document.getElementById(element));
|
||||
} catch (e) {
|
||||
// Disregard exception
|
||||
// Disregard exception if custom stuff doesn't exist
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -92,8 +91,8 @@ export function loadSettings(hotreload) {
|
||||
const js = localStorage.getItem('customjs');
|
||||
if (js) {
|
||||
try {
|
||||
// eslint-disable-next-line no-eval
|
||||
eval(js);
|
||||
// eslint-disable-next-line no-new-func
|
||||
Function(`'use strict'; return (${js})`)();
|
||||
} catch (e) {
|
||||
console.error('Failed to run custom JS: ', e);
|
||||
}
|
||||
@@ -126,18 +125,19 @@ export function loadSettings(hotreload) {
|
||||
// in a nutshell, this function saves all of the current settings, resets them, sets the defaults and then overrides
|
||||
// the new settings with the old saved messages where they exist
|
||||
export function moveSettings() {
|
||||
if (Object.keys(localStorage).length === 0) {
|
||||
const currentSettings = Object.keys(localStorage);
|
||||
if (currentSettings.length === 0) {
|
||||
return this.setDefaultSettings();
|
||||
}
|
||||
|
||||
let settings = {};
|
||||
Object.keys(localStorage).forEach((key) => {
|
||||
const settings = {};
|
||||
currentSettings.forEach((key) => {
|
||||
settings[key] = localStorage.getItem(key);
|
||||
});
|
||||
|
||||
localStorage.clear();
|
||||
|
||||
setDefaultSettings();
|
||||
|
||||
Object.keys(settings).forEach((key) => {
|
||||
localStorage.setItem(key, settings[key]);
|
||||
});
|
||||
|
||||
@@ -6,21 +6,22 @@ export function saveFile(data, filename = 'file') {
|
||||
}
|
||||
|
||||
const blob = new Blob([data], { type: 'text/json' });
|
||||
let e = document.createEvent('MouseEvents');
|
||||
let a = document.createElement('a');
|
||||
|
||||
const event = document.createEvent('MouseEvents');
|
||||
const a = document.createElement('a');
|
||||
|
||||
a.href = window.URL.createObjectURL(blob);
|
||||
a.download = filename;
|
||||
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':');
|
||||
|
||||
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||
a.dispatchEvent(e);
|
||||
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||
a.dispatchEvent(event);
|
||||
}
|
||||
|
||||
export function exportSettings() {
|
||||
let settings = {};
|
||||
const settings = {};
|
||||
Object.keys(localStorage).forEach((key) => {
|
||||
settings[key] = localStorage.getItem(key);
|
||||
settings[key] = localStorage.getItem(key);
|
||||
});
|
||||
saveFile(settings, 'mue-settings.json');
|
||||
window.stats.postEvent('tab', 'Settings exported');
|
||||
|
||||
Reference in New Issue
Block a user