diff options
author | ManeraKai <manerakai@protonmail.com> | 2023-02-08 15:51:07 +0300 |
---|---|---|
committer | ManeraKai <manerakai@protonmail.com> | 2023-02-08 15:51:07 +0300 |
commit | 356fd321d9a035c9c4d0f5b6bb8313cf1d4ca64d (patch) | |
tree | 7351cc426a35e5b5086a00c36c0b808e8b3891f7 /src/assets | |
parent | Link menu: Redirect, Reverse, Copy Reverse. Icon menu: Settings, SwitchInstan... (diff) | |
download | libredirect-356fd321d9a035c9c4d0f5b6bb8313cf1d4ca64d.zip |
Added option to use github, codeberg, disable for fetching instances https://github.com/libredirect/libredirect/issues/626
Diffstat (limited to 'src/assets')
-rw-r--r-- | src/assets/javascripts/services.js | 40 | ||||
-rw-r--r-- | src/assets/javascripts/utils.js | 46 |
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) }) } |