- <%- include('src/pages/options/widgets/general', {config: {networks, services}}) -%>
- <%- include('src/pages/options/widgets/services', {config: {networks, services}}) -%>
- <%- include('src/pages/options/widgets/about') -%>
-
-
-
-
diff --git a/src/pages/options/index.js b/src/pages/options/index.js
index 409fa5b5..a735110a 100644
--- a/src/pages/options/index.js
+++ b/src/pages/options/index.js
@@ -1,3 +1,10 @@
+import utils from "../../assets/javascripts/utils.js"
+import localise from "../../assets/javascripts/localise.js"
+
+let config,
+ options,
+ divs = {}
+
for (const a of document.getElementById("links").getElementsByTagName("a")) {
a.addEventListener("click", e => {
const path = a.getAttribute("href").replace("#", "")
@@ -6,6 +13,35 @@ for (const a of document.getElementById("links").getElementsByTagName("a")) {
})
}
+await new Promise(resolve => {
+ fetch("/config.json").then(response => response.text())
+ .then(data => {
+ config = JSON.parse(data)
+ resolve()
+ })
+})
+await new Promise(resolve => {
+ browser.storage.local.get("options", r => {
+ options = r.options
+ resolve()
+ })
+})
+
+function changeFrontendsSettings(service) {
+ for (const frontend in config.services[service].frontends) {
+ if (config.services[service].frontends[frontend].instanceList) {
+ const frontendDiv = document.getElementById(frontend)
+ if (typeof divs[service].frontend !== "undefined") {
+ if (frontend == divs[service].frontend.value) {
+ frontendDiv.style.display = "block"
+ } else {
+ frontendDiv.style.display = "none"
+ }
+ }
+ }
+ }
+}
+
function loadPage(path) {
for (const section of document.getElementById("pages").getElementsByTagName("section")) section.style.display = "none"
document.getElementById(`${path}_page`).style.display = "block"
@@ -16,8 +52,171 @@ function loadPage(path) {
let stateObj = { id: "100" }
window.history.pushState(stateObj, "Page 2", `/pages/options/index.html#${path}`)
+
+ const service = path;
+ divs[service] = {}
+ for (const option in config.services[service].options) {
+ divs[service][option] = document.getElementById(`${service}-${option}`)
+
+ if (typeof config.services[service].options[option] == "boolean") divs[service][option].checked = options[service][option]
+ else divs[service][option].value = options[service][option]
+
+ divs[service][option].addEventListener("change", () => {
+ browser.storage.local.get("options", r => {
+ let options = r.options
+ if (typeof config.services[service].options[option] == "boolean") options[service][option] = divs[service][option].checked
+ else options[service][option] = divs[service][option].value
+ browser.storage.local.set({ options })
+ 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) {
+ for (const network in config.networks) {
+ processDefaultCustomInstances(frontend, network, document)
+ }
+ }
+ }
}
const r = window.location.href.match(/#(.*)/)
if (r) loadPage(r[1])
else loadPage("general")
+
+async function processDefaultCustomInstances(frontend, network, document) {
+ let networkElement = document.getElementById(frontend).getElementsByClassName(network)[0]
+ let customInstances = []
+ let checkListElement = networkElement.getElementsByClassName("checklist")[0]
+
+ let cloudflareBlackList = []
+ let authenticateBlackList = []
+ await new Promise(resolve => {
+ fetch("/instances/blacklist.json")
+ .then(response => response.text())
+ .then(data => {
+ cloudflareBlackList = JSON.parse(data).cloudflare
+ authenticateBlackList = JSON.parse(data).authenticate
+ resolve()
+ })
+ })
+
+ let frontendDefaultRedirects
+
+ let redirects, options
+
+ await new Promise(async resolve =>
+ browser.storage.local.get(["options", "redirects",], r => {
+ frontendDefaultRedirects = r.options[frontend][network].enabled
+ customInstances = r.options[frontend][network].custom
+ options = r.options
+ redirects = r.redirects
+ resolve()
+ })
+ )
+
+ function calcCheckBoxes() {
+ for (const element of checkListElement.getElementsByTagName("input")) {
+ element.checked = frontendDefaultRedirects.includes(element.className)
+ }
+ }
+ if (redirects[frontend][network].length > 0)
+ checkListElement.innerHTML = [
+ `
+
-
-
-
General
-
-
-
-
Theme
-
-
-
-
Excluded from redirecting
-
-
-
-
-
-
-
-
-
-
Youtube
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
Frontend
-
-
-
-
Redirect Type
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
YT Music
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
Frontend
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
Instagram
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
TikTok
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Reddit
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
Frontend
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Imgur
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
Redirect Type
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Wikipedia
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Medium
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Quora
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
IMDb
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Reuters
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Fandom
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
PeerTube
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
LBRY
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
Frontend
-
-
-
-
Redirect Type
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Search
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
Frontend
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Translate
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
Frontend
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Maps
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
Frontend
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Send Files
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
Paste Text
-
-
-
-
Enable
-
-
-
-
Show in Popup
-
-
-
-
-
-
-
-
-
-
Custom Instances
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js
index 1ac804d0..b2f2c299 100644
--- a/src/pages/popup/popup.js
+++ b/src/pages/popup/popup.js
@@ -9,7 +9,7 @@ let config,
async function getConfig() {
return new Promise(resolve => {
- fetch("/config/config.json")
+ fetch("/config.json")
.then(response => response.text())
.then(data => {
config = JSON.parse(data)