From d4151c826fff5008a0d6017feced261061585deb Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Sat, 21 Sep 2024 09:30:22 +0300 Subject: Restricted maps regex --- src/pages/messages_src/App.svelte | 43 +++++------ src/pages/options_src/Services/Instances.svelte | 57 ++++++++------- src/pages/popup_src/Buttons.svelte | 95 ++++++++++++------------- 3 files changed, 94 insertions(+), 101 deletions(-) (limited to 'src/pages') diff --git a/src/pages/messages_src/App.svelte b/src/pages/messages_src/App.svelte index 9f464ac7..82526530 100644 --- a/src/pages/messages_src/App.svelte +++ b/src/pages/messages_src/App.svelte @@ -9,7 +9,6 @@ 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,33 +48,16 @@ const oldUrl = new URL(params.get("url")) async function autoPick() { - const frontend = params.get("frontend") autoPicking = true + const frontend = params.get("frontend") const redirects = await utils.getList(_options) - const instances = utils.randomInstances(redirects[frontend]["clearnet"], 5) - const pings = await Promise.all([ - ...instances.map(async instance => { - return [instance, await utils.ping(instance)] - }), - ]) - pings.sort((a, b) => a[1] - b[1]) - _options[frontend].push(pings[0][0]) + const clearnet = redirects[frontend]["clearnet"] + const instance = await utils.autoPickInstance(clearnet) + _options[frontend].push(instance) options.set(_options) autoPicking = false } - async function autoPickInstance() { - await autoPick() - await redirectUrl() - } - - async function enableService() { - const service = await servicesHelper.computeService(oldUrl) - _options[service].enabled = true - options.set(_options) - await redirectUrl() - } - async function redirectUrl() { const newUrl = await servicesHelper.redirectAsync(oldUrl, "main_frame", null, null, false, true) browser.tabs.update({ url: newUrl }) @@ -87,14 +69,27 @@ {#if params.get("message") == "disabled"}

You disabled redirections for this service

-
{:else if params.get("message") == "no_instance"}

You have no instance selected for this frontend

- diff --git a/src/pages/options_src/Services/Instances.svelte b/src/pages/options_src/Services/Instances.svelte index 4e5d1e7d..7a04b04e 100644 --- a/src/pages/options_src/Services/Instances.svelte +++ b/src/pages/options_src/Services/Instances.svelte @@ -56,30 +56,6 @@ return true } - async function pingInstances() { - pingCache = {} - for (const instance of allInstances) { - pingCache[instance] = { color: "lightblue", value: "pinging..." } - const time = await utils.ping(instance) - pingCache[instance] = colorTime(time) - } - } - - async function autoPickInstance() { - const instances = utils.randomInstances(redirects[selectedFrontend]["clearnet"], 5) - const myInstancesCache = [] - for (const instance of instances) { - pingCache[instance] = { color: "lightblue", value: "pinging..." } - const time = await utils.ping(instance) - pingCache[instance] = colorTime(time) - myInstancesCache.push([instance, time]) - } - myInstancesCache.sort((a, b) => a[1] - b[1]) - - _options[selectedFrontend].push(myInstancesCache[0][0]) - options.set(_options) - } - function colorTime(time) { let value let color @@ -113,17 +89,46 @@ options.set(_options) } } + + let autoPicking = false + let pinging = false {#if serviceConf.frontends[selectedFrontend].instanceList && redirects && blacklist}
- - diff --git a/src/pages/popup_src/Buttons.svelte b/src/pages/popup_src/Buttons.svelte index 992ed8e2..2354fcac 100644 --- a/src/pages/popup_src/Buttons.svelte +++ b/src/pages/popup_src/Buttons.svelte @@ -17,7 +17,6 @@ let _options let _config - let autoPicking = false const unsubscribeOptions = options.subscribe(val => (_options = val)) const unsubscribeConfig = config.subscribe(val => (_config = val)) @@ -30,7 +29,6 @@ let switchInstance let redirectToOriginal let redirect - let currentService let frontend let service browser.tabs.query({ active: true, currentWindow: true }, async tabs => { @@ -39,57 +37,20 @@ servicesHelper.switchInstance(url).then(r => (switchInstance = r)) servicesHelper.reverse(url).then(r => (redirectToOriginal = r)) servicesHelper.redirectAsync(url, "main_frame", null, null, false, true).then(r => (redirect = r)) - servicesHelper.computeService(url).then(r => (currentService = r)) - const computed = servicesHelper.computeFrontend(url) - if (computed) { - ;({ service, frontend } = computed) - } + servicesHelper.computeServiceFrontend(url).then(r => ({ service, frontend } = r)) } }) - async function removeInstance() { - const i = _options[frontend].findIndex(instance => url.href.startsWith(instance)) - _options[frontend].splice(i, 1) - options.set(_options) - const newUrl = await servicesHelper.switchInstance(url, service) - browser.tabs.update({ url: newUrl }) - window.close() - } - - async function autoPickInstance() { + let autoPicking = false + async function autoPick() { autoPicking = true const redirects = await utils.getList(_options) const clearnet = redirects[frontend]["clearnet"] - const i = clearnet.findIndex(instance => url.href.startsWith(instance)) - if (i >= 0) clearnet.splice(i, 1) - const randomInstances = utils.randomInstances(clearnet, 5) - const pings = await Promise.all([ - ...randomInstances.map(async instance => { - return [instance, await utils.ping(instance)] - }), - ]) - pings.sort((a, b) => a[1] - b[1]) - _options[frontend].push(pings[0][0]) + const instance = await utils.autoPickInstance(clearnet, url) + _options[frontend].push(instance) options.set(_options) autoPicking = false } - - async function addAutoPickInstance() { - await autoPickInstance() - browser.tabs.update({ url: await servicesHelper.switchInstance(url, service) }, () => { - window.close() - }) - } - - async function removeAndAutoPickInstance() { - const i = _options[frontend].findIndex(instance => url.href.startsWith(instance)) - _options[frontend].splice(i, 1) - options.set(_options) - await autoPickInstance() - browser.tabs.update({ url: await servicesHelper.switchInstance(url, service) }, () => { - window.close() - }) - }
@@ -125,7 +86,18 @@ {/if} - + { + const i = _options[frontend].findIndex(instance => url.href.startsWith(instance)) + _options[frontend].splice(i, 1) + options.set(_options) + const newUrl = await servicesHelper.switchInstance(url, service) + browser.tabs.update({ url: newUrl }, () => { + window.close() + }) + }} + > {:else} - + { + const i = _options[frontend].findIndex(instance => url.href.startsWith(instance)) + _options[frontend].splice(i, 1) + options.set(_options) + await autoPick() + browser.tabs.update({ url: await servicesHelper.switchInstance(url, service) }, () => { + window.close() + }) + }} + > - + { + await autoPick() + browser.tabs.update({ url: await servicesHelper.switchInstance(url, service) }, () => { + window.close() + }) + }} + > @@ -161,7 +152,9 @@ on:click={() => { browser.tabs.query({ active: true, currentWindow: true }, tabs => { browser.runtime.sendMessage({ message: "reverse", tabId: tabs[0].id }, () => { - browser.tabs.update({ url: redirectToOriginal }) + browser.tabs.update({ url: redirectToOriginal }, () => { + window.close() + }) }) }) }} @@ -175,13 +168,13 @@
{/if} - {#if currentService} - + {#if service} +
{/if} {#each _options.popupServices as serviceKey} - {#if currentService !== serviceKey} + {#if service !== serviceKey} {/if} {/each} -- cgit 1.4.1