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 @@ - - - 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 = [ `
Toggle All
`, - ...redirects[name][network].map(x => { + ...redirects[frontend][network].map(x => { const cloudflare = cloudflareBlackList.includes(x) ? ' cloudflare' : "" const authenticate = authenticateBlackList.includes(x) ? ' authenticate' : "" const offline = offlineBlackList.includes(x) ? ' offline' : "" @@ -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 => `
${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}: ${text}` } }) + 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) }) }) diff --git a/src/config/config.json b/src/config/config.json index e2b511b9..b15c20d4 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -48,7 +48,8 @@ "sponsorblock", "theme", "volume", - "watchHistory" + "watchHistory", + "localSubscriptions" ] }, "name": "Piped", @@ -490,13 +491,13 @@ }, "lingva": { "preferences": { - "localstorage": ["isauto", "source", "target"] + "localstorage": ["isauto", "source", "target", "chakra-ui-color-mode"] }, - "name": "Lingva", + "name": "Lingva Translate", "instanceList": true } }, - "targets": ["^https?:\\/{2}translate\\.google(\\.[a-z]{2,3}){1,2}\\/"], + "targets": ["^https?:\\/{2}translate\\.google(\\.[a-z]{2,3}){1,2}\\/", "^https?:\\/{2}translate\\.libredirect\\.invalid"], "name": "Translate", "options": { "enabled": true, @@ -504,7 +505,7 @@ }, "imageType": "svgMono", "embeddable": false, - "url": "https://translate.google.com" + "url": "https://translate.libredirect.invalid" }, "maps": { "frontends": { @@ -518,7 +519,7 @@ "singleInstance": "https://www.openstreetmap.org" } }, - "targets": ["^https?:\\/{2}(((www|maps)\\.)?(google\\.).*(\\/maps)|maps\\.(google\\.).*)"], + "targets": ["^https?:\\/{2}maps\\.libredirect\\.invalid", "^https?:\\/{2}(((www|maps)\\.)?(google\\.).*(\\/maps)|maps\\.(google\\.).*)"], "name": "Maps", "options": { "enabled": true, @@ -526,16 +527,16 @@ }, "imageType": "svgMono", "embeddable": false, - "url": "https://maps.google.com" + "url": "https://maps.libredirect.invalid" }, - "sendTargets": { + "uploadFiles": { "frontends": { "send": { "name": "Send", "instanceList": "true" } }, - "targets": ["^https?:\\/{2}send\\.libredirect\\.invalid\\/?$", "^https?:\\/{2}send\\.firefox\\.com\\/?$", "^https?:\\/{2}sendfiles\\.online\\/?$"], + "targets": ["^https?:\\/{2}send\\.libredirect\\.invalid", "^https?:\\/{2}send\\.firefox\\.com\\/?$", "^https?:\\/{2}sendfiles\\.online\\/?$"], "name": "Send Files", "options": { "enabled": true }, "imageType": "svgMono", diff --git a/src/pages/background/background.js b/src/pages/background/background.js index e9bf691f..3a900609 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -6,20 +6,7 @@ import servicesHelper from "../../assets/javascripts/services.js" window.browser = window.browser || window.chrome -browser.runtime.onInstalled.addListener(details => { - function initDefaults() { - fetch("/instances/blacklist.json") - .then(response => response.text()) - .then(async data => { - browser.storage.local.clear(() => { - browser.storage.local.set({ blacklists: JSON.parse(data) }, () => { - generalHelper.initDefaults() - servicesHelper.initDefaults() - }) - }) - }) - } - +browser.runtime.onInstalled.addListener(async details => { // if (details.reason == 'install' || (details.reason == "update" && details.previousVersion != browser.runtime.getManifest().version)) { // if (details.reason == "update") // browser.storage.local.get(null, r => { @@ -38,12 +25,25 @@ browser.runtime.onInstalled.addListener(details => { case "update": switch (details.previousVersion) { case "2.2.1": - //do stuff + initDefaults() break } } }) +function initDefaults() { + browser.storage.local.clear(() => { + fetch("/instances/blacklist.json") + .then(response => response.text()) + .then(async data => { + browser.storage.local.set({ blacklists: JSON.parse(data) }, async () => { + await generalHelper.initDefaults() + await servicesHelper.initDefaults() + }) + }) + }) +} + let BYPASSTABs = [] browser.webRequest.onBeforeRequest.addListener( details => { diff --git a/src/pages/options/index.html b/src/pages/options/index.html index 6ef33723..71d04fd0 100644 --- a/src/pages/options/index.html +++ b/src/pages/options/index.html @@ -84,7 +84,7 @@ - Send Files
+ Send Files
@@ -318,9 +318,9 @@ - Send Files + Send Files
- + @@ -2818,7 +2818,7 @@

Frontend

@@ -3134,14 +3134,14 @@ -
+
-

Send Files

+

Send Files


Enable

- +

diff --git a/src/pages/options/widgets/general.js b/src/pages/options/widgets/general.js index 23ed73ee..cd5cfb47 100644 --- a/src/pages/options/widgets/general.js +++ b/src/pages/options/widgets/general.js @@ -37,7 +37,6 @@ function setOption(option, multiChoice, event) { browser.storage.local.get("options", r => { let options = r.options if (multiChoice) { - console.log(event.target.options) options[option] = event.target.options[event.target.options.selectedIndex].value } else { options[option] = event.target.checked @@ -95,6 +94,7 @@ resetSettings.addEventListener("click", async () => { .then(response => response.text()) .then(async data => { browser.storage.local.set({ blacklists: JSON.parse(data) }, async () => { + await generalHelper.initDefaults() await servicesHelper.initDefaults() location.reload() }) diff --git a/src/pages/options/widgets/services.js b/src/pages/options/widgets/services.js index 873950f3..98e068a1 100644 --- a/src/pages/options/widgets/services.js +++ b/src/pages/options/widgets/services.js @@ -77,7 +77,7 @@ function changeNetworkSettings() { changeNetworkSettings() for (const service in config.services) { divs[service] = {} - divs[service][service] = document.getElementById(`${service}_page`) + //divs[service].page = document.getElementById(`${service}_page`) for (const option in config.services[service].options) { divs[service][option] = document.getElementById(`${service}-${option}`) diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index d52a34b6..56e4ca14 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -91,7 +91,7 @@

Search

-