Skip to content

Commit

Permalink
Added a chosen info for chosen instances from the public list #754
Browse files Browse the repository at this point in the history
  • Loading branch information
ManeraKai committed Jul 23, 2023
1 parent b343878 commit 0af6eac
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/pages/options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ async function calcCustomInstances(frontend) {
if (index > -1) customInstances.splice(index, 1)
options = await utils.getOptions()
options[frontend] = customInstances
browser.storage.local.set({ options }, () => calcCustomInstances(frontend))
browser.storage.local.set({ options }, async () => {
calcCustomInstances(frontend)
const blacklist = await utils.getBlacklist(options)
const redirects = await utils.getList(options)
createList(frontend, config.networks, document, redirects, blacklist)
})
})
}
}
Expand Down Expand Up @@ -232,7 +237,7 @@ async function processCustomInstances(frontend, document) {
})
}

function createList(frontend, networks, document, redirects, blacklist) {
async function createList(frontend, networks, document, redirects, blacklist) {
for (const network in networks) {
const checklist = document.getElementById(frontend)
.getElementsByClassName(network)[0]
Expand All @@ -250,10 +255,8 @@ function createList(frontend, networks, document, redirects, blacklist) {
.getElementsByClassName("custom-instance")[0]
.placeholder = redirects[frontend].clearnet[0]

const sortedInstances = instances
.sort((a, b) => {
return (blacklist.cloudflare.includes(a) && !blacklist.cloudflare.includes(b))
})
const sortedInstances = instances.sort((a, b) => blacklist.cloudflare.includes(a) && !blacklist.cloudflare.includes(b))
const options = await utils.getOptions()

const content = sortedInstances
.map(x => {
Expand All @@ -262,7 +265,9 @@ function createList(frontend, networks, document, redirects, blacklist) {
<span style="color:red;">cloudflare</span>
</a>` : ""

const warnings = [cloudflare].join(" ")
const chosen = options[frontend].includes(x) ? `<span style="color:grey;">chosen</span>` : ""

const warnings = [cloudflare, chosen].join(" ")
return `<div class="frontend">
<x>
<a href="${x}" target="_blank">${x}</a>
Expand Down Expand Up @@ -290,7 +295,10 @@ function createList(frontend, networks, document, redirects, blacklist) {
let options = await utils.getOptions()
if (!options[frontend].includes(instance)) {
options[frontend].push(instance)
browser.storage.local.set({ options }, () => calcCustomInstances(frontend))
browser.storage.local.set({ options }, () => {
calcCustomInstances(frontend)
createList(frontend, config.networks, document, redirects, blacklist)
})
}
})
}
Expand Down

0 comments on commit 0af6eac

Please sign in to comment.