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