aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/assets/javascripts/services.js38
-rw-r--r--src/pages/background/background.js34
-rw-r--r--src/pages/messages_src/App.svelte17
-rw-r--r--src/pages/popup_src/Buttons.svelte17
4 files changed, 61 insertions, 45 deletions
diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js
index 243f0598..d19d8aa2 100644
--- a/src/assets/javascripts/services.js
+++ b/src/assets/javascripts/services.js
@@ -66,7 +66,6 @@ function rewrite(url, originUrl, frontend, randomInstance) {
case "searx":
case "searxng":
for (const key of [...url.searchParams.keys()]) if (key !== "q") url.searchParams.delete(key)
- console.log(url.searchParams)
return `${randomInstance}/${url.search}`
case "whoogle":
for (const key of [...url.searchParams.keys()]) if (key !== "q") url.searchParams.delete(key)
@@ -658,7 +657,7 @@ function computeService(url) {
return
} else {
for (const frontend in config.services[service].frontends) {
- if (all(service, frontend, options, config).includes(utils.protocolHost(url))) {
+ if (all(service, frontend, options, config).findIndex(instance => url.href.startsWith(instance)) >= 0) {
return resolve(service)
}
}
@@ -670,8 +669,8 @@ function computeService(url) {
export function computeFrontend(url) {
for (const service in config.services) {
for (const frontend in config.services[service].frontends) {
- if (all(service, frontend, options, config).includes(utils.protocolHost(url))) {
- return {service, frontend}
+ if (all(service, frontend, options, config).findIndex(instance => url.href.startsWith(instance)) >= 0) {
+ return { service, frontend }
}
}
}
@@ -692,25 +691,20 @@ function switchInstance(url, customService) {
if (instancesList !== undefined) {
const newInstance = utils.getNextInstance(url.origin, instancesList)
if (newInstance) {
- resolve(`${newInstance}${url.pathname}${url.search}`)
- return
+ return resolve(`${newInstance}${url.pathname}${url.search}`)
}
}
} else {
for (const service in config.services) {
let instancesList = options[options[service].frontend]
if (instancesList === undefined) continue
- if (!instancesList.includes(protocolHost)) continue
-
- instancesList.splice(instancesList.indexOf(protocolHost), 1)
- if (instancesList.length === 0) {
- resolve()
- return
- }
+ const index = instancesList.findIndex(instance => url.href.startsWith(instance))
+ if (index < 0) continue
+ instancesList.splice(index, 1)
+ if (instancesList.length === 0) return resolve()
const newInstance = utils.getNextInstance(url.origin, instancesList)
if (newInstance) {
- resolve(`${newInstance}${url.pathname}${url.search}`)
- return
+ return resolve(`${newInstance}${url.pathname}${url.search}`)
}
}
}
@@ -724,11 +718,14 @@ function switchInstance(url, customService) {
async function reverse(url) {
let options = await utils.getOptions()
let config = await utils.getConfig()
- let protocolHost = utils.protocolHost(url)
for (const service in config.services) {
let frontend = options[service].frontend
if (options[frontend] == undefined) continue
- if (!options[frontend].includes(protocolHost) && protocolHost != `http://${frontend}.localhost:8080`) continue
+ if (
+ options[frontend].findIndex(instance => url.href.startsWith(instance)) < 0 &&
+ !url.href.startsWith(`http://${frontend}.localhost:8080`)
+ )
+ continue
switch (service) {
case "youtube":
case "imdb":
@@ -776,7 +773,6 @@ async function reverse(url) {
}
const defaultInstances = {
- // invidious: ["https://inv.vern.cc"],
materialious: ["https://app.materialio.us"],
viewtube: ["https://viewtube.io"],
piped: ["https://pipedapi-libre.kavin.rocks"],
@@ -786,8 +782,6 @@ const defaultInstances = {
poketube: ["https://poketube.fun"],
proxiTok: ["https://proxitok.pabloferreiro.es"],
redlib: ["https://safereddit.com"],
- libreddit: ["https://libreddit.spike.codes"],
- teddit: ["https://teddit.net"],
eddrit: ["https://eddrit.com"],
scribe: ["https://scribe.rip"],
libMedium: ["https://md.vern.cc"],
@@ -807,15 +801,11 @@ const defaultInstances = {
intellectual: ["https://intellectual.insprill.net"],
ruralDictionary: ["https://rd.vern.cc"],
anonymousOverflow: ["https://code.whatever.social"],
- biblioReads: ["https://biblioreads.ml"],
- wikiless: ["https://wikiless.org"],
suds: ["https://sd.vern.cc"],
unfunny: ["https://uf.vern.cc"],
soprano: ["https://sp.vern.cc"],
meme: ["https://mm.vern.cc"],
waybackClassic: ["https://wayback-classic.net"],
- gothub: ["https://gh.odyssey346.dev"],
- mikuInvidious: ["https://mikuinv.resrv.org"],
tent: ["https://tent.sny.sh"],
wolfreeAlpha: ["https://gqq.gitlab.io", "https://uqq.gitlab.io"],
laboratory: ["https://lab.vern.cc"],
diff --git a/src/pages/background/background.js b/src/pages/background/background.js
index 0d558b01..1fcba190 100644
--- a/src/pages/background/background.js
+++ b/src/pages/background/background.js
@@ -67,16 +67,22 @@ browser.webRequest.onBeforeRequest.addListener(
tabIdRedirects[details.tabId]
)
- if (newUrl && newUrl.startsWith("https://no-instance.libredirect.invalid")) {
- const url = new URL(newUrl)
- const frontend = url.searchParams.get("frontend")
- const oldUrl = new URL(url.searchParams.get("url"))
+ if (
+ (newUrl && newUrl.startsWith("https://no-instance.libredirect.invalid")) ||
+ (!newUrl && url.href.startsWith("https://no-instance.libredirect.invalid"))
+ ) {
+ newUrl = newUrl ? new URL(newUrl) : url
+ const frontend = newUrl.searchParams.get("frontend")
+ const oldUrl = new URL(newUrl.searchParams.get("url"))
const params = new URLSearchParams({
message: "no_instance",
url: oldUrl,
frontend: frontend,
})
- newUrl = browser.runtime.getURL(`/pages/messages/index.html?${params.toString()}`)
+ browser.tabs.update({
+ url: browser.runtime.getURL(`/pages/messages/index.html?${params.toString()}`),
+ })
+ return { cancel: true }
}
if (!newUrl) {
@@ -85,7 +91,10 @@ browser.webRequest.onBeforeRequest.addListener(
message: "disabled",
url: url.href,
})
- newUrl = browser.runtime.getURL(`/pages/messages/index.html?${params.toString()}`)
+ browser.tabs.update({
+ url: browser.runtime.getURL(`/pages/messages/index.html?${params.toString()}`),
+ })
+ return { cancel: true }
}
}
@@ -121,9 +130,11 @@ browser.webRequest.onHeadersReceived.addListener(
frontend: frontend,
service: service,
})
- browser.tabs.update({
- url: browser.runtime.getURL(`/pages/messages/index.html?${params.toString()}`),
- })
+ setTimeout(() => {
+ browser.tabs.update({
+ url: browser.runtime.getURL(`/pages/messages/index.html?${params.toString()}`),
+ })
+ }, 2000)
}
},
{ urls: ["<all_urls>"] }
@@ -365,3 +376,8 @@ browser.runtime.getPlatformInfo(r => {
})
}
})
+
+browser.runtime.onMessage.addListener(r => {
+ if (r.message == "reverse") tabIdRedirects[r.tabId] = false
+ else if (r.message == "redirect") tabIdRedirects[r.tabId] = true
+})
diff --git a/src/pages/messages_src/App.svelte b/src/pages/messages_src/App.svelte
index 6d68ff5f..1c5170dd 100644
--- a/src/pages/messages_src/App.svelte
+++ b/src/pages/messages_src/App.svelte
@@ -33,7 +33,6 @@
await servicesHelper.initDefaults()
opts = await utils.getOptions()
}
- redirects = await utils.getList(opts)
options.set(opts)
config.set(await utils.getConfig())
})
@@ -45,7 +44,6 @@
$: if (_options) style = utils.style(_options, window)
let autoPicking = false
- let redirects
const params = new URLSearchParams(window.location.search)
const oldUrl = new URL(params.get("url"))
@@ -53,10 +51,14 @@
async function autoPick() {
const frontend = params.get("frontend")
autoPicking = true
+ const redirects = await utils.getList(_options)
const instances = utils.randomInstances(redirects[frontend]["clearnet"], 5)
- const pings = await Promise.all([...instances.map(async instance => [instance, await utils.ping(instance)])])
+ const pings = await Promise.all([
+ ...instances.map(async instance => {
+ return [instance, await utils.ping(instance)]
+ }),
+ ])
pings.sort((a, b) => a[1] - b[1])
- console.log(pings)
_options[frontend].push(pings[0][0])
options.set(_options)
autoPicking = false
@@ -85,8 +87,9 @@
}
async function removeInstance() {
+ const service = await servicesHelper.computeService(oldUrl)
const frontend = params.get("frontend")
- const i = _options[frontend].indexOf(utils.protocolHost(oldUrl))
+ const i = _options[frontend].findIndex(instance => oldUrl.href.startsWith(instance))
_options[frontend].splice(i, 1)
options.set(_options)
const newUrl = await servicesHelper.switchInstance(oldUrl, service)
@@ -94,8 +97,10 @@
}
async function removeAndAutoPickInstance() {
+ const service = await servicesHelper.computeService(oldUrl)
+
const frontend = params.get("frontend")
- const i = _options[frontend].indexOf(utils.protocolHost(oldUrl))
+ const i = _options[frontend].findIndex(instance => oldUrl.href.startsWith(instance))
_options[frontend].splice(i, 1)
options.set(_options)
await autoPick()
diff --git a/src/pages/popup_src/Buttons.svelte b/src/pages/popup_src/Buttons.svelte
index c0644ff7..ab5682dc 100644
--- a/src/pages/popup_src/Buttons.svelte
+++ b/src/pages/popup_src/Buttons.svelte
@@ -44,8 +44,10 @@
<Row
class="interactive"
on:click={() => {
- browser.tabs.update({ url: redirect }, () => {
- window.close()
+ browser.tabs.query({ active: true, currentWindow: true }, tabs => {
+ browser.runtime.sendMessage({ message: "redirect", tabId: tabs[0].id }, () => {
+ browser.tabs.update({ url: redirect })
+ })
})
}}
>
@@ -74,10 +76,13 @@
</Row>
<Row
class="interactive"
- on:click={() =>
- browser.tabs.update({ url: redirectToOriginal }, () => {
- window.close()
- })}
+ on:click={() => {
+ browser.tabs.query({ active: true, currentWindow: true }, tabs => {
+ browser.runtime.sendMessage({ message: "reverse", tabId: tabs[0].id }, () => {
+ browser.tabs.update({ url: redirectToOriginal })
+ })
+ })
+ }}
>
<Label>{browser.i18n.getMessage("redirectToOriginal" || "Redirect to Original")}</Label>
<RedirectToOriginalIcon />