From 0af6eac7d297ef801d4c4930f22a3a045ca016c9 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Sun, 23 Jul 2023 23:08:31 +0300 Subject: Added a chosen info for chosen instances from the public list https://github.com/libredirect/browser_extension/issues/754 --- src/pages/options/index.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/pages/options/index.js') diff --git a/src/pages/options/index.js b/src/pages/options/index.js index 2cf525ee..b537d340 100644 --- a/src/pages/options/index.js +++ b/src/pages/options/index.js @@ -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) + }) }) } } @@ -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] @@ -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 => { @@ -262,7 +265,9 @@ function createList(frontend, networks, document, redirects, blacklist) { cloudflare ` : "" - const warnings = [cloudflare].join(" ") + const chosen = options[frontend].includes(x) ? `chosen` : "" + + const warnings = [cloudflare, chosen].join(" ") return `
${x} @@ -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) + }) } }) } -- cgit 1.4.1