Fixed Import Tool not working #242
This commit is contained in:
parent
ca9c5e04c0
commit
5aa8f7a56a
|
@ -48,7 +48,7 @@ async function updateInstances() {
|
|||
await wholeInit();
|
||||
const instances = JSON.parse(http.responseText);
|
||||
|
||||
brwoser.storage.local.get(
|
||||
browser.storage.local.get(
|
||||
[
|
||||
'youtubeRedirects'
|
||||
],
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
<path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"></path>
|
||||
</svg>
|
||||
<x data-localise="__MSG_updateInstances__">Update Instances</x></a>
|
||||
<label class="button button-inline" for="import-settings">
|
||||
<label class="button button-inline" id="import_settings_text" for="import-settings">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
||||
<path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"></path>
|
||||
</svg>
|
||||
|
|
|
@ -37,16 +37,34 @@ exportSettings();
|
|||
browser.storage.onChanged.addListener(exportSettings);
|
||||
|
||||
let importSettingsElement = document.getElementById("import-settings");
|
||||
let importSettingsElementText = document.getElementById('import_settings_text');
|
||||
importSettingsElement.addEventListener("change",
|
||||
() => {
|
||||
let file = importSettingsElement.files[0];
|
||||
const reader = new FileReader();
|
||||
reader.readAsText(file);
|
||||
reader.onload = () => browser.storage.local.set({ ...JSON.parse(reader.result) })
|
||||
reader.onerror = error => reject(error);
|
||||
location.reload();
|
||||
reader.onload = async () => {
|
||||
const data = JSON.parse(reader.result)
|
||||
if (
|
||||
"theme" in data &&
|
||||
"disableImgur" in data &&
|
||||
"cloudflareList" in data &&
|
||||
"imgurRedirects" in data
|
||||
) {
|
||||
console.log('importing a valid file...');
|
||||
await browser.storage.local.set({ ...data })
|
||||
location.reload();
|
||||
} else
|
||||
importError()
|
||||
}
|
||||
reader.onerror = error => importError();
|
||||
}
|
||||
);
|
||||
function importError() {
|
||||
const oldHTML = importSettingsElementText.innerHTML;
|
||||
importSettingsElementText.innerHTML = '<span style="color:red;">Error!</span>';
|
||||
setTimeout(() => importSettingsElementText.innerHTML = oldHTML, 1000);
|
||||
}
|
||||
|
||||
let resetSettingsElement = document.getElementById("reset-settings");
|
||||
resetSettingsElement.addEventListener("click",
|
||||
|
|
|
@ -44,7 +44,7 @@ body.option(dir="auto")
|
|||
|
||||
|
|
||||
|
||||
label.button.button-inline(for="import-settings")
|
||||
label#import_settings_text.button.button-inline(for="import-settings")
|
||||
svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor")
|
||||
path(d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z")
|
||||
|
|
||||
|
|
Loading…
Reference in New Issue