Fixed more bugs

This commit is contained in:
Hygna 2022-09-20 22:24:19 +01:00
parent 098e7368a7
commit 8f05957ffa
3 changed files with 45 additions and 50 deletions

View File

@ -25,14 +25,12 @@ function init() {
options.networkFallback = r.networkFallback
options.redirects = r.redirects
})
//cur = current
for (const service in config.services) {
options[service] = {}
browser.storage.local.get([`${utils.camelCase(service)}Enable`, `${service}RedirectType`, `${service}Frontend`], r => {
options[service].enabled = r[utils.camelCase(service) + "Enable"]
options[service].frontend = r[service + "Frontend"]
options[service].redirectType = r[service + "RedirectType"]
// console.log(r)
})
for (const frontend in config.services[service].frontends) {
options[frontend] = {}
@ -40,8 +38,6 @@ function init() {
options[frontend].custom = []
for (const network in config.networks) {
browser.storage.local.get([`${frontend}${utils.camelCase(network)}RedirectsChecks`, `${frontend}${utils.camelCase(network)}CustomRedirects`], r => {
// console.log(r)
// 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"]
})
@ -390,46 +386,45 @@ function initDefaults() {
.then(async data => {
let dataJson = JSON.parse(data)
redirects = dataJson
// console.log(redirects)
// console.log(config)
browser.storage.local.set({
redirects: redirects.invidious,
})
browser.storage.local.get(["cloudflareBlackList", "authenticateBlackList", "offlineBlackList"], async r => {
// console.log(r)
for (const service in config.services) {
if (config.services[service].targets == "datajson") {
browser.storage.local.set({ [service + "Targets"]: redirects[service] })
browser.storage.local.set({ [service + "Targets"]: [...dataJson[service]] })
delete redirects[service]
}
for (const defaultOption in config.services[service].defaults) {
browser.storage.local.set({ [service + camelCase(defaultOption)]: config.services[service].defaults[defaultOption] })
for (const defaultOption in config.services[service].options) {
browser.storage.local.set({ [service + utils.camelCase(defaultOption)]: config.services[service].options[defaultOption] })
}
for (const frontend in config.services[service].frontends) {
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])
switch (network) {
case "clearnet":
browser.storage.local.set({
[frontend + "ClearnetRedirectsChecks"]: [clearnetChecks],
[frontend + "ClearnetCustomRedirects"]: [],
})
break
default:
browser.storage.local.set({
[frontend + utils.camelCase(network) + "RedirectsChecks"]: [...redirects[frontend][network]],
[frontend + utils.camelCase(network) + "CustomRedirects"]: [],
})
if (config.services[service].frontends[frontend].instanceList) {
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) {
switch (network) {
case "clearnet":
browser.storage.local.set({
[frontend + "ClearnetRedirectsChecks"]: [...clearnetChecks],
[frontend + "ClearnetCustomRedirects"]: [],
})
break
default:
browser.storage.local.set({
[frontend + utils.camelCase(network) + "RedirectsChecks"]: [...redirects[frontend][network]],
[frontend + utils.camelCase(network) + "CustomRedirects"]: [],
})
}
}
}
}
}
;() => resolve()
})
browser.storage.local.set({
redirects,
})
;() => resolve()
})
})
}

View File

@ -22,7 +22,6 @@ with open('./src/config/config.json', 'rt') as tmp:
config['networks'] = json.load(tmp)['config']['networks']
def filterLastSlash(urlList):
tmp = {}
for x in urlList:
@ -106,7 +105,7 @@ def is_offline(url):
except:
return False
def fetchCache(frontend, name) :
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]
@ -125,7 +124,16 @@ def fetchJsonList(frontend, name, url, urlItem):
_list = {}
for network in config['networks']:
_list[network] = []
if type(urlItem) == 'str':
if type(urlItem) == dict:
for item in rJson:
for network in config['networks']:
if urlItem[network] != None:
if urlItem[network] in item:
if item[urlItem[network]].strip() != '':
_list[network].append(item[urlItem[network]])
else:
if frontend == 'librarian':
rJson = rJson['instances'] # I got lazy :p Might fix this at some point...
for item in rJson:
tmpItem = item
if urlItem is not None:
@ -140,14 +148,6 @@ def fetchJsonList(frontend, name, url, urlItem):
_list['loki'].append(tmpItem)
else:
_list['clearnet'].append(tmpItem)
else:
for i in range(len(config['networks']) - 1):
# 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)
@ -322,11 +322,11 @@ def libreddit():
def teddit():
fetchJsonList('teddit', 'Teddit', 'https://codeberg.org/teddit/teddit/raw/branch/main/instances.json', ['url', 'onion', 'i2p', None])
fetchJsonList('teddit', 'Teddit', 'https://codeberg.org/teddit/teddit/raw/branch/main/instances.json', { 'clearnet': 'url', 'tor': 'onion', 'i2p': 'i2p', 'loki': None })
def wikiless():
fetchJsonList('wikiless', 'Wikiless', 'https://wikiless.org/instances.json', ['url', 'onion', 'i2p', None])
fetchJsonList('wikiless', 'Wikiless', 'https://wikiless.org/instances.json', { 'clearnet': 'url', 'tor': 'onion', 'i2p': 'i2p', 'loki': None})
def scribe():
@ -419,7 +419,7 @@ def librex():
def rimgo():
fetchJsonList('rimgo', 'rimgo', 'https://codeberg.org/video-prize-ranch/rimgo/raw/branch/main/instances.json', ['url', 'onion', 'i2p', None])
fetchJsonList('rimgo', 'rimgo', 'https://codeberg.org/video-prize-ranch/rimgo/raw/branch/main/instances.json', {'clearnet': 'url', 'tor': 'onion', 'i2p': 'i2p', 'loki': None})
def librarian():

View File

@ -1,7 +1,7 @@
import utils from "../../../assets/javascripts/utils.js"
let config,
network,
selectedNetwork,
divs = {}
function getConfig() {
@ -19,7 +19,7 @@ function getConfig() {
await getConfig()
browser.storage.local.get("network", r => {
network = r.network
selectedNetwork = r.network
})
function changeFrontendsSettings(service) {
@ -54,6 +54,7 @@ function changeNetworkSettings(selectedNetwork) {
}
}
changeNetworkSettings(selectedNetwork)
for (const service in config.services) {
divs[service] = {}
divs[service][service] = document.getElementById(`${service}_page`)
@ -73,7 +74,6 @@ for (const service in config.services) {
}
changeFrontendsSettings(service)
changeNetworkSettings(network)
for (const frontend in config.services[service].frontends) {
if (config.services[service].frontends[frontend].instanceList) {