Made get_instances.py more efficient

Further work to get widgets/services.js to work properly
This commit is contained in:
Hygna 2022-09-19 17:30:39 +01:00
parent 978e079307
commit 0c1595ec3a
9 changed files with 796 additions and 1369 deletions

View File

@ -28,8 +28,8 @@ function init() {
//cur = current //cur = current
for (const service in config.services) { for (const service in config.services) {
options[service] = {} options[service] = {}
browser.storage.local.get([`disable${utils.camelCase(service)}`, `${service}RedirectType`, `${service}Frontend`], r => { browser.storage.local.get([`${utils.camelCase(service)}Enable`, `${service}RedirectType`, `${service}Frontend`], r => {
options[service].disabled = r["disable" + utils.camelCase(service)] options[service].enabled = r[utils.camelCase(service) + "Enable"]
options[service].frontend = r[service + "Frontend"] options[service].frontend = r[service + "Frontend"]
options[service].redirectType = r[service + "RedirectType"] options[service].redirectType = r[service + "RedirectType"]
// console.log(r) // console.log(r)
@ -60,19 +60,19 @@ function all(service) {
return tmp return tmp
} }
getConfig() await getConfig()
init() init()
browser.storage.onChanged.addListener(init) browser.storage.onChanged.addListener(init)
function redirect(url, type, initiator) { function redirect(url, type, initiator) {
let randomInstance let randomInstance
let frontend = options[service].frontend let frontend
let network = options.network let network = options.network
let networkFallback = options.networkFallback let networkFallback = options.networkFallback
let redirectType = options[service].redirectType let redirectType
if (url.pathname == "/") return if (url.pathname == "/") return
for (const service in config.services) { for (const service in config.services) {
if (options[service].disabled && !disableOverride) continue if (!options[service].enabled && !disableOverride) continue
let targets = service.targets let targets = service.targets
if (targets == "datajson") { if (targets == "datajson") {
browser.storage.local.get(`${service}Targets`, (targets = r[service + "Targets"])) browser.storage.local.get(`${service}Targets`, (targets = r[service + "Targets"]))
@ -81,12 +81,19 @@ function redirect(url, type, initiator) {
if (initiator && (all(service).includes(initiator.origin) || targets.includes(initiator.host))) continue if (initiator && (all(service).includes(initiator.origin) || targets.includes(initiator.host))) continue
if (!targets.some(rx => rx.test(url.href))) continue if (!targets.some(rx => rx.test(url.href))) continue
if (type != redirectType && type != "both") continue if (type != redirectType && type != "both") continue
frontend = options[service].frontend
redirectType = options[service].redirectType
// browser.storage.local.get(`${service}Frontend`, (frontend = r[service + "Frontend"])) // browser.storage.local.get(`${service}Frontend`, (frontend = r[service + "Frontend"]))
let instanceList = [...[service + utils.camelCase(network) + "RedirectsChecks"], ...[service + utils.camelCase(network) + "CustomRedirects"]]
if (instanceList.length === 0 && networkFallback) instanceList = [...[service + "ClearnetRedirectsChecks"], ...[service + "ClearnetCustomRedirects"]] if (config.services[service].frontends[frontend].instanceList) {
let instanceList = [...[frontend + utils.camelCase(network) + "RedirectsChecks"], ...[frontend + utils.camelCase(network) + "CustomRedirects"]]
if (instanceList.length === 0 && networkFallback) instanceList = [...[frontend + "ClearnetRedirectsChecks"], ...[frontend + "ClearnetCustomRedirects"]]
if (instanceList.length === 0 && redirects.indexOf(frontend) != -1) return if (instanceList.length === 0 && redirects.indexOf(frontend) != -1) return
randomInstance = utils.getRandomInstance(instanceList) randomInstance = utils.getRandomInstance(instanceList)
} }
}
// Here is a (temperory) space for defining constants required in 2 or more switch cases. // Here is a (temperory) space for defining constants required in 2 or more switch cases.
// When possible, try have the two switch cases share all their code as done with searx and searxng. // When possible, try have the two switch cases share all their code as done with searx and searxng.
@ -114,7 +121,7 @@ function redirect(url, type, initiator) {
.replace("/watch?v=", "/listen?id=") .replace("/watch?v=", "/listen?id=")
.replace("/channel/", "/artist/") .replace("/channel/", "/artist/")
.replace("/playlist?list=", "/playlist/VL") .replace("/playlist?list=", "/playlist/VL")
.replace(/\/search\?q=.*/, searchQuery => searchQuery.replace("?q=", "/") + "?filter=song") .replace(/\/search\?q=.*/, searchQuery => searchQuery.replace("?q=", "/") + "?filter=all")
case "hyperpipe": case "hyperpipe":
return `${randomInstance}${url.pathname}${url.search}`.replace(/\/search\?q=.*/, searchQuery => searchQuery.replace("?q=", "/")) return `${randomInstance}${url.pathname}${url.search}`.replace(/\/search\?q=.*/, searchQuery => searchQuery.replace("?q=", "/"))
case "bibliogram": case "bibliogram":
@ -386,7 +393,7 @@ function initDefaults() {
// console.log(redirects) // console.log(redirects)
// console.log(config) // console.log(config)
browser.storage.local.set({ browser.storage.local.set({
redirects, redirects: redirects.invidious,
}) })
browser.storage.local.get(["cloudflareBlackList", "authenticateBlackList", "offlineBlackList"], async r => { browser.storage.local.get(["cloudflareBlackList", "authenticateBlackList", "offlineBlackList"], async r => {
// console.log(r) // console.log(r)
@ -395,7 +402,7 @@ function initDefaults() {
browser.storage.local.set({ [service + "Targets"]: redirects[service] }) browser.storage.local.set({ [service + "Targets"]: redirects[service] })
} }
for (const defaultOption in config.services[service].defaults) { for (const defaultOption in config.services[service].defaults) {
browser.storage.local.set({ [defaultOption]: config.services[service].defaults[defaultOption] }) browser.storage.local.set({ [service + camelCase(defaultOption)]: config.services[service].defaults[defaultOption] })
} }
for (const frontend in config.services[service].frontends) { for (const frontend in config.services[service].frontends) {
let clearnetChecks = redirects[frontend].clearnet let clearnetChecks = redirects[frontend].clearnet

View File

@ -24,7 +24,10 @@
"invidious": { "invidious": {
"preferences": { "preferences": {
"cookies": ["PREFS"] "cookies": ["PREFS"]
} },
"name": "Invidious",
"embeddable": true,
"instanceList": true
}, },
"piped": { "piped": {
"preferences": { "preferences": {
@ -48,19 +51,38 @@
"volume", "volume",
"watchHistory" "watchHistory"
] ]
} },
"name": "Piped",
"embeddable": true,
"instanceList": true
}, },
"pipedMaterial": { "pipedMaterial": {
"preferences": { "preferences": {
"localstorage": ["PREFERENCES"] "localstorage": ["PREFERENCES"]
} },
"name": "Piped-Material",
"embeddable": false,
"instanceList": true
}, },
"cloudtube": { "cloudtube": {
"preferences": { "preferences": {
"token": "token", "token": "token",
"fetchEndpoint": "/api/settings", "fetchEndpoint": "/api/settings",
"setEndpoint": "/settings" "setEndpoint": "/settings"
} },
"name": "CloudTube",
"embeddable": false,
"instanceList": true
},
"freetube": {
"name": "FreeTube",
"embeddable": false,
"instanceList": false
},
"yattee": {
"name": "Yattee",
"embeddable": false,
"instanceList": false
} }
}, },
"singleInstanceFrontends": ["freetube", "yatte"], "singleInstanceFrontends": ["freetube", "yatte"],
@ -74,7 +96,7 @@
], ],
"name": "Youtube", "name": "Youtube",
"options": { "options": {
"disabled": false, "enabled": true,
"redirectType": "both", "redirectType": "both",
"frontend": "invidious", "frontend": "invidious",
"embedFrontend": "invidious" "embedFrontend": "invidious"
@ -88,19 +110,23 @@
"preferences": { "preferences": {
"localstorage": ["settings"], "localstorage": ["settings"],
"indexeddb": "beatbump" "indexeddb": "beatbump"
} },
"name": "Beatbump",
"instanceList": true
}, },
"hyperpipe": { "hyperpipe": {
"preferences": { "preferences": {
"localstorage": ["api", "authapi", "codec", "locale", "next", "pipedapi", "quality", "theme", "vol"], "localstorage": ["api", "authapi", "codec", "locale", "next", "pipedapi", "quality", "theme", "vol"],
"indexeddb": ["hyperpipedb"] "indexeddb": ["hyperpipedb"]
} },
"name": "HyperPipe",
"instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}music\\.youtube\\.com(\\/.*|$)"], "targets": ["^https?:\\/{2}music\\.youtube\\.com(\\/.*|$)"],
"name": "YT Music", "name": "YT Music",
"options": { "options": {
"disabled": false, "enabled": true,
"frontend": "beatbump" "frontend": "beatbump"
}, },
"imageType": "png", "imageType": "png",
@ -130,13 +156,16 @@
"replaceTwitter", "replaceTwitter",
"replaceYouTube" "replaceYouTube"
] ]
} },
"name": "Nitter",
"embeddable": true,
"instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}(www\\.|mobile\\.|)twitter\\.com", "^https?:\\/{2}(pbs\\.|video\\.|)twimg\\.com", "^https?:\\/{2}platform\\.twitter\\.com/embed", "^https?:\\/{2}t\\.co"], "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", "name": "Twitter",
"options": { "options": {
"disabled": false, "enabled": true,
"redirectType": "both" "redirectType": "both"
}, },
"imageType": "png", "imageType": "png",
@ -149,12 +178,14 @@
"token": "token", "token": "token",
"fetchEndpoint": "/settings.json", "fetchEndpoint": "/settings.json",
"setEndpoint": "/applysettings" "setEndpoint": "/applysettings"
} },
"name": "Bibliogram",
"instanceList": false
} }
}, },
"targets": ["^https?:\\/{2}(www\\.)?instagram\\.com"], "targets": ["^https?:\\/{2}(www\\.)?instagram\\.com"],
"name": "Instagram", "name": "Instagram",
"options": { "disabled": false }, "options": { "enabled": true },
"imageType": "png", "imageType": "png",
"embeddable": false "embeddable": false
}, },
@ -163,12 +194,14 @@
"proxiTok": { "proxiTok": {
"preferences": { "preferences": {
"cookies": ["api-test_endpoints", "theme"] "cookies": ["api-test_endpoints", "theme"]
} },
"name": "ProxiTok",
"instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}(www\\.|)tiktok\\.com.*"], "targets": ["^https?:\\/{2}(www\\.|)tiktok\\.com.*"],
"name": "TikTok", "name": "TikTok",
"options": { "disabled": false }, "options": { "enabled": true },
"imageType": "png", "imageType": "png",
"embeddable": false "embeddable": false
}, },
@ -177,7 +210,9 @@
"libreddit": { "libreddit": {
"preferences": { "preferences": {
"cookies": ["theme", "front_page", "layout", "wide", "post_sort", "comment_sort", "show_nsfw", "autoplay_videos", "use_hls", "hide_hls_notification", "subscriptions", "filters"] "cookies": ["theme", "front_page", "layout", "wide", "post_sort", "comment_sort", "show_nsfw", "autoplay_videos", "use_hls", "hide_hls_notification", "subscriptions", "filters"]
} },
"name": "Libreddit",
"instanceList": true
}, },
"teddit": { "teddit": {
"preferences": { "preferences": {
@ -195,13 +230,15 @@
"theme", "theme",
"videos_muted" "videos_muted"
] ]
} },
"name": "Teddit",
"instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}(www\\.|old\\.|np\\.|new\\.|amp\\.|)reddit\\.com", "^https?:\\/{2}(i\\.|preview\\.)redd\\.it"], "targets": ["^https?:\\/{2}(www\\.|old\\.|np\\.|new\\.|amp\\.|)reddit\\.com", "^https?:\\/{2}(i\\.|preview\\.)redd\\.it"],
"name": "Reddit", "name": "Reddit",
"options": { "options": {
"disabled": false, "enabled": true,
"frontend": "libreddit" "frontend": "libreddit"
}, },
"imageType": "png", "imageType": "png",
@ -210,12 +247,14 @@
"imgur": { "imgur": {
"frontends": { "frontends": {
"rimgo": { "rimgo": {
"preferences": {} "preferences": {},
"name": "rimgo",
"instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}([im]\\.)?imgur\\.(com|io)(\\/|$)"], "targets": ["^https?:\\/{2}([im]\\.)?imgur\\.(com|io)(\\/|$)"],
"name": "Imgur", "name": "Imgur",
"options": { "disabled": false }, "options": { "enabled": true },
"imageType": "png", "imageType": "png",
"embeddable": false "embeddable": false
}, },
@ -224,19 +263,23 @@
"wikiless": { "wikiless": {
"preferences": { "preferences": {
"cookies": ["theme", "default_lang"] "cookies": ["theme", "default_lang"]
} },
"name": "Wikiless",
"instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}([a-z]+\\.)*wikipedia\\.org"], "targets": ["^https?:\\/{2}([a-z]+\\.)*wikipedia\\.org"],
"name": "Wikipedia", "name": "Wikipedia",
"options": { "disabled": true }, "options": { "enabled": false },
"imageType": "svg", "imageType": "svg",
"embeddable": false "embeddable": false
}, },
"medium": { "medium": {
"frontends": { "frontends": {
"scribe": { "scribe": {
"preferences": {} "preferences": {},
"name": "Scribe",
"instanceList": true
} }
}, },
"targets": [ "targets": [
@ -260,7 +303,7 @@
"^writingcooperative\\.com " "^writingcooperative\\.com "
], ],
"name": "Medium", "name": "Medium",
"options": { "disabled": false }, "options": { "enabled": true },
"imageType": "svg", "imageType": "svg",
"embeddable": false "embeddable": false
}, },
@ -269,12 +312,14 @@
"quetre": { "quetre": {
"preferences": { "preferences": {
"localstorage": ["theme"] "localstorage": ["theme"]
} },
"name": "Quetre",
"instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}([a-z]+\\.)*quora\\.com.*"], "targets": ["^https?:\\/{2}([a-z]+\\.)*quora\\.com.*"],
"name": "Quora", "name": "Quora",
"options": { "disabled": false }, "options": { "enabled": true },
"imageType": "png", "imageType": "png",
"embeddable": false "embeddable": false
}, },
@ -283,36 +328,42 @@
"libremdb": { "libremdb": {
"preferences": { "preferences": {
"localstorage": ["theme"] "localstorage": ["theme"]
} },
"name": "libremdb",
"instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}(?:www\\.|)imdb\\.com.*"], "targets": ["^https?:\\/{2}(?:www\\.|)imdb\\.com.*"],
"name": "IMDb", "name": "IMDb",
"options": { "disabled": true }, "options": { "enabled": false },
"imageType": "svg", "imageType": "svg",
"embeddable": false "embeddable": false
}, },
"reuters": { "reuters": {
"frontends": { "frontends": {
"neuters": { "neuters": {
"preferences": {} "preferences": {},
"name": "Neuters",
"instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}(www\\.|)reuters\\.com.*"], "targets": ["^https?:\\/{2}(www\\.|)reuters\\.com.*"],
"name": "Reuters", "name": "Reuters",
"options": { "disabled": true }, "options": { "enabled": false },
"imageType": "svg", "imageType": "svg",
"embeddable": false "embeddable": false
}, },
"peertube": { "peertube": {
"frontends": { "frontends": {
"simpleertube": { "simpleertube": {
"preferences": {} "preferences": {},
"name": "SimpleerTube",
"instanceList": true
} }
}, },
"targets": "datajson", "targets": "datajson",
"name": "PeerTube", "name": "PeerTube",
"options": { "disabled": true }, "options": { "enabled": false },
"imageType": "svg", "imageType": "svg",
"embeddable": false "embeddable": false
}, },
@ -322,14 +373,21 @@
"preferences": { "preferences": {
"cookies": ["nsfw", "theme"], "cookies": ["nsfw", "theme"],
"localstorage": ["autoplay", "autoplayNextVid", "collapseComments", "plyr", "sb_categories", "showRelated"] "localstorage": ["autoplay", "autoplayNextVid", "collapseComments", "plyr", "sb_categories", "showRelated"]
} },
"name": "Librarian",
"embeddable": true,
"instanceList": true
},
"lbryDesktop": {
"name": "LBRY Desktop",
"embeddable": false,
"instanceList": false
} }
}, },
"singleInstanceFrontends": ["lbryDesktop"],
"targets": ["^https?:\\/{2}odysee\\.com", "^https?:\\/{2}lbry\\.tv"], "targets": ["^https?:\\/{2}odysee\\.com", "^https?:\\/{2}lbry\\.tv"],
"name": "LBRY", "name": "LBRY",
"options": { "options": {
"disabled": true, "enabled": false,
"frontend": "librarian", "frontend": "librarian",
"redirectType": "both" "redirectType": "both"
}, },
@ -359,7 +417,9 @@
"theme", "theme",
"tokens" "tokens"
] ]
} },
"name": "SearX",
"instanceList": true
}, },
"searxng": { "searxng": {
"preferences": { "preferences": {
@ -384,21 +444,27 @@
"theme", "theme",
"tokens" "tokens"
] ]
} },
"name": "SearXNG",
"instanceList": true
}, },
"whoogle": { "whoogle": {
"preferences": {} "preferences": {},
"name": "Whoogle",
"instanceList": true
}, },
"librex": { "librex": {
"preferences": { "preferences": {
"cookies": ["bibliogram", "disable_special", "invidious", "libreddit", "nitter", "proxitok", "theme", "wikiless"] "cookies": ["bibliogram", "disable_special", "invidious", "libreddit", "nitter", "proxitok", "theme", "wikiless"]
} },
"name": "LibreX",
"instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}search\\.libredirect\\.invalid"], "targets": ["^https?:\\/{2}search\\.libredirect\\.invalid"],
"name": "Search", "name": "Search",
"options": { "options": {
"disabled": false, "enabled": true,
"frontend": "searxng" "frontend": "searxng"
}, },
"imageType": "svg", "imageType": "svg",
@ -409,18 +475,22 @@
"simplyTranslate": { "simplyTranslate": {
"preferences": { "preferences": {
"cookies": ["from_lang", "to_lang", "tts_enabled", "use_text_fields"] "cookies": ["from_lang", "to_lang", "tts_enabled", "use_text_fields"]
} },
"name": "SimplyTranslate",
"instanceList": true
}, },
"lingva": { "lingva": {
"preferences": { "preferences": {
"localstorage": ["isauto", "source", "target"] "localstorage": ["isauto", "source", "target"]
} },
"name": "Lingva",
"instanceList": true
} }
}, },
"targets": ["^https?:\\/{2}translate\\.google(\\.[a-z]{2,3}){1,2}\\/"], "targets": ["^https?:\\/{2}translate\\.google(\\.[a-z]{2,3}){1,2}\\/"],
"name": "Translate", "name": "Translate",
"options": { "options": {
"disabled": false, "enabled": true,
"frontend": "simplyTranslate" "frontend": "simplyTranslate"
}, },
"imageType": "svg", "imageType": "svg",
@ -429,14 +499,19 @@
"maps": { "maps": {
"frontends": { "frontends": {
"facil": { "facil": {
"preferences": {} "preferences": {},
"name": "FacilMap",
"instanceList": true
},
"osm": {
"name": "OpenStreetMap",
"instanceList": false
} }
}, },
"singleInstanceFrontends": ["osm"],
"targets": ["^https?:\\/{2}(((www|maps)\\.)?(google\\.).*(\\/maps)|maps\\.(google\\.).*)"], "targets": ["^https?:\\/{2}(((www|maps)\\.)?(google\\.).*(\\/maps)|maps\\.(google\\.).*)"],
"name": "Maps", "name": "Maps",
"options": { "options": {
"disabled": false, "enabled": true,
"frontend": "osm" "frontend": "osm"
}, },
"imageType": "svg", "imageType": "svg",
@ -445,12 +520,14 @@
"sendTargets": { "sendTargets": {
"frontends": { "frontends": {
"send": { "send": {
"preferences": {} "preferences": {},
"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", "name": "Send Files",
"options": { "disabled": false }, "options": { "enabled": true },
"imageType": "svg", "imageType": "svg",
"embeddable": false "embeddable": false
} }

View File

@ -3,12 +3,10 @@
import requests import requests
import json import json
from urllib.parse import urlparse from urllib.parse import urlparse
from bs4 import BeautifulSoup
import re import re
from colorama import Fore, Back, Style from colorama import Fore, Back, Style
from urllib.parse import urlparse from urllib.parse import urlparse
import socket import socket
import subprocess
mightyList = {} mightyList = {}
@ -18,6 +16,11 @@ torRegex = startRegex + "onion" + endRegex
i2pRegex = startRegex + "i2p" + endRegex i2pRegex = startRegex + "i2p" + endRegex
lokiRegex = startRegex + "loki" + endRegex lokiRegex = startRegex + "loki" + endRegex
authRegex = "https?:\/{2}\S+:\S+@(?:[^\s\/]+\.)+[a-zA-Z0-9]+" + endRegex authRegex = "https?:\/{2}\S+:\S+@(?:[^\s\/]+\.)+[a-zA-Z0-9]+" + endRegex
config = {}
with open('./config/config.json') as file:
config = file
def filterLastSlash(urlList): def filterLastSlash(urlList):
tmp = {} tmp = {}
@ -102,35 +105,141 @@ def is_offline(url):
except: except:
return False return False
def fetchCache(frontend, name) :
# json_object = json.dumps(mightyList, ensure_ascii=False, indent=2)
with open('./src/instances/data.json') as file:
mightyList[frontend] = json.load(file).frontend
print(Fore.ORANGE + 'Failed' + Style.RESET_ALL + ' to fetch ' + name)
def fetchFromFile(frontend, name):
#json_object = json.dumps(mightyList, ensure_ascii=False, indent=2)
with open('./src/instances/' + frontend + '.json') as file:
mightyList[frontend] = json.load(file)
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + name)
def fetchJsonList(frontend, name, url, urlItem):
try:
r = requests.get(url)
rJson = json.loads(r.text)
_list = {}
for network in config.networks:
_list[network] = []
if type(urlItem) is 'str':
for item in rJson:
if urlItem is not None:
tmpUrl = item[urlItem]
else:
tmpUrl = item
if tmpUrl.strip() == "":
continue
elif re.search(torRegex, tmpUrl):
_list['tor'].append(tmpUrl)
elif re.search(i2pRegex, tmpUrl):
_list['i2p'].append(tmpUrl)
elif re.search(lokiRegex, tmpUrl):
_list['loki'].append(tmpUrl)
else:
_list['clearnet'].append(tmpUrl)
else:
for i in range(config.networks.length):
# The expected order is the same as in config.json. If the frontend doesn't have any instances for a specified network, use None
if urlItem != None:
for item in rJson:
if network in item:
if item[network].strip() != "":
_list[config.networks[i]].append(item[urlItem[i]])
mightyList[frontend] = _list
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + name)
except:
fetchCache(frontend, name)
def fetchRegexList(frontend, name, url, regex):
try:
r = requests.get(url)
_list = {}
for network in config.networks:
_list[network] = []
tmp = re.findall(regex, r.text)
for item in tmp:
if item.strip() == "":
continue
elif re.search(torRegex, item):
_list['tor'].append(item)
elif re.search(i2pRegex, item):
_list['i2p'].append(item)
elif re.search(lokiRegex, item):
_list['loki'].append(item)
else:
_list['clearnet'].append(item)
mightyList[frontend] = _list
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + name)
except:
fetchCache(frontend, name)
def fetchTextList(frontend, name, url, prepend):
try:
r = requests.get(url)
tmp = r.text.strip().split('\n')
_list = {}
for network in config.networks:
_list[network] = []
for item in tmp:
item = prepend + item
if re.search(torRegex, item):
_list['tor'].append(item)
elif re.search(i2pRegex, item):
_list['i2p'].append(item)
elif re.search(lokiRegex, item):
_list['loki'].append(item)
else:
_list['clearnet'].append(item)
mightyList[frontend] = _list
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + name)
except:
fetchCache(frontend, name)
def invidious(): def invidious():
r = requests.get('https://api.invidious.io/instances.json') name = 'Invidious'
rJson = json.loads(r.text) frontend = 'invidious'
invidiousList = {} try:
invidiousList['clearnet'] = []
invidiousList['tor'] = []
invidiousList['i2p'] = []
invidiousList['loki'] = []
for instance in rJson:
if instance[1]['type'] == 'https':
invidiousList['clearnet'].append(instance[1]['uri'])
elif instance[1]['type'] == 'onion':
invidiousList['tor'].append(instance[1]['uri'])
mightyList['invidious'] = invidiousList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Invidious')
def piped():
r = requests.get(
'https://raw.githubusercontent.com/wiki/TeamPiped/Piped/Instances.md')
tmp = re.findall(
'(?:[^\s\/]+\.)+[a-zA-Z]+ (?:\(Official\) )?\| (https:\/{2}(?:[^\s\/]+\.)+[a-zA-Z]+) \| ', r.text)
_list = {} _list = {}
_list['clearnet'] = [] _list['clearnet'] = []
_list['tor'] = [] _list['tor'] = []
_list['i2p'] = [] _list['i2p'] = []
_list['loki'] = [] _list['loki'] = []
r = requests.get('https://api.invidious.io/instances.json')
rJson = json.loads(r.text)
for instance in rJson:
if instance[1]['type'] == 'https':
_list['clearnet'].append(instance[1]['uri'])
elif instance[1]['type'] == 'onion':
_list['tor'].append(instance[1]['uri'])
mightyList[frontend] = _list
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + name)
except:
fetchCache(frontend, name)
def piped():
frontend = 'piped'
name = 'Piped'
try:
_list = {}
_list['clearnet'] = []
_list['tor'] = []
_list['i2p'] = []
_list['loki'] = []
r = requests.get(
'https://raw.githubusercontent.com/wiki/TeamPiped/Piped/Instances.md')
tmp = re.findall(
'(?:[^\s\/]+\.)+[a-zA-Z]+ (?:\(Official\) )?\| (https:\/{2}(?:[^\s\/]+\.)+[a-zA-Z]+) \| ', r.text)
for item in tmp: for item in tmp:
try: try:
url = requests.get(item, timeout=5).url url = requests.get(item, timeout=5).url
@ -140,32 +249,18 @@ def piped():
_list['clearnet'].append(url) _list['clearnet'].append(url)
except: except:
continue continue
mightyList['piped'] = _list mightyList[frontend] = _list
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Piped') print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + name)
except:
fetchCache(frontend, name)
def pipedMaterial(): def pipedMaterial():
r = requests.get( fetchRegexList('pipedMaterial', 'Piped-Material', 'https://raw.githubusercontent.com/mmjee/Piped-Material/master/README.md', r"\| (https?:\/{2}(?:\S+\.)+[a-zA-Z0-9]*) +\|")
'https://raw.githubusercontent.com/mmjee/Piped-Material/master/README.md')
tmp = re.findall(
r"\| (https?:\/{2}(?:\S+\.)+[a-zA-Z0-9]*) +\|", r.text)
pipedMaterialList = {}
pipedMaterialList['clearnet'] = []
pipedMaterialList['tor'] = []
pipedMaterialList['i2p'] = []
pipedMaterialList['loki'] = []
for item in tmp:
pipedMaterialList['clearnet'].append(item)
mightyList['pipedMaterial'] = pipedMaterialList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'pipedMaterial')
def cloudtube(): def cloudtube():
json_object = json.dumps(mightyList, ensure_ascii=False, indent=2) fetchCache('cloudtube', 'Cloudtube')
with open('./src/instances/cloudtube.json') as file:
mightyList['cloudtube'] = json.load(file)
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'CloudTube')
def proxitok(): def proxitok():
@ -186,19 +281,7 @@ def proxitok():
def send(): def send():
r = requests.get( fetchRegexList('send', 'Send', 'https://gitlab.com/timvisee/send-instances/-/raw/master/README.md', r"- ([-a-zA-Z0-9@:%_\+.~#?&//=]{2,}\.[a-z0-9]{2,}\b(?:\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?)\)*\|*[A-Z]{0,}")
'https://gitlab.com/timvisee/send-instances/-/raw/master/README.md')
tmp = re.findall(
r"- ([-a-zA-Z0-9@:%_\+.~#?&//=]{2,}\.[a-z0-9]{2,}\b(?:\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?)\)*\|*[A-Z]{0,}", r.text)
sendList = {}
sendList['clearnet'] = []
sendList['tor'] = []
sendList['i2p'] = []
sendList['loki'] = []
for item in tmp:
sendList['clearnet'].append(item)
mightyList['send'] = sendList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Send')
def nitter(): def nitter():
@ -230,150 +313,35 @@ def nitter():
def bibliogram(): def bibliogram():
json_object = json.dumps(mightyList, ensure_ascii=False, indent=2) fetchFromFile('bibliogram', 'Bibliogram')
with open('./src/instances/bibliogram.json') as file:
mightyList['bibliogram'] = json.load(file)
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Bibliogram')
def libreddit(): def libreddit():
r = requests.get( fetchRegexList('libreddit', 'Libreddit', 'https://raw.githubusercontent.com/spikecodes/libreddit/master/README.md', r"\| \[.*\]\(([-a-zA-Z0-9@:%_\+.~#?&//=]{2,}\.[a-z]{2,}\b(?:\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?)\)*\|*[A-Z]{0,}.*\|.*\|")
'https://raw.githubusercontent.com/spikecodes/libreddit/master/README.md')
libredditList = {}
libredditList['clearnet'] = []
libredditList['tor'] = []
libredditList['i2p'] = []
libredditList['loki'] = []
tmp = re.findall(
r"\| \[.*\]\(([-a-zA-Z0-9@:%_\+.~#?&//=]{2,}\.[a-z]{2,}\b(?:\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?)\)*\|*[A-Z]{0,}.*\|.*\|", r.text)
for item in tmp:
if re.search(torRegex, item):
libredditList['tor'].append(item)
else:
libredditList['clearnet'].append(item)
mightyList['libreddit'] = libredditList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'LibReddit')
def teddit(): def teddit():
r = requests.get( fetchJsonList('teddit', 'Teddit', 'https://codeberg.org/teddit/teddit/raw/branch/main/instances.json', ['url', 'onion', 'i2p', None])
'https://codeberg.org/teddit/teddit/raw/branch/main/instances.json')
rJson = json.loads(r.text)
tedditList = {}
tedditList['clearnet'] = []
tedditList['tor'] = []
tedditList['i2p'] = []
tedditList['loki'] = []
for item in rJson:
url = item['url']
if url != '':
tedditList['clearnet'].append(url)
if 'onion' in item:
onion = item['onion']
if onion != '':
tedditList['tor'].append(onion)
mightyList['teddit'] = tedditList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Teddit')
def wikiless(): def wikiless():
r = requests.get('https://wikiless.org/instances.json') fetchJsonList('wikiless', 'Wikiless', 'https://wikiless.org/instances.json', ['url', 'onion', 'i2p', None])
rJson = json.loads(r.text)
wikilessList = {}
wikilessList['clearnet'] = []
wikilessList['tor'] = []
wikilessList['i2p'] = []
wikilessList['loki'] = []
for item in rJson:
if 'url' in item:
if item['url'].strip() != "":
wikilessList['clearnet'].append(item['url'])
if 'onion' in item:
if item['onion'].strip() != "":
wikilessList['tor'].append(item['onion'])
if 'i2p' in item:
if item['i2p'].strip() != "":
wikilessList['i2p'].append(item['i2p'])
mightyList['wikiless'] = wikilessList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Wikiless')
def scribe(): def scribe():
r = requests.get( fetchJsonList('scribe', 'Scribe', 'https://git.sr.ht/~edwardloveall/scribe/blob/main/docs/instances.json', None)
'https://git.sr.ht/~edwardloveall/scribe/blob/main/docs/instances.json')
rJson = json.loads(r.text)
scribeList = {}
scribeList['clearnet'] = []
scribeList['tor'] = []
scribeList['i2p'] = []
scribeList['loki'] = []
for item in rJson:
scribeList['clearnet'].append(item)
mightyList['scribe'] = scribeList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Scribe')
def quetre(): def quetre():
r = requests.get( fetchRegexList('quetre', 'Quetre', 'https://raw.githubusercontent.com/zyachel/quetre/main/README.md', r"\| \[.*\]\(([-a-zA-Z0-9@:%_\+.~#?&//=]{2,}\.[a-z]{2,}\b(?:\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?)\)*\|*[A-Z]{0,}.*\|.*\|")
'https://raw.githubusercontent.com/zyachel/quetre/main/README.md')
_list = {}
_list['clearnet'] = []
_list['tor'] = []
_list['i2p'] = []
_list['loki'] = []
tmp = re.findall(
r"\| \[.*\]\(([-a-zA-Z0-9@:%_\+.~#?&//=]{2,}\.[a-z]{2,}\b(?:\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?)\)*\|*[A-Z]{0,}.*\|.*\|", r.text)
for item in tmp:
if re.search(torRegex, item):
_list['tor'].append(item)
else:
_list['clearnet'].append(item)
mightyList['quetre'] = _list
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Quetre')
def libremdb(): def libremdb():
r = requests.get( fetchRegexList('libremdb', 'libremdb', 'https://raw.githubusercontent.com/zyachel/libremdb/main/README.md', r"\| ([-a-zA-Z0-9@:%_\+.~#?&//=]{2,}\.[a-z]{2,}\b(?:\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?)*\|*[A-Z]{0,}.*\|.*\|")
'https://raw.githubusercontent.com/zyachel/libremdb/main/README.md')
_list = {}
_list['clearnet'] = []
_list['tor'] = []
_list['i2p'] = []
_list['loki'] = []
tmp = re.findall(
r"\| ([-a-zA-Z0-9@:%_\+.~#?&//=]{2,}\.[a-z]{2,}\b(?:\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?)*\|*[A-Z]{0,}.*\|.*\|", r.text)
for item in tmp:
if item.strip() == "":
continue
if re.search(torRegex, item):
_list['tor'].append(item)
else:
_list['clearnet'].append(item)
mightyList['libremdb'] = _list
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Libremdb')
def simpleertube(): def simpleertube():
r = requests.get('https://simple-web.org/instances/simpleertube') fetchTextList('simpleertube', 'SimpleerTube', 'https://simple-web.org/instances/simpleertube', 'https://')
_list = {}
_list['clearnet'] = []
_list['tor'] = []
_list['i2p'] = []
_list['loki'] = []
for item in r.text.strip().split('\n'):
_list['clearnet'].append('https://' + item)
mightyList['simpleertube'] = _list
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'SimpleerTube')
def simplytranslate(): def simplytranslate():
@ -403,19 +371,7 @@ def simplytranslate():
def linvgatranslate(): def linvgatranslate():
r = requests.get( fetchJsonList('lingva', 'LingvaTranslate', 'https://raw.githubusercontent.com/TheDavidDelta/lingva-translate/main/instances.json', None)
'https://raw.githubusercontent.com/TheDavidDelta/lingva-translate/main/instances.json')
rJson = json.loads(r.text)
lingvaList = {}
lingvaList['clearnet'] = []
lingvaList['tor'] = []
lingvaList['i2p'] = []
lingvaList['loki'] = []
for item in rJson:
lingvaList['clearnet'].append(item)
mightyList['lingva'] = lingvaList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'LinvgaTranslate')
def searx_searxng(): def searx_searxng():
@ -454,140 +410,34 @@ def searx_searxng():
def whoogle(): def whoogle():
r = requests.get( fetchTextList('whoogle', 'Whoogle', 'https://raw.githubusercontent.com/benbusby/whoogle-search/main/misc/instances.txt', '')
'https://raw.githubusercontent.com/benbusby/whoogle-search/main/misc/instances.txt')
tmpList = r.text.strip().split('\n')
whoogleList = {}
whoogleList['clearnet'] = []
whoogleList['tor'] = []
whoogleList['i2p'] = []
whoogleList['loki'] = []
for item in tmpList:
if re.search(torRegex, item):
whoogleList['tor'].append(item)
elif re.search(torRegex, item):
whoogleList['i2p'].append(item)
else:
whoogleList['clearnet'].append(item)
mightyList['whoogle'] = whoogleList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Whoogle')
def librex(): def librex():
r = requests.get( fetchRegexList('librex', 'LibreX', 'https://raw.githubusercontent.com/hnhx/librex/main/README.md', r"\| {1,2}\[(?:(?:[a-zA-Z0-9]+\.)+[a-zA-Z]{2,}|✅)\]\((https?:\/{2}(?:[a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,})")
'https://raw.githubusercontent.com/hnhx/librex/main/README.md')
_list = {}
_list['clearnet'] = []
_list['tor'] = []
_list['i2p'] = []
_list['loki'] = []
tmp = re.findall(
r"\| {1,2}\[(?:(?:[a-zA-Z0-9]+\.)+[a-zA-Z]{2,}|✅)\]\((https?:\/{2}(?:[a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,})", r.text)
for item in tmp:
if item.strip() == "":
continue
elif re.search(torRegex, item):
_list['tor'].append(item)
elif re.search(i2pRegex, item):
_list['i2p'].append(item)
else:
_list['clearnet'].append(item)
mightyList['librex'] = _list
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Librex')
def rimgo(): def rimgo():
r = requests.get( fetchJsonList('rimgo', 'rimgo', 'https://codeberg.org/video-prize-ranch/rimgo/raw/branch/main/instances.json', ['url', 'onion', 'i2p', None])
'https://codeberg.org/video-prize-ranch/rimgo/raw/branch/main/instances.json')
rJson = json.loads(r.text)
rimgoList = {}
rimgoList['clearnet'] = []
rimgoList['tor'] = []
rimgoList['i2p'] = []
rimgoList['loki'] = []
for item in rJson:
if 'url' in item:
rimgoList['clearnet'].append(item['url'])
if 'onion' in item:
rimgoList['tor'].append(item['onion'])
if 'i2p' in item:
rimgoList['i2p'].append(item['i2p'])
mightyList['rimgo'] = rimgoList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Rimgo')
def librarian(): def librarian():
r = requests.get( fetchJsonList('librarian', 'Librarian', 'https://codeberg.org/librarian/librarian/raw/branch/main/instances.json', 'url')
'https://codeberg.org/librarian/librarian/raw/branch/main/instances.json')
rJson = json.loads(r.text)
librarianList = {}
librarianList['clearnet'] = []
librarianList['tor'] = []
librarianList['i2p'] = []
librarianList['loki'] = []
instances = rJson['instances']
for item in instances:
url = item['url']
if url.strip() == "":
continue
elif re.search(torRegex, url):
librarianList['tor'].append(url)
elif re.search(i2pRegex, url):
librarianList['i2p'].append(url)
elif re.search(lokiRegex, url):
librarianList['loki'].append(url)
else:
librarianList['clearnet'].append(url)
mightyList['librarian'] = librarianList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Librarian')
def neuters(): def neuters():
json_object = json.dumps(mightyList, ensure_ascii=False, indent=2) fetchFromFile('neuters', 'Neuters')
with open('./src/instances/neuters.json') as file:
mightyList['neuters'] = json.load(file)
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Neuters')
def beatbump(): def beatbump():
json_object = json.dumps(mightyList, ensure_ascii=False, indent=2) fetchFromFile('beatbump', 'Beatbump')
with open('./src/instances/beatbump.json') as file:
mightyList['beatbump'] = json.load(file)
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Beatbump')
def hyperpipe(): def hyperpipe():
r = requests.get( fetchJsonList('hyperpipe', 'Hyperpipe', 'https://codeberg.org/Hyperpipe/pages/raw/branch/main/api/frontend.json', 'url')
'https://codeberg.org/Hyperpipe/pages/raw/branch/main/api/frontend.json')
rJson = json.loads(r.text)
hyperpipeList = {}
hyperpipeList['clearnet'] = []
hyperpipeList['tor'] = []
hyperpipeList['i2p'] = []
hyperpipeList['loki'] = []
for item in rJson:
url = item['url']
if url.strip() == "":
continue
elif re.search(torRegex, url):
hyperpipeList['tor'].append(url)
elif re.search(i2pRegex, url):
hyperpipeList['i2p'].append(url)
elif re.search(lokiRegex, url):
hyperpipeList['loki'].append(url)
else:
hyperpipeList['clearnet'].append(url)
mightyList['hyperpipe'] = hyperpipeList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Hyperpipe')
def facil(): def facil():
json_object = json.dumps(mightyList, ensure_ascii=False, indent=2) fetchFromFile('facil', 'FacilMap')
with open('./src/instances/facil.json') as file:
mightyList['facil'] = json.load(file)
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'FacilMap')
def peertube(): def peertube():

