Changed some regex

Made ejs no longer need extra config member variable

Added url reversal
This commit is contained in:
Hygna 2022-09-26 18:32:32 +01:00
parent 01bb150213
commit 378fab21c0
10 changed files with 571 additions and 578 deletions

View File

@ -11,8 +11,7 @@ async function getConfig() {
fetch("/config/config.json")
.then(response => response.text())
.then(data => {
const tmp = JSON.parse(data)
config = tmp.config
config = JSON.parse(data)
resolve()
})
})
@ -55,7 +54,7 @@ function all(service) {
for (const frontend in config.services[service].frontends) {
if (config.services[service].frontends[frontend].instanceList) {
for (const network in config.networks) {
tmp.push(...redirects[frontend][network])
tmp.push(...redirects[frontend][network], ...options[frontend][network].custom)
}
} else if (config.services[service].frontends[frontend].singleInstance != undefined) tmp.push(config.services[service].frontends[frontend].singleInstance)
}
@ -168,10 +167,10 @@ function redirect(url, type, initiator) {
} else if (url.pathname.split("/").includes("tweets")) return `${randomInstance}${url.pathname.replace("/tweets", "")}${url.search}`
else if (url.host == "t.co") return `${randomInstance}/t.co${url.pathname}`
else return `${randomInstance}${url.pathname}${url.search}`
case "yatte":
case "yattee":
return url.href.replace(/^https?:\/{2}/, "yattee://")
case "freetube":
return `freetube://https://youtube.com${url.pathname}${url.search}`
return `freetube://https://youtu.be${url.pathname}${url.search}`.replace(/watch\?v=/, "")
case "simplyTranslate":
return `${randomInstance}/${url.search}`
case "osm": {
@ -462,9 +461,9 @@ function switchInstance(url) {
return new Promise(async resolve => {
await init()
await getConfig()
const protocolHost = utils.protocolHost(url)
for (const service in config.services) {
if (!options[service].enabled) continue
const protocolHost = utils.protocolHost(url)
if (!all(service).includes(protocolHost)) continue
let instancesList = [...options[options[service].frontend][options.network].checks, ...options[options[service].frontend][options.network].custom]
@ -485,15 +484,44 @@ function switchInstance(url) {
// This is to make instance switching work when the instance depends on the pathname, eg https://darmarit.org/searx
// Doesn't work because of .includes array method, not a top priotiry atm
resolve(oldUrl.replace(oldInstance, randomInstance))
return
}
resolve()
})
}
function reverse(url) {
return new Promise(async resolve => {
await init()
await getConfig()
let protocolHost = utils.protocolHost(url)
let currentService
for (const service in config.services) {
if (!all(service).includes(protocolHost)) continue
currentService = service
}
switch (currentService) {
case "instagram":
if (url.pathname.startsWith("/p")) resolve(`https://instagram.com${url.pathname.replace("/p", "")}${url.search}`)
if (url.pathname.startsWith("/u")) resolve(`https://instagram.com${url.pathname.replace("/u", "")}${url.search}`)
case "youtube":
case "imdb":
case "imgur":
case "tiktok":
case "twitter":
resolve(config.services[currentService].url + url.pathname + url.search)
return
default:
resolve()
return
}
})
}
export default {
redirect,
initDefaults,
computeService,
switchInstance,
init,
reverse,
}

View File

@ -408,13 +408,7 @@ function copyRaw(test, copyRawElement) {
return
}
let newUrl = await youtubeHelper.reverse(url)
if (!newUrl) newUrl = await twitterHelper.reverse(url)
if (!newUrl) newUrl = await instagramHelper.reverse(url)
if (!newUrl) newUrl = await tiktokHelper.reverse(url)
if (!newUrl) newUrl = await quoraHelper.reverse(url)
if (!newUrl) newUrl = await libremdbHelper.reverse(url)
if (!newUrl) newUrl = await imgurHelper.reverse(url)
let newUrl = await servicesHelper.reverse(url)
if (newUrl) {
resolve(newUrl)

File diff suppressed because it is too large Load Diff

View File

@ -286,31 +286,7 @@ def send():
def nitter():
r = requests.get('https://raw.githubusercontent.com/wiki/zedeus/nitter/Instances.md')
tmp = re.findall(
r"(?:(?:\| \[(?:\S+\.)+[a-zA-Z]+\]\((https?:\/{2}(?:\S+\.)+[a-zA-Z]+)\/?\) (?:\((?:\S+ ?\S*)\) )? *\| [^❌]{1,3} +\|(?:(?:\n)|(?: (?:❌)|(?: ✅)|(?: ❓)|(?: \[))))|(?:- \[(?:\S+\.)+(?:(?:i2p)|(?:loki))\]\((https?:\/{2}(?:\S+\.)(?:(?:i2p)|(?:loki)))\/?\)))", r.text)
nitterList = {}
nitterList['clearnet'] = []
nitterList['tor'] = []
nitterList['i2p'] = []
nitterList['loki'] = []
for item in tmp:
for i in item:
if i == '':
continue
else:
item = i
if re.search(torRegex, item):
nitterList['tor'].append(item)
elif re.search(i2pRegex, item):
nitterList['i2p'].append(item)
elif re.search(lokiRegex, item):
nitterList['loki'].append(item)
else:
nitterList['clearnet'].append(item)
mightyList['nitter'] = nitterList
print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Nitter')
fetchRegexList('nitter', 'Nitter', 'https://raw.githubusercontent.com/wiki/zedeus/nitter/Instances.md', r"(?:(?:\| )|(?:- ))\[(?:(?:\S+\.)+[a-zA-Z0-9]+)\/?\]\((https?:\/{2}(?:\S+\.)+[a-zA-Z0-9]+)\/?\)(?:(?: (?:\((?:\S+ ?\S*)\) )? *\| [^❌]{1,4} +\|(?:(?:\n)|(?: ❌)|(?: ✅)|(?: ❓)|(?: \[)))|(?:\n))")
def bibliogram():
@ -334,11 +310,11 @@ def scribe():
def quetre():
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,}.*\|.*\|")
fetchRegexList('quetre', 'Quetre', 'https://raw.githubusercontent.com/zyachel/quetre/main/README.md', r"\| \[.*\]\(([-a-zA-Z0-9@:%_\+.~#?&//=]{2,}\.[a-z0-9]{2,}\b(?:\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?)\)*\|*[A-Z]{0,}.*\|.*\|")
def libremdb():
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,}.*\|.*\|")
fetchRegexList('libremdb', 'libremdb', 'https://raw.githubusercontent.com/zyachel/libremdb/main/README.md', r"\| \[.*\]\(([-a-zA-Z0-9@:%_\+.~#?&//=]{2,}\.[a-z0-9]{2,}\b(?:\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?)\)*\|*[A-Z]{0,}.*\|.*\|")
def simpleertube():

View File

@ -2,10 +2,10 @@
<html id="elementToShowWithJavaScript" lang="en">
<%- include('src/pages/widgets/head') -%>
<body class="option" dir="auto">
<%- include('src/pages/widgets/links', {config: config}) -%>
<%- include('src/pages/widgets/links', {services: services}) -%>
<div id="pages">
<%- include('src/pages/options/widgets/general', {config: config}) -%>
<%- include('src/pages/options/widgets/services', {config: config}) -%>
<%- include('src/pages/options/widgets/general', {config: {networks, services}}) -%>
<%- include('src/pages/options/widgets/services', {config: {networks, services}}) -%>
<%- include('src/pages/options/widgets/about') -%>
</div>
</body>

View File

@ -22,8 +22,7 @@ async function getConfig() {
fetch("/config/config.json")
.then(response => response.text())
.then(data => {
const tmp = JSON.parse(data)
config = tmp.config
config = JSON.parse(data)
resolve()
})
})

View File

@ -9,8 +9,7 @@ function getConfig() {
fetch("/config/config.json")
.then(response => response.text())
.then(data => {
const tmp = JSON.parse(data)
config = tmp.config
config = JSON.parse(data)
resolve()
})
})

