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> <slot></slot>
</button> </button>

View File

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

View File

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

View File

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

View File

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

View File

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