fix: close #245, port various fixes from 7.0

This commit is contained in:
David Ralph
2022-03-06 17:28:25 +00:00
parent 66e22b05ef
commit 66da158840
9 changed files with 19 additions and 34 deletions

View File

@@ -110,23 +110,11 @@ export function loadSettings(hotreload) {
`);
}
// everything below this either doesn't support hot reload (custom js) or shouldn't run on a hot reload event
// everything below this shouldn't run on a hot reload event
if (hotreload === true) {
return;
}
if (window.location.href.startsWith('http://') || window.location.href.startsWith('https://')){
const js = localStorage.getItem('customjs');
if (js) {
try {
// eslint-disable-next-line no-eval
eval(js);
} catch (e) {
console.error('Failed to run custom JS: ', e);
}
}
}
if (localStorage.getItem('experimental') === 'true') {
experimentalInit();
}

View File

@@ -1,19 +1,21 @@
import variables from 'modules/variables';
import { toast } from 'react-toastify';
export function saveFile(data, filename = 'file') {
const getMessage = (text) => variables.language.getMessage(variables.languagecode, text);
export function saveFile(data, filename = 'file', type = 'text/json') {
if (typeof data === 'object') {
data = JSON.stringify(data, undefined, 4);
}
const blob = new Blob([data], { type: 'text/json' });
const blob = new Blob([data], { type });
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(':');
a.dataset.downloadurl = [type, a.download, a.href].join(':');
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(event);
@@ -29,7 +31,6 @@ export function exportSettings() {
}
export function importSettings(e) {
const getMessage = (text) => variables.language.getMessage(variables.languagecode, text);
const content = JSON.parse(e.target.result);
Object.keys(content).forEach((key) => {