View File

@ -1,12 +1,12 @@
<!DOCTYPE html> <!DOCTYPE html>
<html id="elementToShowWithJavaScript" lang="en"> <html id="elementToShowWithJavaScript" lang="en">
<%- include('src/pages/widgets/head') %> <%- include('src/pages/widgets/head') -%>
<body class="option" dir="auto"> <body class="option" dir="auto">
<%- include('src/pages/widgets/links', {config: config}) %> <%- include('src/pages/widgets/links', {config: config}) -%>
<div id="pages"> <div id="pages">
<%- include('src/pages/options/widgets/general', {config: config}) %> <%- include('src/pages/options/widgets/general', {config: config}) -%>
<%- include('src/pages/options/widgets/services', {config: config}) %> <%- include('src/pages/options/widgets/services', {config: config}) -%>
<%- include('src/pages/options/widgets/about') %> <%- include('src/pages/options/widgets/about') -%>
</div> </div>
</body> </body>
<script type="module" src="./index.js"></script> <script type="module" src="./index.js"></script>

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
<div class="some-block option-block"> <div class="some-block option-block">
<h4 data-localise="__MSG_protocol__"></h4> <h4 data-localise="__MSG_protocol__"></h4>
<select id="protocol"> <select id="protocol">
<% for (const network in config.networks) { %> <% for (const network in config.networks) { -%>
<option value="<%= network %>"><%= config.networks[network].name %></option> <option value="<%= network %>"><%= config.networks[network].name %></option>
<% }; %> <% }; %>
</select> </select>
@ -84,7 +84,7 @@
<h4 data-localise="__MSG_customPopup__">Customize Popup</h4> <h4 data-localise="__MSG_customPopup__">Customize Popup</h4>
</div> </div>
<div class="checklist-popup" id="popup-frontends-checklist"> <div class="checklist-popup" id="popup-frontends-checklist">
<% for (const service in config.services) { %> <% for (const service in config.services) { -%>
<div> <div>
<div><img src="../../../assets/images/<%= service %>-icon.<%= config.services[service].imageType %>"> <div><img src="../../../assets/images/<%= service %>-icon.<%= config.services[service].imageType %>">
<x data-localise="__MSG_<%= service %>__"><%= service %></x> <x data-localise="__MSG_<%= service %>__"><%= service %></x>

View File

@ -1,4 +1,4 @@
<% for (const service in config.services) { %> <% for (const service in config.services) { -%>
<section class="option-block" id="<%= service %>_page"> <section class="option-block" id="<%= service %>_page">
<div class="some-block option-block"> <div class="some-block option-block">
<h1 data-localise="__MSG_<%= service %>__"><%= config.services[service].name %></h1> <h1 data-localise="__MSG_<%= service %>__"><%= config.services[service].name %></h1>
@ -6,47 +6,47 @@
<hr> <hr>
<div class="some-block option-block"> <div class="some-block option-block">
<h4 data-localise="__MSG_enable__">Enable</h4> <h4 data-localise="__MSG_enable__">Enable</h4>
<input id="<%= service %>-enable" type="checkbox"> <input id="<%= service %>-enabled" type="checkbox">
</div> </div>
<% if ((Object.keys(config.services[service].frontends).length > 1) || config.services[service].singleInstanceFrontends) { %> <% if (Object.keys(config.services[service].frontends).length > 1) { %>
<div class="some-block option-block"> <div class="some-block option-block">
<h4 data-localise="__MSG_frontend__">Frontend</h4> <h4 data-localise="__MSG_frontend__">Frontend</h4>
<select id="<%= service %>-frontend"> <select id="<%= service %>-frontend">
<% for (const frontend in config.services[service].frontends) { %> <% for (const frontend in config.services[service].frontends) { -%>
<option value="<%= frontend %>"><%= frontend %></option> <option value="<%= frontend %>"><%= config.services[service].frontends[frontend].name %></option>
<% }; %> <% } %>
<% for (const frontend in config.services[service].singleInstanceFrontends){ %>
<option value="<%= config.services[service].singleInstanceFrontends[frontend] %>"><%= config.services[service].singleInstanceFrontends[frontend] %></option>
<% }; %>
</select> </select>
</div> </div>
<% } %> <% if (config.services[service].embeddable) { _%>
<% if ((config.services[service].singleInstanceFrontends) && (Object.keys(config.services[service].frontends).length > 1)) { %> <div id="<%= service %>-embedFrontend">
<div id="<%= service %>-embedded_frontend">
<div class="some-block option-block"> <div class="some-block option-block">
<h4 data-localise="__MSG_embed_frontend__">Embed Frontend</h4> <h4 data-localise="__MSG_embed_frontend__">Embed Frontend</h4>
<select id="<%= service %>-embed_frontend"> <select id="<%= service %>-embed_frontend">
<% for (const frontend in config.services[service].frontends) { %> <% for (const frontend in config.services[service].frontends) { -%>
<% if (config.services[service].frontends[frontend].embeddable) { _%>
<option value="<%= frontend %>"><%= frontend %></option> <option value="<%= frontend %>"><%= frontend %></option>
<% }; %> <% } _%>
<% } %>
</select> </select>
</div> </div>
</div> </div>
<% } %> <% } _%>
<% if (config.services[service].embeddable) { %> <% } _%>
<% if (config.services[service].embeddable) { _%>
<div class="some-block option-block"> <div class="some-block option-block">
<h4 data-localise="__MSG_redirectType__">Redirect Type</h4> <h4 data-localise="__MSG_redirectType__">Redirect Type</h4>
<select id="<%= service %>-redirect_type"> <select id="<%= service %>-redirectType">
<option value="both" data-localise="__MSG_both__">both</option> <option value="both" data-localise="__MSG_both__">both</option>
<option value="onlyEmbedded" data-localise="__MSG_onlyEmbedded__">Only Embedded</option> <option value="sub_frame" data-localise="__MSG_onlyEmbedded__">Only Embedded</option>
<option value="onlyNotEmbedded" data-localise="__MSG_onlyNotEmbedded__">Only Not Embedded</option> <option value="main_frame" data-localise="__MSG_onlyNotEmbedded__">Only Not Embedded</option>
</select> </select>
</div> </div>
<% } %> <% } _%>
<hr> <hr>
<% for (const frontend in config.services[service].frontends) { %> <% for (const frontend in config.services[service].frontends) { -%>
<% if (config.services[service].frontends[frontend].instanceList) { _%>
<div id="<%= frontend %>"> <div id="<%= frontend %>">
<% for (const network in config.networks) { %> <% for (const network in config.networks) { -%>
<div class="<%= network %>"> <div class="<%= network %>">
<div class="some-block option-block"> <div class="some-block option-block">
<h4 data-localise="__MSG_defaultInstances__">Default Instances</h4> <h4 data-localise="__MSG_defaultInstances__">Default Instances</h4>
@ -67,7 +67,7 @@
</div> </div>
</form> </form>
<div class="checklist custom-checklist"></div> <div class="checklist custom-checklist"></div>
<% if (network == "clearnet") { %> <% if (network == "clearnet") { _%>
<div class="buttons buttons-inline"> <div class="buttons buttons-inline">
<label class="button button-inline" id="latency-<%= frontend %>-label" for="latency-<%= frontend %>"> <label class="button button-inline" id="latency-<%= frontend %>-label" for="latency-<%= frontend %>">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor"> <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
@ -77,11 +77,12 @@
</label> </label>
<input class="button button-inline" id="latency-<%= frontend %>" style="display:none;"> <input class="button button-inline" id="latency-<%= frontend %>" style="display:none;">
</div> </div>
<% } _%>
</div>
<% } %> <% } %>
</div> </div>
<% }; %> <% } _%>
</div> <% } %>
<% }; %>
</section> </section>
<% }; %> <% } %>
<script type="module" src="./widgets/services.js"></script> <script type="module" src="./widgets/services.js"></script>

View File

@ -1,13 +1,10 @@
import utils from "../../../assets/javascripts/utils.js" import utils from "../../../assets/javascripts/utils.js"
// const frontends = new Array("librarian")
// const protocols = new Array("clearnet", "tor", "i2p", "loki")
let config, let config,
network, network,
divs = {} divs = {}
async function getConfig() { function getConfig() {
return new Promise(resolve => { return new Promise(resolve => {
fetch("/config/config.json") fetch("/config/config.json")
.then(response => response.text()) .then(response => response.text())
@ -19,7 +16,7 @@ async function getConfig() {
}) })
} }
getConfig() await getConfig()
browser.storage.local.get("network", r => { browser.storage.local.get("network", r => {
network = r.network network = r.network
@ -27,7 +24,11 @@ browser.storage.local.get("network", r => {
function changeFrontendsSettings(service) { function changeFrontendsSettings(service) {
for (const frontend in config.services[service].frontends) { for (const frontend in config.services[service].frontends) {
if (config.services[service].frontends[frontend].instanceList && config.services[service].frontends.length > 1) {
const frontendDiv = document.getElementById(frontend) const frontendDiv = document.getElementById(frontend)
if (divs[service].frontend == null) {
console.log(frontend)
}
if (frontend == divs[service].frontend.value) { if (frontend == divs[service].frontend.value) {
frontendDiv.style.display = "block" frontendDiv.style.display = "block"
} else { } else {
@ -35,9 +36,11 @@ function changeFrontendsSettings(service) {
} }
} }
} }
}
function changeNetworkSettings(selectedNetwork) { function changeNetworkSettings(selectedNetwork) {
for (const frontend in config.frontends) { for (const frontend in config.frontends) {
if (config.services[service].frontends[frontend].instanceList) {
const frontendDiv = document.getElementById(frontend) const frontendDiv = document.getElementById(frontend)
for (const network in config.networks) { for (const network in config.networks) {
const networkDiv = frontendDiv.getElementsByClassName(network)[0] const networkDiv = frontendDiv.getElementsByClassName(network)[0]
@ -49,23 +52,22 @@ function changeNetworkSettings(selectedNetwork) {
} }
} }
} }
}
for (service in config.services) { for (const service in config.services) {
divs[service] = {}
divs[service][service] = document.getElementById(`${service}_page`) divs[service][service] = document.getElementById(`${service}_page`)
for (const option in config.services[service].options) { for (const option in config.services[service].options) {
divs[service][option] = document.getElementById(`${service}-${option}`) divs[service][option] = document.getElementById(`${service}-${option}`)
browser.storage.local.get([`${service + utils.camelCase(option)}`], r => { 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)] 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)] else divs[service][option].value = !r[service + utils.camelCase(option)]
}) })
divs[service][option].addEventListener("change", () => { divs[service][option].addEventListener("change", () => {
if (typeof config.services[service].options[option] == "boollean") { if (typeof config.services[service].options[option] == "boollean") browser.storage.local.set({ [service + utils.camelCase(option)]: divs[service][option].checked })
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 })
} else {
browser.storage.local.set({ [service + utils.camelCase(option)]: divs[service][option].value })
}
changeFrontendsSettings() changeFrontendsSettings()
}) })
} }
@ -74,9 +76,11 @@ for (service in config.services) {
changeNetworkSettings(network) changeNetworkSettings(network)
for (const frontend in config.services[service].frontends) { for (const frontend in config.services[service].frontends) {
if (config.services[service].frontends[frontend].instanceList) {
for (const network in config.networks) { for (const network in config.networks) {
utils.processDefaultCustomInstances(service, frontend, network, document) utils.processDefaultCustomInstances(service, frontend, network, document)
} }
utils.latency(service, frontend, document, location) utils.latency(service, frontend, document, location)
} }
} }
}

View File

@ -1,7 +1,7 @@
<section class="links" id="links"> <section class="links" id="links">
<div class="title"><img src="../../../assets/images/general-icon.svg"><a href="#general" data-localise="__MSG_general__">General</a></div> <div class="title"><img src="../../../assets/images/general-icon.svg"><a href="#general" data-localise="__MSG_general__">General</a></div>
<% for (const service in config.services) { %> <% for (const service in config.services) { -%>
<div class="title"><img src="../../../assets/images/<%= service %>-icon.<%= config.services[service].imageType %>"><a href="#<%= service %>" data-localise="__MSG_<%= service %>__"><%= service %></a></div> <div class="title"><img src="../../../assets/images/<%= service %>-icon.<%= config.services[service].imageType %>"><a href="#<%= service %>" data-localise="__MSG_<%= service %>__"><%= service %></a></div>
<% }; %> <% }; -%>
<div class="title"><img src="../../../assets/images/about-icon.svg"><a href="#about" data-localise="__MSG_about__">About</a></div> <div class="title"><img src="../../../assets/images/about-icon.svg"><a href="#about" data-localise="__MSG_about__">About</a></div>
</section> </section>