Cleaned code

This commit is contained in:
ManeraKai 2024-07-27 12:11:54 +03:00
parent 7015f3f628
commit ed0c90ec3d
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
6 changed files with 18 additions and 34 deletions

View File

@ -1,4 +1,4 @@
<button on:click {...$$props}>
<button {...$$restProps} on:click {...$$props}>
<slot></slot>
</button>

View File

@ -3,7 +3,7 @@
</script>
<input
{...$$props}
{...$$restProps}
bind:value
on:blur
on:change

View File

@ -1,4 +1,4 @@
<div {...$$props} on:click>
<div {...$$restProps} on:click>
<slot></slot>
</div>

View File

@ -38,7 +38,6 @@
_options.theme = e.target.options[e.target.options.selectedIndex].value
options.set(_options)
}}
ariaLabel="select theme"
/>
</Row>
@ -55,7 +54,6 @@
_options.fetchInstances = e.target.options[e.target.options.selectedIndex].value
options.set(_options)
}}
ariaLabel={"Select fetch public instances"}
/>
</Row>
@ -75,7 +73,7 @@
<Checkbox bind:checked={bookmarksPermission} />
</Row>
<Exceptions opts={_options} />
<Exceptions />
<SettingsButtons opts={_options} />
<SettingsButtons />
</div>

View File

@ -14,24 +14,18 @@
const unsubscribe = options.subscribe(val => (_options = val))
onDestroy(unsubscribe)
let disableButtons = false
let importSettingsInput
let importSettingsFiles
$: if (importSettingsFiles) {
disableButtons = true
const reader = new FileReader()
reader.readAsText(importSettingsFiles[0])
reader.onload = async () => {
const data = JSON.parse(reader.result)
if ("theme" in data && data.version == browser.runtime.getManifest().version) {
browser.storage.local.clear(async () => {
console.log("clearing")
options.set(data)
disableButtons = false
})
} else {
console.log("incompatible settings")
alert("Incompatible settings")
}
}
@ -42,26 +36,21 @@
}
async function exportSettings() {
disableButtons = true
_options.version = browser.runtime.getManifest().version
const resultString = JSON.stringify(_options, null, " ")
const anchor = document.createElement("a")
anchor.href = "data:application/json;base64," + btoa(resultString)
anchor.download = `libredirect-settings-v${_options.version}.json`
anchor.click()
disableButtons = false
}
async function exportSettingsSync() {
disableButtons = true
_options.version = browser.runtime.getManifest().version
await servicesHelper.initDefaults()
browser.storage.sync.set({ options: _options })
disableButtons = false
}
async function importSettingsSync() {
disableButtons = true
browser.storage.sync.get({ options }, r => {
const optionsSync = r.options
if (optionsSync.version == browser.runtime.getManifest().version) {
@ -69,24 +58,21 @@
} else {
alert("Error")
}
disableButtons = false
})
}
async function resetSettings() {
disableButtons = true
browser.storage.local.clear(async () => {
await servicesHelper.initDefaults()
options.set(await utils.getOptions())
disableButtons = false
})
}
</script>
<div class="buttons">
<Button on:click={() => importSettingsInput.click()} disabled={disableButtons}>
<Button on:click={() => importSettingsInput.click()}>
<ImportIcon class="margin margin_{document.body.dir}" />
<x data-localise="__MSG_importSettings__">{browser.i18n.getMessage("importSettings") || "Import Settings"}</x>
{browser.i18n.getMessage("importSettings") || "Import Settings"}
</Button>
<input
type="file"
@ -96,24 +82,24 @@
bind:files={importSettingsFiles}
/>
<Button on:click={exportSettings} disabled={disableButtons}>
<Button on:click={exportSettings}>
<ExportIcon class="margin margin_{document.body.dir}" />
<x data-localise="__MSG_exportSettings__">{browser.i18n.getMessage("exportSettings") || "Export Settings"}</x>
{browser.i18n.getMessage("exportSettings") || "Export Settings"}
</Button>
<Button on:click={exportSettingsSync} disabled={disableButtons}>
<Button on:click={exportSettingsSync}>
<ExportIcon class="margin margin_{document.body.dir}" />
<x>Export Settings to Sync</x>
{browser.i18n.getMessage("exportSettingsToSync") || "Export Settings to Sync"}
</Button>
<Button on:click={importSettingsSync} disabled={disableButtons}>
<Button on:click={importSettingsSync}>
<ImportIcon class="margin margin_{document.body.dir}" />
<x>{browser.i18n.getMessage("importSettingsFromSync") || "Import Settings from Sync"}</x>
{browser.i18n.getMessage("importSettingsFromSync") || "Import Settings from Sync"}
</Button>
<Button on:click={resetSettings} disabled={disableButtons}>
<Button on:click={resetSettings}>
<ResetIcon class="margin margin_{document.body.dir}" />
<x>{browser.i18n.getMessage("resetSettings") || "Reset Settings"}</x>
{browser.i18n.getMessage("resetSettings") || "Reset Settings"}
</Button>
</div>

View File

@ -10,15 +10,15 @@
<div>
<a href="#general" on:click={() => page.set("general")} style={$page == "general" && "color: var(--active);"}>
<GeneralIcon class="margin margin_{document.body.dir}" />
<span data-localise="__MSG_general__">{browser.i18n.getMessage("general") || "General"}</span>
{browser.i18n.getMessage("general") || "General"}
</a>
<a href="#services" on:click={() => page.set("services")} style={$page == "services" && "color: var(--active);"}>
<ServicesIcon class="margin margin_{document.body.dir}" />
<span data-localise="__MSG_services__">{browser.i18n.getMessage("general") || "Services"}</span>
{browser.i18n.getMessage("general") || "Services"}
</a>
<a href="https://libredirect.github.io" target="_blank" rel="noopener noreferrer">
<AboutIcon class="margin margin_{document.body.dir}" />
<span data-localise="__MSG_about__">{browser.i18n.getMessage("about") || "About"}</span>
{browser.i18n.getMessage("about") || "About"}
</a>
</div>