Added Auto Pick Instance https://github.com/libredirect/browser_extension/issues/949
This commit is contained in:
parent
8828f1ca97
commit
dd4b741e4a
11
src/pages/icons/AutoPickIcon.svelte
Normal file
11
src/pages/icons/AutoPickIcon.svelte
Normal file
@ -0,0 +1,11 @@
|
||||
<svg
|
||||
{...$$restProps}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
height="20px"
|
||||
viewBox="0 -960 960 960"
|
||||
width="20px"
|
||||
fill="currentColor"
|
||||
><path
|
||||
d="M144-144v-178l342-342-54-53 51-51 72 72 110.22-110.22q4.45-4.45 11.11-7.11Q683-816 691-816t15 2.5q7 2.5 12 7.5l87 88q4.55 5.83 7.27 12.64 2.73 6.8 2.73 14.58t-2.66 14.44q-2.67 6.66-7.11 11.1L696-556l72 73-51 51-54-54-341 342H144Zm72-72h76l320-320-75-76-321 320v76Zm424-385 90-91-38-39-91 90 39 40Zm0 0-39-40 39 40Z"
|
||||
/></svg
|
||||
>
|
After Width: | Height: | Size: 485 B |
@ -5,6 +5,7 @@
|
||||
import AddIcon from "../../icons/AddIcon.svelte"
|
||||
import { options, config } from "../stores"
|
||||
import PingIcon from "../../icons/PingIcon.svelte"
|
||||
import AutoPickIcon from "../../icons/AutoPickIcon.svelte"
|
||||
import Row from "../../components/Row.svelte"
|
||||
import Input from "../../components/Input.svelte"
|
||||
import Label from "../../components/Label.svelte"
|
||||
@ -36,10 +37,9 @@
|
||||
allInstances = []
|
||||
if (_options[selectedFrontend]) allInstances.push(..._options[selectedFrontend])
|
||||
if (redirects && redirects[selectedFrontend]) {
|
||||
for (const network in redirects[selectedFrontend]) {
|
||||
allInstances.push(...redirects[selectedFrontend][network])
|
||||
}
|
||||
allInstances.push(...redirects[selectedFrontend]["clearnet"])
|
||||
}
|
||||
allInstances = [...new Set(allInstances)]
|
||||
}
|
||||
|
||||
let pingCache
|
||||
@ -64,6 +64,31 @@
|
||||
pingCache[instance] = colorTime(time)
|
||||
}
|
||||
}
|
||||
function randomInstances(n) {
|
||||
let instances = []
|
||||
for (let i = 0; i < n; i++) {
|
||||
instances.push(redirects[selectedFrontend]["clearnet"][Math.floor(Math.random() * allInstances.length)])
|
||||
}
|
||||
return instances
|
||||
}
|
||||
|
||||
async function autoPickInstance() {
|
||||
const instances = randomInstances(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(function (a, b) {
|
||||
return a[1] - b[1]
|
||||
})
|
||||
|
||||
_options[selectedFrontend].push(myInstancesCache[0][0])
|
||||
options.set(_options)
|
||||
}
|
||||
|
||||
function colorTime(time) {
|
||||
let value
|
||||
let color
|
||||
@ -102,11 +127,15 @@
|
||||
{#if serviceConf.frontends[selectedFrontend].instanceList && redirects && blacklist}
|
||||
<hr />
|
||||
|
||||
<div class="ping">
|
||||
<div>
|
||||
<Button on:click={pingInstances}>
|
||||
<PingIcon class="margin margin_{document.body.dir}" />
|
||||
{browser.i18n.getMessage("pingInstances") || "Ping Instances"}
|
||||
</Button>
|
||||
<Button on:click={autoPickInstance}>
|
||||
<AutoPickIcon class="margin margin_{document.body.dir}" />
|
||||
{browser.i18n.getMessage("autoPickInstance") || "Auto Pick Instance"}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Row>
|
||||
|
Loading…
x
Reference in New Issue
Block a user