Merge branch 'kirizdev-master'
This commit is contained in:
commit
357f97b6a4
|
@ -1,5 +1,4 @@
|
||||||
import utils from "../../assets/javascripts/utils.js"
|
import utils from "../../assets/javascripts/utils.js"
|
||||||
import localise from "../../assets/javascripts/localise.js"
|
|
||||||
|
|
||||||
let config,
|
let config,
|
||||||
options,
|
options,
|
||||||
|
@ -182,28 +181,36 @@ async function processCustomInstances(frontend, document) {
|
||||||
|
|
||||||
function createList(frontend, networks, document, redirects, blacklist) {
|
function createList(frontend, networks, document, redirects, blacklist) {
|
||||||
for (const network in networks) {
|
for (const network in networks) {
|
||||||
if (redirects[frontend]) {
|
const checklist = document.getElementById(frontend)
|
||||||
if (redirects[frontend][network].length > 0) {
|
|
||||||
document.getElementById(frontend).getElementsByClassName("custom-instance")[0].placeholder = redirects[frontend].clearnet[0]
|
|
||||||
document.getElementById(frontend)
|
|
||||||
.getElementsByClassName(network)[0]
|
.getElementsByClassName(network)[0]
|
||||||
.getElementsByClassName("checklist")[0]
|
.getElementsByClassName("checklist")[0]
|
||||||
.innerHTML = [
|
|
||||||
`<div class="some-block option-block">
|
if (!redirects[frontend]) {
|
||||||
<h4>${utils.camelCase(network)}</h4>
|
checklist.innerHTML = '<div class="some-block option-block">No instances found.</div>'
|
||||||
</div>`,
|
break
|
||||||
...redirects[frontend][network]
|
}
|
||||||
.sort((a, b) =>
|
|
||||||
(blacklist.cloudflare.includes(a) && !blacklist.cloudflare.includes(b))
|
const instances = redirects[frontend][network]
|
||||||
)
|
if (!instances || instances.length === 0) continue
|
||||||
|
|
||||||
|
document.getElementById(frontend)
|
||||||
|
.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 content = sortedInstances
|
||||||
.map(x => {
|
.map(x => {
|
||||||
const cloudflare = blacklist.cloudflare.includes(x) ?
|
const cloudflare = blacklist.cloudflare.includes(x) ?
|
||||||
` <a target="_blank" href="https://libredirect.github.io/docs.html#instances">
|
`<a target="_blank" href="https://libredirect.github.io/docs.html#instances">
|
||||||
<span style="color:red;">cloudflare</span>
|
<span style="color:red;">cloudflare</span>
|
||||||
</a>` : ""
|
</a>` : ""
|
||||||
|
|
||||||
const warnings = [cloudflare].join(" ")
|
const warnings = [cloudflare].join(" ")
|
||||||
return `<div>
|
return `<div class="frontend">
|
||||||
<x>
|
<x>
|
||||||
<a href="${x}" target="_blank">${x}</a>${warnings}
|
<a href="${x}" target="_blank">${x}</a>${warnings}
|
||||||
</x>
|
</x>
|
||||||
|
@ -213,36 +220,27 @@ function createList(frontend, networks, document, redirects, blacklist) {
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</div>`
|
</div>`
|
||||||
}),
|
})
|
||||||
'<br>'
|
|
||||||
|
checklist.innerHTML = [
|
||||||
|
`<div class="some-block option-block">
|
||||||
|
<h4>${utils.camelCase(network)}</h4>
|
||||||
|
</div>`,
|
||||||
|
...content,
|
||||||
|
"<br>"
|
||||||
].join("\n<hr>\n")
|
].join("\n<hr>\n")
|
||||||
|
|
||||||
for (const x of redirects[frontend][network]) {
|
for (const instance of instances) {
|
||||||
document.getElementById(frontend)
|
checklist.getElementsByClassName(`add-${instance}`)[0]
|
||||||
.getElementsByClassName(network)[0]
|
|
||||||
.getElementsByClassName("checklist")[0]
|
|
||||||
.getElementsByClassName(`add-${x}`)[0]
|
|
||||||
.addEventListener("click", async () => {
|
.addEventListener("click", async () => {
|
||||||
let options = await utils.getOptions()
|
let options = await utils.getOptions()
|
||||||
let customInstances = options[frontend]
|
if (!options[frontend].includes(instance)) {
|
||||||
if (!customInstances.includes(x)) {
|
options[frontend].push(instance)
|
||||||
customInstances.push(x)
|
browser.storage.local.set({ options }, () => calcCustomInstances(frontend))
|
||||||
options = await utils.getOptions()
|
|
||||||
options[frontend] = customInstances
|
|
||||||
browser.storage.local.set({ options }, () => {
|
|
||||||
calcCustomInstances(frontend)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
document.getElementById(frontend).getElementsByClassName(network)[0].getElementsByClassName("checklist")[0].innerHTML =
|
|
||||||
`<div class="some-block option-block">No instances found.</div>`
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const r = window.location.href.match(/#(.*)/)
|
const r = window.location.href.match(/#(.*)/)
|
||||||
|
|
Loading…
Reference in New Issue