This commit is contained in:
ManeraKai 2022-07-31 11:57:59 +03:00
commit b3c44dfbd4
8 changed files with 157 additions and 74 deletions

View File

@ -0,0 +1,31 @@
---
name: "Report a bug"
about: "Is libredirect not behaving as expected? Report a bug so that it can be fixed as soon as possible."
labels:
- "Kind: Bug"
---
## What happened?
## What did you expect to happen?
## Steps to reproduce:
1.
2.
3.
<!-- and so on -->
## Debug information:
Browser and version number:
Libredirect version:
## Screenshots/Videos
<!--Just drag and drop any screenshots or videos you have of the issue below-->
<br>
<!--Put an "x" inbetween the brackets to confirm-->
[ ] I have checked on codeberg and github and can confirm this issue is not a duplicate.

View File

@ -0,0 +1,14 @@
---
name: "Suggest a new feature"
about: "Is there something missing that you want to see in libredirect? Suggest a feature so it will exist in a future release."
labels:
- "Kind: Feature"
---
## Describe your current issue/inconvinience
## Explain how this new feature will solve this
<br>
<!--Put an "x" inbetween the brackets to confirm-->
[ ] I have checked on codeberg and github and can confirm this issue is not a duplicate.

View File

@ -2,7 +2,7 @@ window.browser = window.browser || window.chrome
import utils from "./utils.js"
let targets = ["odysee.com"]
const targets = [/^https?:\/{2}odysee\.com/]
const frontends = new Array("librarian")
const protocols = new Array("normal", "tor", "i2p", "loki")
@ -36,6 +36,7 @@ let disableLbryTargets,
protocol,
protocolFallback,
lbryTargetsRedirects,
lbryRedirectType,
librarianNormalRedirectsChecks,
librarianNormalCustomRedirects,
librarianTorRedirectsChecks,
@ -53,6 +54,7 @@ function init() {
"protocol",
"protocolFallback",
"lbryTargetsRedirects",
"lbryRedirectType",
"librarianNormalRedirectsChecks",
"librarianNormalCustomRedirects",
"librarianTorRedirectsChecks",
@ -67,6 +69,7 @@ function init() {
protocol = r.protocol
protocolFallback = r.protocolFallback
lbryTargetsRedirects = r.lbryTargetsRedirects
lbryRedirectType = r.lbryRedirectType
librarianNormalRedirectsChecks = r.librarianNormalRedirectsChecks
librarianNormalCustomRedirects = r.librarianNormalCustomRedirects
librarianTorRedirectsChecks = r.librarianTorRedirectsChecks
@ -86,6 +89,24 @@ function all() {
return [...redirects.librarian.normal, ...redirects.librarian.tor, ...librarianNormalCustomRedirects, ...librarianTorCustomRedirects, ...librarianI2pCustomRedirects, ...librarianLokiCustomRedirects]
}
function getInstancesList() {
let tmpList = []
switch (protocol) {
case "loki":
tmpList = [...librarianLokiCustomRedirects]
break
case "i2p":
tmpList = [...librarianI2pRedirectsChecks, ...librarianI2pCustomRedirects]
break
case "tor":
tmpList = [...librarianTorRedirectsChecks, ...librarianTorCustomRedirects]
}
if ((tmpList.length === 0 && protocolFallback) || protocol == "normal") {
tmpList = [...librarianNormalRedirectsChecks, ...librarianNormalCustomRedirects]
}
return tmpList
}
function switchInstance(url, disableOverride) {
return new Promise(async resolve => {
await init()
@ -122,37 +143,27 @@ function switchInstance(url, disableOverride) {
function redirect(url, type, initiator, disableOverride) {
if (disableLbryTargets && !disableOverride) return
if (initiator && (all().includes(initiator.origin) || targets.includes(initiator.host))) return
if (!targets.includes(url.host)) return
if (type != ("main_frame" || "sub_frame")) return
//https://odysee.com/$/embed/the-anti-smartphone-revolution/22b482e450c4ca13c464eee8f51b3a52bbb942ae?r=7pAWcQybShS63wz486r8wVv9FpsDJ47A
// to
//https://{instance}/embed/@Coldfusion:f/the-anti-smartphone-revolution:2
if (!targets.some(rx => rx.test(url.href))) return
if ((type == "main_frame" && lbryRedirectType == "sub_frame") || (type == "sub_frame" && lbryRedirectType == "main_frame")) return
let instancesList = []
const instancesList = getInstancesList()
switch (type) {
case "main_frame":
switch (lbryFrontend) {
case "librarian":
switch (protocol) {
case "loki":
instancesList = [...librarianLokiCustomRedirects]
break
case "i2p":
instancesList = [...librarianI2pRedirectsChecks, ...librarianI2pCustomRedirects]
break
case "tor":
instancesList = [...librarianTorRedirectsChecks, ...librarianTorCustomRedirects]
}
if ((instancesList.length === 0 && protocolFallback) || protocol == "normal") {
instancesList = [...librarianNormalRedirectsChecks, ...librarianNormalCustomRedirects]
}
break
if (instancesList.length === 0) return
const randomInstance = utils.getRandomInstance(instancesList)
return `${randomInstance}${url.pathname}${url.search}`
case "lbryDesktop":
if (type == "main_frame") {
return url.href.replace(/^https?:\/{2}odysee\.com\//, "lbry://").replace(/:(?=[a-zA-Z0-9])/g, "#")
}
if (instancesList.length === 0) return
}
case "sub_frame":
if (instancesList.length === 0) return
const randomInstance = utils.getRandomInstance(instancesList)
return `${randomInstance}${url.pathname}${url.search}`
return `${randomInstance}${url.pathname}${url.search}`.replace(/\/(?=[a-f0-9]{40})/, ":")
}
}
function initDefaults() {
@ -169,6 +180,7 @@ function initDefaults() {
disableLbryTargets: true,
lbryFrontend: "librarian",
lbryTargetsRedirects: redirects,
lbryRedirectType: "both",
librarianNormalRedirectsChecks: [...redirects.librarian.normal],
librarianNormalCustomRedirects: [],

View File

@ -40,9 +40,19 @@ async function initcloudflareBlackList() {
function updateInstances() {
return new Promise(async resolve => {
let http = new XMLHttpRequest()
let fallback = new XMLHttpRequest()
http.open("GET", "https://raw.githubusercontent.com/libredirect/libredirect/master/src/instances/data.json", false)
http.send(null)
if (http.status === 200) {
if (http.status != 200) {
fallback.open("GET", "https://codeberg.org/LibRedirect/libredirect/raw/branch/master/src/instances/data.json", false)
fallback.send(null)
if (fallback.status === 200) {
http = fallback
} else {
resolve()
return
}
}
await initcloudflareBlackList()
const instances = JSON.parse(http.responseText)
@ -85,8 +95,6 @@ function updateInstances() {
console.info("Successfully updated Instances")
resolve(true)
return
}
resolve()
})
}

View File

@ -431,7 +431,7 @@ def searx_searxng():
searxngList['tor'].append(item[:-1])
else:
searxList['tor'].append(item[:-1])
elif re.search(torRegex, item[:-1]):
elif re.search(i2pRegex, item[:-1]):
if (rJson['instances'][item].get('generator') == 'searxng'):
searxngList['i2p'].append(item[:-1])
else:

View File

@ -2209,6 +2209,14 @@
<option value="lbryDesktop" data-localise="__MSG_lbryDesktop__">LBRY Desktop</option>
</select>
</div>
<div class="some-block option-block">
<h4 data-localise="__MSG_redirectType__">Redirect Type</h4>
<select id="lbry-redirect_type">
<option value="both" data-localise="__MSG_both__">both</option>
<option value="sub_frame" data-localise="__MSG_onlyEmbedded__">Only Embedded</option>
<option value="main_frame" data-localise="__MSG_onlyNotEmbedded__">Only Not Embedded</option>
</select>
</div>
<div id="librarian">
<hr>
<div class="normal">

View File

@ -5,6 +5,7 @@ const protocols = new Array("normal", "tor", "i2p", "loki")
const enable = document.getElementById("lbry-enable")
const lbry = document.getElementById("lbry_page")
const redirectType = document.getElementById("lbry-redirect_type")
const frontend = document.getElementById("lbry-frontend")
let protocol
@ -33,9 +34,10 @@ function changeProtocolSettings() {
}
}
browser.storage.local.get(["disableLbryTargets", "protocol", "lbryFrontend"], r => {
browser.storage.local.get(["disableLbryTargets", "protocol", "lbryFrontend", "lbryRedirectType"], r => {
enable.checked = !r.disableLbryTargets
protocol = r.protocol
redirectType.value = r.lbryRedirectType
frontend.value = r.lbryFrontend
changeFrontendsSettings()
changeProtocolSettings()
@ -44,6 +46,7 @@ browser.storage.local.get(["disableLbryTargets", "protocol", "lbryFrontend"], r
lbry.addEventListener("change", () => {
browser.storage.local.set({
disableLbryTargets: !enable.checked,
lbryRedirectType: redirectType.value,
lbryFrontend: frontend.value,
})
changeFrontendsSettings()

View File

@ -12,6 +12,13 @@ section#lbry_page.option-block
option(value="librarian") Librarian
option(value="lbryDesktop" data-localise="__MSG_lbryDesktop__") LBRY Desktop
.some-block.option-block
h4(data-localise="__MSG_redirectType__") Redirect Type
select#lbry-redirect_type
option(value="both" data-localise="__MSG_both__") both
option(value="sub_frame" data-localise="__MSG_onlyEmbedded__") Only Embedded
option(value="main_frame" data-localise="__MSG_onlyNotEmbedded__") Only Not Embedded
#librarian
hr
.normal