about summary refs log tree commit diff stats
path: root/src/assets
diff options
context:
space:
mode:
Diffstat (limited to 'src/assets')
-rw-r--r--src/assets/javascripts/services.js40
-rw-r--r--src/assets/javascripts/utils.js46
2 files changed, 45 insertions, 41 deletions
diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js
index 2b630d6d..3e05f047 100644
--- a/src/assets/javascripts/services.js
+++ b/src/assets/javascripts/services.js
@@ -618,6 +618,7 @@ function initDefaults() {
 			}
 			options['theme'] = "detect"
 			options['popupServices'] = ["youtube", "twitter", "tiktok", "imgur", "reddit", "quora", "translate", "maps"]
+			options['fetchInstances'] = 'github'
 
 			options = { ...options, ...defaultInstances }
 
@@ -631,45 +632,10 @@ function initDefaults() {
 function upgradeOptions() {
 	return new Promise(async resolve => {
 		const oldOptions = await utils.getOptions()
-		const config = await utils.getConfig()
 
 		let options = {}
-
-		options.exceptions = oldOptions.exceptions
-		options.theme = oldOptions.theme
-		options.popupServices = oldOptions.popupServices
-
-		for (const service in config.services) {
-			if (service in oldOptions) {
-				options[service] = oldOptions[service]
-				delete options[service].embedFrontend
-			}
-			else {
-				options[service] = {}
-				for (const defaultOption in config.services[service].options) {
-					options[service][defaultOption] = config.services[service].options[defaultOption]
-				}
-				for (const frontend in config.services[service].frontends) {
-					if (config.services[service].frontends[frontend].instanceList) {
-						options[frontend] = []
-					}
-				}
-			}
-
-			for (const frontend in config.services[service].frontends) {
-				if (config.services[service].frontends[frontend].instanceList) {
-					if (frontend in oldOptions) {
-						options[frontend] = [
-							...oldOptions[frontend].clearnet.enabled,
-							...oldOptions[frontend].clearnet.custom
-						]
-					}
-					else {
-						options[frontend] = defaultInstances[frontend]
-					}
-				}
-			}
-		}
+		options = [...oldOptions]
+		options.fetchInstances = 'github'
 
 		browser.storage.local.clear(() => {
 			browser.storage.local.set({ options }, () => {
diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js
index 2b9a9193..6644f8ed 100644
--- a/src/assets/javascripts/utils.js
+++ b/src/assets/javascripts/utils.js
@@ -32,30 +32,68 @@ function getOptions() {
 	)
 }
 
-function getBlacklist() {
+function getBlacklist(options) {
 	return new Promise(resolve => {
+		let url
+		if (options.fetchInstances == 'github') {
+			url = 'https://raw.githubusercontent.com/libredirect/instances/main/blacklist.json'
+		}
+		else if (options.fetchInstances == 'codeberg') {
+			url = 'https://codeberg.org/LibRedirect/instances/raw/branch/main/blacklist.json'
+		}
+		else {
+			resolve('disabled')
+			return
+		}
 		const http = new XMLHttpRequest()
-		http.open("GET", "https://raw.githubusercontent.com/libredirect/instances/main/blacklist.json", true)
+		http.open("GET", url, true)
 		http.onreadystatechange = () => {
 			if (http.status === 200 && http.readyState == XMLHttpRequest.DONE) {
 				resolve(JSON.parse(http.responseText))
 				return
 			}
 		}
+		http.onerror = () => {
+			resolve()
+			return
+		}
+		http.ontimeout = () => {
+			resolve()
+			return
+		}
 		http.send(null)
 	})
 }
 
-function getList() {
+function getList(options) {
 	return new Promise(resolve => {
+		let url
+		if (options.fetchInstances == 'github') {
+			url = 'https://raw.githubusercontent.com/libredirect/instances/main/data.json'
+		}
+		else if (options.fetchInstances == 'codeberg') {
+			url = 'https://codeberg.org/LibRedirect/instances/raw/branch/main/data.json'
+		}
+		else {
+			resolve('disabled')
+			return
+		}
 		const http = new XMLHttpRequest()
-		http.open("GET", "https://raw.githubusercontent.com/libredirect/instances/main/data.json", true)
+		http.open("GET", url, true)
 		http.onreadystatechange = () => {
 			if (http.status === 200 && http.readyState == XMLHttpRequest.DONE) {
 				resolve(JSON.parse(http.responseText))
 				return
 			}
 		}
+		http.onerror = () => {
+			resolve()
+			return
+		}
+		http.ontimeout = () => {
+			resolve()
+			return
+		}
 		http.send(null)
 	})
 }