From 1492345b0d2f0f4d6d4a7a6f8814596785a472b0 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Thu, 29 Aug 2024 15:29:51 +0300 Subject: Added message popup for Server Errors https://github.com/libredirect/browser_extension/issues/936 --- src/pages/messages_src/App.svelte | 65 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'src/pages/messages_src') diff --git a/src/pages/messages_src/App.svelte b/src/pages/messages_src/App.svelte index b08a143b..05a78044 100644 --- a/src/pages/messages_src/App.svelte +++ b/src/pages/messages_src/App.svelte @@ -9,6 +9,7 @@ import { options, config, page } from "./stores" import Button from "../components/Button.svelte" import AutoPickIcon from "../icons/AutoPickIcon.svelte" + import SwitchInstanceIcon from "../icons/SwitchInstanceIcon.svelte" let _options const unsubscribeOptions = options.subscribe(val => { @@ -49,7 +50,7 @@ const params = new URLSearchParams(window.location.search) const oldUrl = new URL(params.get("url")) - async function autoPickInstance() { + async function autoPick() { const frontend = params.get("frontend") autoPicking = true const instances = utils.randomInstances(redirects[frontend]["clearnet"], 5) @@ -59,6 +60,10 @@ _options[frontend].push(pings[0][0]) options.set(_options) autoPicking = false + } + + async function autoPickInstance() { + await autoPick() await redirectUrl() } @@ -73,6 +78,36 @@ const newUrl = await servicesHelper.redirectAsync(oldUrl, "main_frame", null, null, false, true) browser.tabs.update({ url: newUrl }) } + + async function switchInstance() { + const newUrl = await servicesHelper.switchInstance(oldUrl) + browser.tabs.update({ url: newUrl }) + } + + async function removeInstance() { + const frontend = params.get("frontend") + const i = _options[frontend].indexOf(utils.protocolHost(oldUrl)) + _options[frontend].splice(i, 1) + options.set(_options) + const newUrl = await servicesHelper.switchInstance(oldUrl, service) + browser.tabs.update({ url: newUrl }) + } + + async function removeAndAutoPickInstance() { + const frontend = params.get("frontend") + const i = _options[frontend].indexOf(utils.protocolHost(oldUrl)) + _options[frontend].splice(i, 1) + options.set(_options) + await autoPick() + const newUrl = await servicesHelper.switchInstance(oldUrl, service) + browser.tabs.update({ url: newUrl }) + } + + async function addAutoPickInstance() { + await autoPick() + const newUrl = await servicesHelper.switchInstance(oldUrl) + browser.tabs.update({ url: newUrl }) + } {#if _options && _config} @@ -84,6 +119,34 @@ {browser.i18n.getMessage("enable") || "Enable"} + {:else if window.location.search.includes("message=server_error")} + +
+

Your selected instance gave out an error

+ {#if _options[params.get("frontend")].length > 1} + + + {:else} + + + {/if} +
{:else if window.location.search.includes("message=no_instance")}

You have no instance selected for this frontend

-- cgit 1.4.1