about summary refs log tree commit diff stats
path: root/src/pages/options/index.js
diff options
context:
space:
mode:
authorManeraKai <manerakai@protonmail.com>2023-07-23 23:08:31 +0300
committerManeraKai <manerakai@protonmail.com>2023-07-23 23:08:31 +0300
commit0af6eac7d297ef801d4c4930f22a3a045ca016c9 (patch)
tree93cb5df1d3f1b555e476475d3228e74fb314495d /src/pages/options/index.js
parentAdded localhost to Redirect To Original https://github.com/libredirect/browse... (diff)
downloadlibredirect-0af6eac7d297ef801d4c4930f22a3a045ca016c9.zip
Added a chosen info for chosen instances from the public list https://github.com/libredirect/browser_extension/issues/754
Diffstat (limited to 'src/pages/options/index.js')
-rw-r--r--src/pages/options/index.js24
1 files changed, 16 insertions, 8 deletions
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) {
                         <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>
@@ -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)
+						})
 					}
 				})
 		}