diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js
index a0ba0111..80a4851c 100644
--- a/src/assets/javascripts/services.js
+++ b/src/assets/javascripts/services.js
@@ -647,32 +647,19 @@ async function redirectAsync(url, type, originUrl, documentUrl, incognito, force
/**
* @param {URL} url
*/
-function computeService(url) {
- return new Promise(async resolve => {
- const config = await utils.getConfig()
- const options = await utils.getOptions()
- for (const service in config.services) {
- if (regexArray(service, url, config, options)) {
- resolve(service)
- return
- } else {
- for (const frontend in config.services[service].frontends) {
- if (all(service, frontend, options, config).findIndex(instance => url.href.startsWith(instance)) >= 0) {
- return resolve(service)
- }
- }
- }
- }
- resolve()
- })
-}
-export function computeFrontend(url) {
+async function computeServiceFrontend(url) {
+ const config = await utils.getConfig()
+ const options = await utils.getOptions()
for (const service in config.services) {
- for (const frontend in config.services[service].frontends) {
- const instances = all(service, frontend, options, config)
- const i = instances.findIndex(instance => url.href.startsWith(instance))
- if (i >= 0) {
- return { service, frontend }
+ if (regexArray(service, url, config, options)) {
+ return { service, frontend: null }
+ } else {
+ for (const frontend in config.services[service].frontends) {
+ const instances = all(service, frontend, options, config)
+ const i = instances.findIndex(instance => url.href.startsWith(instance))
+ if (i >= 0) {
+ return { service, frontend }
+ }
}
}
}
@@ -970,12 +957,11 @@ function isException(url) {
export default {
redirect,
redirectAsync,
- computeService,
+ computeServiceFrontend,
reverse,
initDefaults,
processUpdate,
copyRaw,
switchInstance,
isException,
- computeFrontend,
}
diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js
index d81a96bc..f360a15b 100644
--- a/src/assets/javascripts/utils.js
+++ b/src/assets/javascripts/utils.js
@@ -222,6 +222,22 @@ export function randomInstances(clearnet, n) {
}
return instances
}
+
+async function autoPickInstance(clearnet, url) {
+ if (url) {
+ const i = clearnet.findIndex(instance => url.href.startsWith(instance))
+ if (i >= 0) clearnet.splice(i, 1)
+ }
+ const random = randomInstances(clearnet, 5)
+ const pings = await Promise.all([
+ ...random.map(async instance => {
+ return [instance, await ping(instance)]
+ }),
+ ])
+ pings.sort((a, b) => a[1] - b[1])
+ return pings[0][0]
+}
+
export function style(options, window) {
const vars = cssVariables(options, window)
return `--text: ${vars.text};
@@ -277,4 +293,5 @@ export default {
convertMapCentre,
randomInstances,
style,
+ autoPickInstance,
}
diff --git a/src/config.json b/src/config.json
index 045d7f20..9767bf43 100644
--- a/src/config.json
+++ b/src/config.json
@@ -1147,7 +1147,8 @@
},
"targets": [
"^https?:\\/{2}maps\\.libredirect\\.invalid",
- "^https?:\\/{2}(((www|maps)\\.)?(google\\.).*(\\/maps)|maps\\.(google\\.).*)"
+ "^https?:\\/{2}(www\\.)?maps\\.google(\\.[a-z]{2,3}){1,2}\\/",
+ "^https?:\\/{2}(www\\.)?google(\\.[a-z]{2,3}){1,2}\\/maps\\/?"
],
"name": "Maps",
"options": {
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
-
+ {
+ await autoPick()
+ await redirectUrl()
+ }}
+ disabled={autoPicking}
+ >
{browser.i18n.getMessage("autoPickInstance") || "Auto Pick Instance"}
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}
-
+ {
+ pinging = true
+ pingCache = {}
+ for (const instance of allInstances) {
+ pingCache[instance] = { color: "lightblue", value: "pinging..." }
+ const time = await utils.ping(instance)
+ pingCache[instance] = colorTime(time)
+ }
+ pinging = false
+ }}
+ disabled={pinging}
+ >
{browser.i18n.getMessage("pingInstances") || "Ping Instances"}
-
+ {
+ autoPicking = true
+ const clearnet = redirects[selectedFrontend]["clearnet"]
+ for (const instance of _options[selectedFrontend]) {
+ const i = clearnet.indexOf(instance)
+ if (i >= 0) clearnet.splice(i, 1)
+ }
+ const instance = await utils.autoPickInstance(clearnet)
+ _options[selectedFrontend].push(instance)
+ options.set(_options)
+ autoPicking = false
+ }}
+ disabled={autoPicking}
+ >
{browser.i18n.getMessage("autoPickInstance") || "Auto Pick Instance"}
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}