View File

@ -8,13 +8,13 @@
</head>
<body dir="auto">
<div class="current_site">
<%- include('src/pages/widgets/switches', {config: config}) -%>
<%- include('src/pages/widgets/switches', {config: {networks, services}}) -%>
<div id="current_site_divider">
<hr>
</div>
</div>
<div class="all_sites">
<%- include('src/pages/widgets/switches', {config: config}) -%>
<%- include('src/pages/widgets/switches', {config: {networks, services}}) -%>
</div>
<hr>
<div class="some-block" id="change_instance_div"><a class="title button prevent" id="change_instance">

View File

@ -27,8 +27,7 @@ async function getConfig() {
fetch("/config/config.json")
.then(response => response.text())
.then(data => {
const tmp = JSON.parse(data)
config = tmp.config
config = JSON.parse(data)
resolve()
})
})

View File

@ -1,13 +1,13 @@
<section class="links" id="links">
<div class="title"><%- include ('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 services) { -%>
<div class="title">
<% if (config.services[service].imageType != "svgMono") { _%>
<img src="../../../assets/images/<%= service %>-icon.<%= config.services[service].imageType %>">
<% if (services[service].imageType != "svgMono") { _%>
<img src="../../../assets/images/<%= service %>-icon.<%= services[service].imageType %>">
<% } else { _%>
<%- include ('src/assets/images/' + service + '-icon.svg') %>
<% } _%>
<a href="#<%= service %>" data-localise="__MSG_<%= service %>__"><%= config.services[service].name %></a></div>
<a href="#<%= service %>" data-localise="__MSG_<%= service %>__"><%= services[service].name %></a></div>
<% }; -%>
<div class="title"><%- include ('src/assets/images/about-icon.svg') %><a href="#about" data-localise="__MSG_about__">About</a></div>
</section>