From 73f85a005eeb28e999839e90077874defc16d00b Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Mon, 20 May 2024 22:55:33 +0300 Subject: Added custom label to instances not from the public list https://github.com/libredirect/browser_extension/issues/907. Cleaned code --- src/pages/options/index.js | 59 +++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/pages/options/index.js b/src/pages/options/index.js index ec47f3c5..9274023f 100644 --- a/src/pages/options/index.js +++ b/src/pages/options/index.js @@ -2,6 +2,8 @@ import utils from "../../assets/javascripts/utils.js" let config, options, + blacklist, + redirects, divs = {} for (const a of document.getElementById("links").getElementsByTagName("a")) { @@ -148,20 +150,11 @@ async function loadPage(path) { changeFrontendsSettings(service) - for (const frontend in config.services[service].frontends) { - if (config.services[service].frontends[frontend].instanceList) { - processCustomInstances(frontend, document) - document.getElementById(`ping-${frontend}`).addEventListener("click", async () => { - document.getElementById(`ping-${frontend}`).getElementsByTagName('x')[0].innerHTML = "Pinging..." - await ping(frontend) - document.getElementById(`ping-${frontend}`).getElementsByTagName('x')[0].innerHTML = "Ping instances" - }) - } - } + !async function () { - const blacklist = await utils.getBlacklist(options) - const redirects = await utils.getList(options) + blacklist = await utils.getBlacklist(options) + redirects = await utils.getList(options) for (const frontend in config.services[service].frontends) { if (config.services[service].frontends[frontend].instanceList) { @@ -177,10 +170,21 @@ async function loadPage(path) { .innerHTML = 'Could not fetch instances.' } else { - createList(frontend, config.networks, document, redirects, blacklist) + createList(frontend) } } } + + for (const frontend in config.services[service].frontends) { + if (config.services[service].frontends[frontend].instanceList) { + processCustomInstances(frontend) + document.getElementById(`ping-${frontend}`).addEventListener("click", async () => { + document.getElementById(`ping-${frontend}`).getElementsByTagName('x')[0].innerHTML = "Pinging..." + await ping(frontend) + document.getElementById(`ping-${frontend}`).getElementsByTagName('x')[0].innerHTML = "Ping instances" + }) + } + } }() } } @@ -199,10 +203,12 @@ async function calcCustomInstances(frontend) { const { color, text } = processTime(time) timeText = `${text}` } + const custom = isCustomInstance(frontend, x) ? "" : `custom` return `
${x} ${timeText} + ${custom}