Added Custom service function for https://github.com/libredirect/browser_extension/issues/767
This commit is contained in:
parent
1aa49d26e2
commit
5ca505080e
|
@ -565,15 +565,20 @@ function computeService(url, returnFrontend) {
|
|||
})
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
function switchInstance(url, customService) {
|
||||
return new Promise(async resolve => {
|
||||
let options = await utils.getOptions()
|
||||
let config = await utils.getConfig()
|
||||
|
||||
const protocolHost = utils.protocolHost(url)
|
||||
if (customService) {
|
||||
const instancesList = options[options[customService].frontend]
|
||||
if (instancesList !== undefined) {
|
||||
resolve(`${utils.getRandomInstance(instancesList)}${url.pathname}${url.search}`)
|
||||
}
|
||||
} else {
|
||||
for (const service in config.services) {
|
||||
let frontend = options[service].frontend
|
||||
let instancesList = options[frontend]
|
||||
let instancesList = options[options[service].frontend]
|
||||
if (instancesList === undefined) continue
|
||||
if (!instancesList.includes(protocolHost)) continue
|
||||
|
||||
|
@ -582,12 +587,10 @@ function switchInstance(url) {
|
|||
resolve()
|
||||
return
|
||||
}
|
||||
|
||||
const randomInstance = utils.getRandomInstance(instancesList)
|
||||
const newUrl = `${randomInstance}${url.pathname}${url.search}`
|
||||
resolve(newUrl)
|
||||
resolve(`${utils.getRandomInstance(instancesList)}${url.pathname}${url.search}`)
|
||||
return
|
||||
}
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue