aboutsummaryrefslogtreecommitdiffstats
path: root/src/assets
diff options
context:
space:
mode:
Diffstat (limited to 'src/assets')
-rw-r--r--src/assets/images/sendTargets-icon.svg3
-rw-r--r--src/assets/javascripts/services.js36
-rw-r--r--src/assets/javascripts/utils.js124
3 files changed, 87 insertions, 76 deletions
diff --git a/src/assets/images/sendTargets-icon.svg b/src/assets/images/sendTargets-icon.svg
deleted file mode 100644
index 5557664e..00000000
--- a/src/assets/images/sendTargets-icon.svg
+++ /dev/null
@@ -1,3 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
- <path d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z"></path>
-</svg>
diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js
index 49af6d1f..404962ee 100644
--- a/src/assets/javascripts/services.js
+++ b/src/assets/javascripts/services.js
@@ -391,7 +391,7 @@ function redirect(url, type, initiator) {
}
}
-function initDefaults() {
+async function initDefaults() {
return new Promise(async resolve => {
fetch("/instances/data.json")
.then(response => response.text())
@@ -400,13 +400,12 @@ function initDefaults() {
let redirects = JSON.parse(data)
let options = r.options
let targets = {}
- // let latency = {}
+ const localstorage = {}
+ const latency = {}
for (const service in config.services) {
options[service] = {}
- // latency[service] = {}
if (config.services[service].targets == "datajson") {
targets[service] = redirects[service]
- //delete dataJson[service]
}
for (const defaultOption in config.services[service].options) {
options[service][defaultOption] = config.services[service].options[defaultOption]
@@ -416,11 +415,11 @@ function initDefaults() {
options[frontend] = {}
for (const network in config.networks) {
options[frontend][network] = {}
- options[frontend][network].enabled = redirects[frontend][network]
+ options[frontend][network].enabled = JSON.parse(data)[frontend][network]
options[frontend][network].custom = []
}
for (const blacklist in r.blacklists) {
- for (const instance of blacklist) {
+ for (const instance of r.blacklists[blacklist]) {
let i = options[frontend].clearnet.enabled.indexOf(instance)
if (i > -1) options[frontend].clearnet.enabled.splice(i, 1)
}
@@ -428,7 +427,7 @@ function initDefaults() {
}
}
}
- browser.storage.local.set({ redirects, options, targets /*, latency*/ })
+ browser.storage.local.set({ redirects, options, targets, latency, localstorage })
resolve()
})
})
@@ -449,7 +448,8 @@ function computeService(url, returnFrontend) {
}
}
}
- return null
+ if (returnFrontend) return [null, null]
+ else return null
}
function switchInstance(url) {
@@ -515,7 +515,7 @@ function reverse(url) {
})
}
-function unifyPreferences(url) {
+function unifyPreferences(url, tabId) {
return new Promise(async resolve => {
// await init()
// await getConfig()
@@ -539,7 +539,23 @@ function unifyPreferences(url) {
await utils.copyCookie(currentFrontend, url, instancesList, cookie)
}
}
- if ("localStorage" in frontend.preferences) {
+ if ("localstorage" in frontend.preferences) {
+ browser.tabs.executeScript(tabId, {
+ code: "const frontend = " + frontend,
+ code: "const items = " + config.services[currentService].frontends[currentFrontend].preferences.localStorage,
+ //file: "/assets/javascripts/get-localstorage.js",
+ runAt: "document_start",
+ })
+
+ for (const instance of instancesList)
+ browser.tabs.create({ url: instance }, tab =>
+ browser.tabs.executeScript(tab.id, {
+ code: "const frontend = " + frontend,
+ code: "const items = " + config.services[currentService].frontends[currentFrontend].preferences.localStorage,
+ file: "/assets/javascripts/set-localstorage.js",
+ runAt: "document_start",
+ })
+ )
}
if ("indexeddb" in frontend.preferences) {
}
diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js
index 186fae43..a1c559df 100644
--- a/src/assets/javascripts/utils.js
+++ b/src/assets/javascripts/utils.js
@@ -59,27 +59,26 @@ function protocolHost(url) {
return `${url.protocol}//${url.host}`
}
-async function processDefaultCustomInstances(service, name, network, document) {
+async function processDefaultCustomInstances(service, frontend, network, document) {
let instancesLatency
- let nameNetworkElement = document.getElementById(name).getElementsByClassName(network)[0]
+ let frontendNetworkElement = document.getElementById(frontend).getElementsByClassName(network)[0]
- let nameCustomInstances = []
- let nameCheckListElement = nameNetworkElement.getElementsByClassName("checklist")[0]
+ let frontendCustomInstances = []
+ let frontendCheckListElement = frontendNetworkElement.getElementsByClassName("checklist")[0]
await initBlackList()
- let nameDefaultRedirects
+ let frontendDefaultRedirects
let redirects, options
async function getFromStorage() {
return new Promise(async resolve =>
browser.storage.local.get(["options", "redirects", "latency"], r => {
- nameDefaultRedirects = r.options[name][network].enabled
- nameCustomInstances = r.options[name][network].custom
+ frontendDefaultRedirects = r.options[frontend][network].enabled
+ frontendCustomInstances = r.options[frontend][network].custom
options = r.options
- if (r.latency) instancesLatency = r.latency[name] ?? []
- else instancesLatency = []
+ instancesLatency = r.latency[frontend] ?? []
redirects = r.redirects
resolve()
})
@@ -88,27 +87,26 @@ async function processDefaultCustomInstances(service, name, network, document) {
await getFromStorage()
- function calcNameCheckBoxes() {
+ function calcFrontendCheckBoxes() {
let isTrue = true
- for (const item of redirects[name][network]) {
- if (nameDefaultRedirects === undefined) console.log(name + network + " is undefined")
- if (!nameDefaultRedirects.includes(item)) {
+ for (const item of redirects[frontend][network]) {
+ if (!frontendDefaultRedirects.includes(item)) {
isTrue = false
break
}
}
- for (const element of nameCheckListElement.getElementsByTagName("input")) {
- element.checked = nameDefaultRedirects.includes(element.className)
+ for (const element of frontendCheckListElement.getElementsByTagName("input")) {
+ element.checked = frontendDefaultRedirects.includes(element.className)
}
- if (nameDefaultRedirects.length == 0) isTrue = false
- nameNetworkElement.getElementsByClassName("toggle-all")[0].checked = isTrue
+ if (frontendDefaultRedirects.length == 0) isTrue = false
+ frontendNetworkElement.getElementsByClassName("toggle-all")[0].checked = isTrue
}
- nameCheckListElement.innerHTML = [
+ frontendCheckListElement.innerHTML = [
`<div>
<x data-localise="__MSG_toggleAll__">Toggle All</x>
<input type="checkbox" class="toggle-all"/>
</div>`,
- ...redirects[name][network].map(x => {
+ ...redirects[frontend][network].map(x => {
const cloudflare = cloudflareBlackList.includes(x) ? ' <span style="color:red;">cloudflare</span>' : ""
const authenticate = authenticateBlackList.includes(x) ? ' <span style="color:orange;">authenticate</span>' : ""
const offline = offlineBlackList.includes(x) ? ' <span style="color:grey;">offline</span>' : ""
@@ -132,33 +130,33 @@ async function processDefaultCustomInstances(service, name, network, document) {
localise.localisePage()
- calcNameCheckBoxes()
- nameNetworkElement.getElementsByClassName("toggle-all")[0].addEventListener("change", async event => {
- if (event.service.checked) nameDefaultRedirects = [...redirects[name][network]]
- else nameDefaultRedirects = []
+ calcFrontendCheckBoxes()
+ frontendNetworkElement.getElementsByClassName("toggle-all")[0].addEventListener("change", async event => {
+ if (event.target.checked) frontendDefaultRedirects = [...redirects[frontend][network]]
+ else frontendDefaultRedirects = []
- options[service][network].enabled = nameDefaultRedirects
+ options[frontend][network].enabled = frontendDefaultRedirects
browser.storage.local.set({ options })
- calcNameCheckBoxes()
+ calcFrontendCheckBoxes()
})
- for (let element of nameCheckListElement.getElementsByTagName("input")) {
+ for (let element of frontendCheckListElement.getElementsByTagName("input")) {
if (element.className != "toggle-all")
- nameNetworkElement.getElementsByClassName(element.className)[0].addEventListener("change", async event => {
- if (event.service.checked) nameDefaultRedirects.push(element.className)
+ frontendNetworkElement.getElementsByClassName(element.className)[0].addEventListener("change", async event => {
+ if (event.target.checked) frontendDefaultRedirects.push(element.className)
else {
- let index = nameDefaultRedirects.indexOf(element.className)
- if (index > -1) nameDefaultRedirects.splice(index, 1)
+ let index = frontendDefaultRedirects.indexOf(element.className)
+ if (index > -1) frontendDefaultRedirects.splice(index, 1)
}
- options[service][network].enabled = nameDefaultRedirects
+ options[frontend][network].enabled = frontendDefaultRedirects
browser.storage.local.set({ options })
- calcNameCheckBoxes()
+ calcFrontendCheckBoxes()
})
}
- function calcNameCustomInstances() {
- nameNetworkElement.getElementsByClassName("custom-checklist")[0].innerHTML = nameCustomInstances
+ function calcFrontendCustomInstances() {
+ frontendNetworkElement.getElementsByClassName("custom-checklist")[0].innerHTML = frontendCustomInstances
.map(
x => `<div>
${x}
@@ -172,30 +170,30 @@ async function processDefaultCustomInstances(service, name, network, document) {
)
.join("\n")
- for (const item of nameCustomInstances) {
- nameNetworkElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => {
- let index = nameCustomInstances.indexOf(item)
- if (index > -1) nameCustomInstances.splice(index, 1)
- options[service][network].custom = nameCustomInstances
+ for (const item of frontendCustomInstances) {
+ frontendNetworkElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => {
+ let index = frontendCustomInstances.indexOf(item)
+ if (index > -1) frontendCustomInstances.splice(index, 1)
+ options[frontend][network].custom = frontendCustomInstances
browser.storage.local.set({ options })
- calcNameCustomInstances()
+ calcFrontendCustomInstances()
})
}
}
- calcNameCustomInstances()
- nameNetworkElement.getElementsByClassName("custom-instance-form")[0].addEventListener("submit", async event => {
+ calcFrontendCustomInstances()
+ frontendNetworkElement.getElementsByClassName("custom-instance-form")[0].addEventListener("submit", async event => {
event.preventDefault()
- let nameCustomInstanceInput = nameNetworkElement.getElementsByClassName("custom-instance")[0]
- let url = new URL(nameCustomInstanceInput.value)
+ let frontendCustomInstanceInput = frontendNetworkElement.getElementsByClassName("custom-instance")[0]
+ let url = new URL(frontendCustomInstanceInput.value)
let protocolHostVar = protocolHost(url)
- if (nameCustomInstanceInput.validity.valid && !redirects[name][network].includes(protocolHostVar)) {
- if (!nameCustomInstances.includes(protocolHostVar)) {
- nameCustomInstances.push(protocolHostVar)
- options[service][network].custom = nameCustomInstances
+ if (frontendCustomInstanceInput.validity.valid && !redirects[frontend][network].includes(protocolHostVar)) {
+ if (!frontendCustomInstances.includes(protocolHostVar)) {
+ frontendCustomInstances.push(protocolHostVar)
+ options[frontend][network].custom = frontendCustomInstances
browser.storage.local.set({ options })
- nameCustomInstanceInput.value = ""
+ frontendCustomInstanceInput.value = ""
}
- calcNameCustomInstances()
+ calcFrontendCustomInstances()
}
})
}
@@ -245,11 +243,12 @@ function pingOnce(href) {
async function testLatency(element, instances, frontend) {
return new Promise(async resolve => {
let myList = {}
- let latencyThreshold
- let redirectsChecks = []
+ let latencyThreshold, options
+ //let redirectsChecks = []
browser.storage.local.get(["options"], r => {
latencyThreshold = r.options.latencyThreshold
- redirectsChecks = r.options[frontend].clearnet.enabled
+ //redirectsChecks = r.options[frontend].clearnet.enabled
+ options = r.options
})
for (const href of instances)
await ping(href).then(time => {
@@ -261,11 +260,9 @@ async function testLatency(element, instances, frontend) {
else color = "red"
if (time > latencyThreshold) {
- redirectsChecks.splice(redirectsChecks.indexOf(href), 1)
+ options[frontend].clearnet.enabled.splice(options[frontend].clearnet.enabled.indexOf(href), 1)
}
- browser.storage.local.set({ [`${frontend}ClearnetRedirectsChecks`]: redirectsChecks })
-
let text
if (time == 5000) text = "5000ms+"
else if (time > 5000) text = `ERROR: ${time - 5000}`
@@ -273,6 +270,7 @@ async function testLatency(element, instances, frontend) {
element.innerHTML = `${href}:&nbsp;<span style="color:${color};">${text}</span>`
}
})
+ browser.storage.local.set({ options })
resolve(myList)
})
}
@@ -386,7 +384,7 @@ function unify() {
return
}
- let result = await servicesHelper.unifyPreferences(url)
+ let result = await servicesHelper.unifyPreferences(url, currTab.id)
resolve(result)
}
@@ -417,21 +415,21 @@ function switchInstance(test) {
})
}
-function latency(name, frontend, document, location) {
+function latency(service, frontend, document, location) {
let latencyElement = document.getElementById(`latency-${frontend}`)
let latencyLabel = document.getElementById(`latency-${frontend}-label`)
latencyElement.addEventListener("click", async () => {
let reloadWindow = () => location.reload()
latencyElement.addEventListener("click", reloadWindow)
- let key = `${name} Redirects`
- browser.storage.local.get(key, r => {
- let redirects = r[key]
+ browser.storage.local.get(["redirects", "latency"], r => {
+ let redirects = r.redirects
const oldHtml = latencyLabel.innerHTML
latencyLabel.innerHTML = "..."
testLatency(latencyLabel, redirects[frontend].clearnet, frontend).then(r => {
- browser.storage.local.set({ [`${frontend}Latency`]: r })
+ latency[frontend] = r
+ browser.storage.local.set({ latency })
latencyLabel.innerHTML = oldHtml
- processDefaultCustomInstances(name, frontend, "clearnet", document)
+ processDefaultCustomInstances(service, frontend, "clearnet", document)
latencyElement.removeEventListener("click", reloadWindow)
})
})