From d86fecab3f3e98a87d6e8af8879c036f9da44779 Mon Sep 17 00:00:00 2001 From: Hygna Date: Wed, 21 Sep 2022 20:38:30 +0100 Subject: [PATCH] 100% compat with widgets/.js --- src/assets/javascripts/services.js | 2 +- src/config/config.json | 2 +- src/pages/options/index.html | 134 +++++++++++++++++++++---- src/pages/options/widgets/general.ejs | 10 +- src/pages/options/widgets/general.js | 24 ++--- src/pages/options/widgets/services.ejs | 20 ++-- src/pages/options/widgets/services.js | 71 ++++++++----- 7 files changed, 188 insertions(+), 75 deletions(-) diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index fff3227..7944444 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -385,7 +385,7 @@ function initDefaults() { .then(response => response.text()) .then(async data => { let dataJson = JSON.parse(data) - redirects = dataJson + redirects = dataJson.slice() browser.storage.local.get(["cloudflareBlackList", "authenticateBlackList", "offlineBlackList"], async r => { for (const service in config.services) { if (config.services[service].targets == "datajson") { diff --git a/src/config/config.json b/src/config/config.json index d0bf7ed..ac393f1 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -180,7 +180,7 @@ "setEndpoint": "/applysettings" }, "name": "Bibliogram", - "instanceList": false + "instanceList": true } }, "targets": ["^https?:\\/{2}(www\\.)?instagram\\.com"], diff --git a/src/pages/options/index.html b/src/pages/options/index.html index df6bec2..e1163e9 100644 --- a/src/pages/options/index.html +++ b/src/pages/options/index.html @@ -46,8 +46,8 @@
-

- @@ -55,10 +55,10 @@
-
+
-

Fallback to normal if no instances are available for the current protocol

- +

Fallback to normal if no instances are available for the current network

+
@@ -254,15 +254,13 @@
-
-

Embed Frontend

- -
+

Embed Frontend

+

Redirect Type

@@ -998,7 +996,103 @@

- +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+ + +
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+ +
+
@@ -2095,14 +2189,12 @@
-
-

Embed Frontend

- -
+

Embed Frontend

+

Redirect Type

diff --git a/src/pages/options/widgets/general.ejs b/src/pages/options/widgets/general.ejs index d68a228..e306ba4 100644 --- a/src/pages/options/widgets/general.ejs +++ b/src/pages/options/widgets/general.ejs @@ -12,17 +12,17 @@
-

- <% for (const network in config.networks) { -%> <% }; %>
-
+
-

Fallback to normal if no instances are available for the current protocol

- +

Fallback to normal if no instances are available for the current network

+
diff --git a/src/pages/options/widgets/general.js b/src/pages/options/widgets/general.js index e573b4e..9dac9bf 100644 --- a/src/pages/options/widgets/general.js +++ b/src/pages/options/widgets/general.js @@ -86,15 +86,15 @@ themeElement.addEventListener("change", event => { location.reload() }) -let protocolElement = document.getElementById("protocol") -protocolElement.addEventListener("change", event => { - const value = event.target.options[protocol.selectedIndex].value +let networkElement = document.getElementById("network") +networkElement.addEventListener("change", event => { + const value = event.target.options[network.selectedIndex].value browser.storage.local.set({ network: value }) location.reload() }) -let protocolFallbackCheckbox = document.getElementById("protocol-fallback-checkbox") -protocolFallbackCheckbox.addEventListener("change", event => { +let networkFallbackCheckbox = document.getElementById("network-fallback-checkbox") +networkFallbackCheckbox.addEventListener("change", event => { browser.storage.local.set({ networkFallback: event.target.checked }) }) @@ -138,16 +138,16 @@ browser.storage.local.get( r => { autoRedirectElement.checked = r.autoRedirect themeElement.value = r.theme - protocolElement.value = r.network - protocolFallbackCheckbox.checked = r.networkFallback + networkElement.value = r.network + networkFallbackCheckbox.checked = r.networkFallback latencyOutput.value = r.latencyThreshold // firstPartyIsolate.checked = r.firstPartyIsolate; - let protocolFallbackElement = document.getElementById("protocol-fallback") - if (protocolElement.value == "clearnet") { - protocolFallbackElement.style.display = "none" + let networkFallbackElement = document.getElementById("network-fallback") + if (networkElement.value == "clearnet") { + networkFallbackElement.style.display = "none" } else { - protocolFallbackElement.style.display = "block" + networkFallbackElement.style.display = "block" } instanceTypeElement.addEventListener("change", event => { @@ -200,7 +200,7 @@ browser.storage.local.get( if (instanceType == "url") { if (nameCustomInstanceInput.validity.valid) { let url = new URL(nameCustomInstanceInput.value) - val = `${url.protocol}//${url.host}` + val = `${url.network}//${url.host}` if (!exceptionsCustomInstances.url.includes(val)) exceptionsCustomInstances.url.push(val) } } else if (instanceType == "regex") { diff --git a/src/pages/options/widgets/services.ejs b/src/pages/options/widgets/services.ejs index bc75f28..44c6a9f 100644 --- a/src/pages/options/widgets/services.ejs +++ b/src/pages/options/widgets/services.ejs @@ -18,17 +18,15 @@
<% if (config.services[service].embeddable) { _%> -
-
-

Embed Frontend

- -
+
+

Embed Frontend

+
<% } _%> <% } _%> diff --git a/src/pages/options/widgets/services.js b/src/pages/options/widgets/services.js index 33c174f..69840de 100644 --- a/src/pages/options/widgets/services.js +++ b/src/pages/options/widgets/services.js @@ -16,19 +16,22 @@ function getConfig() { }) } -await getConfig() +function getNetwork() { + return new Promise(resolve => { + browser.storage.local.get("network", r => { + selectedNetwork = r.network + resolve() + }) + }) +} -browser.storage.local.get("network", r => { - selectedNetwork = r.network -}) +await getConfig() +await getNetwork() function changeFrontendsSettings(service) { for (const frontend in config.services[service].frontends) { - if (config.services[service].frontends[frontend].instanceList && config.services[service].frontends.length > 1) { + if (config.services[service].frontends[frontend].instanceList) { const frontendDiv = document.getElementById(frontend) - if (divs[service].frontend == null) { - console.log(frontend) - } if (frontend == divs[service].frontend.value) { frontendDiv.style.display = "block" } else { @@ -36,25 +39,43 @@ function changeFrontendsSettings(service) { } } } + + if (config.services[service].embeddable) { + if (!config.services[service].frontends[divs[service].frontend.value].instanceList) { + divs[service].embedFrontend.disabled = false + for (const frontend in config.services[service].frontends) { + if (config.services[service].frontends[frontend].embeddable) { + const frontendDiv = document.getElementById(frontend) + if (frontend == divs[service].embedFrontend.value) { + frontendDiv.style.display = "block" + } else { + frontendDiv.style.display = "none" + } + } + } + } else if (Object.keys(config.services[service].frontends) > 1) divs[service].embedFrontend.disabled = true + } } -function changeNetworkSettings(selectedNetwork) { - for (const frontend in config.frontends) { - if (config.services[service].frontends[frontend].instanceList) { - const frontendDiv = document.getElementById(frontend) - for (const network in config.networks) { - const networkDiv = frontendDiv.getElementsByClassName(network)[0] - if (network == selectedNetwork) { - networkDiv.style.display = "block" - } else { - networkDiv.style.display = "none" +function changeNetworkSettings() { + for (const service in config.services) { + for (const frontend in config.services[service].frontends) { + if (config.services[service].frontends[frontend].instanceList) { + const frontendDiv = document.getElementById(frontend) + for (const network in config.networks) { + const networkDiv = frontendDiv.getElementsByClassName(network)[0] + if (network == selectedNetwork) { + networkDiv.style.display = "block" + } else { + networkDiv.style.display = "none" + } } } } } } -changeNetworkSettings(selectedNetwork) +changeNetworkSettings() for (const service in config.services) { divs[service] = {} divs[service][service] = document.getElementById(`${service}_page`) @@ -62,18 +83,20 @@ for (const service in config.services) { divs[service][option] = document.getElementById(`${service}-${option}`) browser.storage.local.get([`${service + utils.camelCase(option)}`], r => { - if (typeof config.services[service].options[option] == "boollean") divs[service][option].checked = r[service + utils.camelCase(option)] - else divs[service][option].value = !r[service + utils.camelCase(option)] + if (typeof config.services[service].options[option] == "boolean") divs[service][option].checked = r[service + utils.camelCase(option)] + else divs[service][option].value = r[service + utils.camelCase(option)] }) divs[service][option].addEventListener("change", () => { - if (typeof config.services[service].options[option] == "boollean") browser.storage.local.set({ [service + utils.camelCase(option)]: divs[service][option].checked }) + if (typeof config.services[service].options[option] == "boolean") browser.storage.local.set({ [service + utils.camelCase(option)]: divs[service][option].checked }) else browser.storage.local.set({ [service + utils.camelCase(option)]: divs[service][option].value }) - changeFrontendsSettings() + changeFrontendsSettings(service) }) } - changeFrontendsSettings(service) + if (Object.keys(config.services[service].frontends).length > 1) { + changeFrontendsSettings(service) + } for (const frontend in config.services[service].frontends) { if (config.services[service].frontends[frontend].instanceList) {