diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 4dba8a7..b7ee220 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -17,10 +17,6 @@ async function getConfig() { }) } -function camelCase(str) { - return str.charAt(0).toUpperCase() + str.slice(1) -} - function init() { return new Promise(async resolve => { browser.storage.local.get(["network", "networkFallback"], r => { @@ -31,8 +27,8 @@ function init() { //cur = current for (const service in config.services) { options[service] = {} - browser.storage.local.get([`disable${camelCase(service)}`, `${service}RedirectType`, `${service}Frontend`], r => { - options[service].disabled = r["disable" + camelCase(service)] + browser.storage.local.get([`disable${utils.camelCase(service)}`, `${service}RedirectType`, `${service}Frontend`], r => { + options[service].disabled = r["disable" + utils.camelCase(service)] options[service].frontend = r[service + "Frontend"] options[service].redirectType = r[service + "RedirectType"] // console.log(r) @@ -42,11 +38,11 @@ function init() { options[frontend].checks = [] options[frontend].custom = [] for (const network in config.networks) { - browser.storage.local.get([`${frontend}${camelCase(network)}RedirectsChecks`, `${frontend}${camelCase(network)}CustomRedirects`], r => { + browser.storage.local.get([`${frontend}${utils.camelCase(network)}RedirectsChecks`, `${frontend}${utils.camelCase(network)}CustomRedirects`], r => { // console.log(r) - // console.log(`${frontend}${camelCase(network)}RedirectsChecks`) - options[frontend].checks = r[frontend + camelCase(network) + "RedirectsChecks"] - options[frontend].custom = r[frontend + camelCase(network) + "CustomRedirects"] + // console.log(`${frontend}${utils.camelCase(network)}RedirectsChecks`) + options[frontend].checks = r[frontend + utils.camelCase(network) + "RedirectsChecks"] + options[frontend].custom = r[frontend + utils.camelCase(network) + "CustomRedirects"] }) } } @@ -72,6 +68,7 @@ function redirect(url, type, initiator) { let frontend = options[service].frontend let network = options.network let networkFallback = options.networkFallback + let redirectType = options[service].redirectType if (url.pathname == "/") return for (const service in config.services) { if (options[service].disabled && !disableOverride) continue @@ -82,9 +79,9 @@ function redirect(url, type, initiator) { if (initiator && (all(service).includes(initiator.origin) || targets.includes(initiator.host))) continue if (!targets.some(rx => rx.test(url.href))) continue - if (type != options[service].redirectType && type != "both") continue + if (type != redirectType && type != "both") continue // browser.storage.local.get(`${service}Frontend`, (frontend = r[service + "Frontend"])) - let instanceList = [...[service + camelCase(network) + "RedirectsChecks"], ...[service + camelCase(network) + "CustomRedirects"]] + let instanceList = [...[service + utils.camelCase(network) + "RedirectsChecks"], ...[service + utils.camelCase(network) + "CustomRedirects"]] if (instanceList.length === 0 && networkFallback) instanceList = [...[service + "ClearnetRedirectsChecks"], ...[service + "ClearnetCustomRedirects"]] if (instanceList.length === 0 && redirects.indexOf(frontend) != -1) return randomInstance = utils.getRandomInstance(instanceList) @@ -400,13 +397,13 @@ function initDefaults() { browser.storage.local.set({ [defaultOption]: config.services[service].defaults[defaultOption] }) } for (const frontend in config.services[service].frontends) { - let clearnetChecks = redirects[frontend][clearnet] + let clearnetChecks = redirects[frontend].clearnet for (const instance of [...r.cloudflareBlackList, ...r.authenticateBlackList, ...r.offlineBlackList]) { let i = clearnetChecks.indexOf(instance) if (i > -1) clearnetChecks.splice(i, 1) } for (const network in config.networks) { - console.log(redirects[frontend][network]) + // console.log(redirects[frontend][network]) switch (network) { case "clearnet": browser.storage.local.set({ @@ -416,8 +413,8 @@ function initDefaults() { break default: browser.storage.local.set({ - [frontend + camelCase(network) + "RedirectsChecks"]: [...redirects[frontend][network]], - [frontend + camelCase(network) + "CustomRedirects"]: [], + [frontend + utils.camelCase(network) + "RedirectsChecks"]: [...redirects[frontend][network]], + [frontend + utils.camelCase(network) + "CustomRedirects"]: [], }) } } diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js index 50ada76..9c5947a 100644 --- a/src/assets/javascripts/utils.js +++ b/src/assets/javascripts/utils.js @@ -123,17 +123,16 @@ async function processDefaultCustomInstances(target, name, protocol, document) { let redirectsChecks = `${name}${camelCase(protocol)}RedirectsChecks` let customRedirects = `${name}${camelCase(protocol)}CustomRedirects` - let redirectsKey = `${target}Redirects` let redirects async function getFromStorage() { return new Promise(async resolve => - browser.storage.local.get([redirectsChecks, customRedirects, redirectsKey, latencyKey], r => { + browser.storage.local.get([redirectsChecks, customRedirects, "redirects", latencyKey], r => { nameDefaultRedirects = r[redirectsChecks] nameCustomInstances = r[customRedirects] instancesLatency = r[latencyKey] ?? [] - redirects = r[redirectsKey] + redirects = r.redirects resolve() }) ) @@ -298,9 +297,9 @@ async function testLatency(element, instances, frontend) { let myList = {} let latencyThreshold let redirectsChecks = [] - browser.storage.local.get(["latencyThreshold", `${frontend}NormalRedirectsChecks`], r => { + browser.storage.local.get(["latencyThreshold", `${frontend}ClearnetRedirectsChecks`], r => { latencyThreshold = r.latencyThreshold - redirectsChecks = r[`${frontend}NormalRedirectsChecks`] + redirectsChecks = r[`${frontend}ClearnetRedirectsChecks`] }) for (const href of instances) await ping(href).then(time => { @@ -315,7 +314,7 @@ async function testLatency(element, instances, frontend) { redirectsChecks.splice(redirectsChecks.indexOf(href), 1) } - browser.storage.local.set({ [`${frontend}NormalRedirectsChecks`]: redirectsChecks }) + browser.storage.local.set({ [`${frontend}ClearnetRedirectsChecks`]: redirectsChecks }) let text if (time == 5000) text = "5000ms+" @@ -516,10 +515,10 @@ function latency(name, frontend, document, location) { let redirects = r[key] const oldHtml = latencyLabel.innerHTML latencyLabel.innerHTML = "..." - testLatency(latencyLabel, redirects[frontend].normal, frontend).then(r => { + testLatency(latencyLabel, redirects[frontend].clearnet, frontend).then(r => { browser.storage.local.set({ [`${frontend}Latency`]: r }) latencyLabel.innerHTML = oldHtml - processDefaultCustomInstances(name, frontend, "normal", document) + processDefaultCustomInstances(name, frontend, "clearnet", document) latencyElement.removeEventListener("click", reloadWindow) }) }) @@ -537,4 +536,5 @@ export default { switchInstance, copyRaw, unify, + camelCase, } diff --git a/src/config/config.json b/src/config/config.json index 6c4d802..97fd838 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -1,19 +1,19 @@ { "networks": { "clearnet": { - "url": "org", + "tld": "org", "name": "Clearnet" }, "tor": { - "url": "onion", + "tld": "onion", "name": "Tor" }, "i2p": { - "url": "i2p", + "tld": "i2p", "name": "I2P" }, "loki": { - "url": "loki", + "tld": "loki", "name": "Lokinet" } }, @@ -72,14 +72,14 @@ "^https?:\\/{2}(www\\.|)(youtube|youtube-nocookie)\\.com\\/embed\\/..*" ], "name": "Youtube", - "defaults": { - "disableYoutube": false, - "enableYoutubeCustomSettings": false, - "onlyEmbeddedVideo": "both", - "youtubeFrontend": "invidious", - "youtubeEmbedFrontend": "invidious" + "options": { + "disabled": false, + "redirectType": "both", + "frontend": "invidious", + "embedFrontend": "invidious" }, - "imageType": "png" + "imageType": "png", + "embeddable": true }, "youtubeMusic": { "frontends": { @@ -88,11 +88,12 @@ }, "targets": ["^https?:\\/{2}music\\.youtube\\.com(\\/.*|$)"], "name": "YT Music", - "defaults": { - "disableYoutubeMusic": false, - "youtubeMusicFrontend": "beatbump" + "options": { + "disabled": false, + "frontend": "beatbump" }, - "imageType": "png" + "imageType": "png", + "embeddable": false }, "twitter": { "frontends": { @@ -123,11 +124,12 @@ }, "targets": ["^https?:\\/{2}(www\\.|mobile\\.|)twitter\\.com", "^https?:\\/{2}(pbs\\.|video\\.|)twimg\\.com", "^https?:\\/{2}platform\\.twitter\\.com/embed", "^https?:\\/{2}t\\.co"], "name": "Twitter", - "defaults": { - "disableTwitter": false, - "twitterRedirectType": "both" + "options": { + "disabled": false, + "redirectType": "both" }, - "imageType": "png" + "imageType": "png", + "embeddable": true }, "instagram": { "frontends": { @@ -141,10 +143,9 @@ }, "targets": ["^https?:\\/{2}(www\\.)?instagram\\.com"], "name": "Instagram", - "defaults": { - "disableInstagram": false - }, - "imageType": "png" + "options": { "disabled": false }, + "imageType": "png", + "embeddable": false }, "tiktok": { "frontends": { @@ -152,10 +153,9 @@ }, "targets": ["^https?:\\/{2}(www\\.|)tiktok\\.com.*"], "name": "TikTok", - "defaults": { - "disableTiktok": false - }, - "imageType": "png" + "options": { "disabled": false }, + "imageType": "png", + "embeddable": false }, "reddit": { "frontends": { @@ -185,11 +185,12 @@ }, "targets": ["^https?:\\/{2}(www\\.|old\\.|np\\.|new\\.|amp\\.|)reddit\\.com", "^https?:\\/{2}(i\\.|preview\\.)redd\\.it"], "name": "Reddit", - "defaults": { - "disableReddit": false, - "redditFrontend": "libreddit" + "options": { + "disabled": false, + "frontend": "libreddit" }, - "imageType": "png" + "imageType": "png", + "embeddable": false }, "imgur": { "frontends": { @@ -199,8 +200,9 @@ }, "targets": ["^https?:\\/{2}([im]\\.)?imgur\\.(com|io)(\\/|$)"], "name": "Imgur", - "defaults": { "disableImgur": false }, - "imageType": "png" + "options": { "disabled": false }, + "imageType": "png", + "embeddable": false }, "wikipedia": { "frontends": { @@ -212,8 +214,9 @@ }, "targets": ["^https?:\\/{2}([a-z]+\\.)*wikipedia\\.org"], "name": "Wikipedia", - "defaults": { "disableWikipedia": true }, - "imageType": "svg" + "options": { "disabled": true }, + "imageType": "svg", + "embeddable": false }, "medium": { "frontends": { @@ -242,8 +245,9 @@ "^writingcooperative\\.com " ], "name": "Medium", - "defaults": { "disableMedium": false }, - "imageType": "svg" + "options": { "disabled": false }, + "imageType": "svg", + "embeddable": false }, "quora": { "frontends": { @@ -253,10 +257,9 @@ }, "targets": ["^https?:\\/{2}([a-z]+\\.)*quora\\.com.*"], "name": "Quora", - "defaults": { - "disableQuora": false - }, - "imageType": "png" + "options": { "disabled": false }, + "imageType": "png", + "embeddable": false }, "imdb": { "frontends": { @@ -266,10 +269,9 @@ }, "targets": ["^https?:\\/{2}(?:www\\.|)imdb\\.com.*"], "name": "IMDb", - "defaults": { - "disableImdb": true - }, - "imageType": "svg" + "options": { "disabled": true }, + "imageType": "svg", + "embeddable": false }, "reuters": { "frontends": { @@ -279,10 +281,9 @@ }, "targets": ["^https?:\\/{2}(www\\.|)reuters\\.com.*"], "name": "Reuters", - "defaults": { - "disableReuters": true - }, - "imageType": "svg" + "options": { "disabled": true }, + "imageType": "svg", + "embeddable": false }, "peertube": { "frontends": { @@ -292,10 +293,9 @@ }, "targets": "datajson", "name": "PeerTube", - "defaults": { - "disablePeertube": true - }, - "imageType": "svg" + "options": { "disabled": true }, + "imageType": "svg", + "embeddable": false }, "lbry": { "frontends": { @@ -309,12 +309,13 @@ "singleInstanceFrontends": ["lbryDesktop"], "targets": ["^https?:\\/{2}odysee\\.com", "^https?:\\/{2}lbry\\.tv"], "name": "LBRY", - "defaults": { - "disableLbry": true, - "lbryFrontend": "librarian", - "lbryRedirectType": "both" + "options": { + "disabled": true, + "frontend": "librarian", + "redirectType": "both" }, - "imageType": "png" + "imageType": "png", + "embeddable": true }, "search": { "frontends": { @@ -377,12 +378,12 @@ }, "targets": ["^https?:\\/{2}search\\.libredirect\\.invalid"], "name": "Search", - "defaults": { - "disableSearch": false, - "searchFrontend": "searxng", - "searxngCustomSettings": false + "options": { + "disabled": false, + "frontend": "searxng" }, - "imageType": "svg" + "imageType": "svg", + "embeddable": false }, "translate": { "frontends": { @@ -399,11 +400,12 @@ }, "targets": ["^https?:\\/{2}translate\\.google(\\.[a-z]{2,3}){1,2}\\/"], "name": "Translate", - "defaults": { - "translateDisable": false, - "translateFrontend": "simplyTranslate" + "options": { + "disabled": false, + "frontend": "simplyTranslate" }, - "imageType": "svg" + "imageType": "svg", + "embeddable": false }, "maps": { "frontends": { @@ -414,11 +416,12 @@ "singleInstanceFrontends": ["osm"], "targets": ["^https?:\\/{2}(((www|maps)\\.)?(google\\.).*(\\/maps)|maps\\.(google\\.).*)"], "name": "Maps", - "defaults": { - "disableMaps": false, - "mapsFrontend": "osm" + "options": { + "disabled": false, + "frontend": "osm" }, - "imageType": "svg" + "imageType": "svg", + "embeddable": false }, "sendTargets": { "frontends": { @@ -428,10 +431,9 @@ }, "targets": ["^https?:\\/{2}send\\.libredirect\\.invalid\\/$", "^https?:\\/{2}send\\.firefox\\.com\\/$", "^https?:\\/{2}sendfiles\\.online\\/$"], "name": "Send Files", - "defaults": { - "disableSendTargets": false - }, - "imageType": "svg" + "options": { "disabled": false }, + "imageType": "svg", + "embeddable": false } } } diff --git a/src/pages/options/index.html b/src/pages/options/index.html index 077b3da..5c0aedd 100644 --- a/src/pages/options/index.html +++ b/src/pages/options/index.html @@ -78,7 +78,7 @@