Added lbry desktop

Closes https://github.com/libredirect/libredirect/issues/365
This commit is contained in:
BobIsMyManager 2022-07-27 11:05:49 +01:00
parent 2a0596f08f
commit 0803eb5e04
7 changed files with 65 additions and 27 deletions

View File

@ -8,7 +8,6 @@
{
"files": ["*.js", "*.json"],
"options": {
"tabWidth": 2,
"singleQuote": false
}
},

View File

@ -207,5 +207,8 @@
},
"protocolFallback": {
"message": "Fallback to normal if no instances are available for the current protocol"
},
"lbryDesktop": {
"message": "LBRY Desktop"
}
}

View File

@ -32,6 +32,7 @@ function setRedirects(val) {
}
let disableLbryTargets,
lbryFrontend,
protocol,
protocolFallback,
lbryTargetsRedirects,
@ -48,6 +49,7 @@ function init() {
browser.storage.local.get(
[
"disableLbryTargets",
"lbryFrontend",
"protocol",
"protocolFallback",
"lbryTargetsRedirects",
@ -61,6 +63,7 @@ function init() {
],
r => {
disableLbryTargets = r.disableLbryTargets
lbryFrontend = r.lbryFrontend
protocol = r.protocol
protocolFallback = r.protocolFallback
lbryTargetsRedirects = r.lbryTargetsRedirects
@ -120,17 +123,34 @@ 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") 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
let instancesList = []
if (protocol == "loki") instancesList = [...librarianLokiCustomRedirects]
else if (protocol == "i2p") instancesList = [...librarianI2pCustomRedirects]
else if (protocol == "tor") instancesList = [...librarianTorRedirectsChecks, ...librarianTorCustomRedirects]
if ((instancesList.length === 0 && protocolFallback) || protocol == "normal") {
instancesList = [...librarianNormalRedirectsChecks, ...librarianNormalCustomRedirects]
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
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
}
if (instancesList.length === 0) return
const randomInstance = utils.getRandomInstance(instancesList)
return `${randomInstance}${url.pathname}${url.search}`
}
@ -147,6 +167,7 @@ function initDefaults() {
browser.storage.local.set(
{
disableLbryTargets: true,
lbryFrontend: "librarian",
lbryTargetsRedirects: redirects,
librarianNormalRedirectsChecks: [...redirects.librarian.normal],

View File

@ -2,7 +2,7 @@ window.browser = window.browser || window.chrome
import utils from "./utils.js"
const targets = /^https?:\/{2}(([a-z]{1,}\.){0,})wikipedia\.org/
const targets = /^https?:\/{2}([a-z]+\.)*wikipedia\.org/
const frontends = new Array("wikiless")
const protocols = new Array("normal", "tor", "i2p", "loki")

View File

@ -2195,13 +2195,20 @@
</section>
<section class="option-block" id="lbry_page">
<div class="some-block option-block">
<h1 data-localise="__MSG_lbry__">LBRY/Odysee</h1>
<h1 data-localise="__MSG_lbry__">LBRY</h1>
</div>
<hr>
<div class="some-block option-block">
<h4 data-localise="__MSG_enable__">Enable</h4>
<input id="lbry-enable" type="checkbox">
</div>
<div class="some-block option-block">
<h4 data-localise="__MSG_frontend__">Frontend</h4>
<select id="lbry-frontend">
<option value="librarian">Librarian</option>
<option value="lbryDesktop" data-localise="__MSG_lbryDesktop__">LBRY Desktop</option>
</select>
</div>
<div id="librarian">
<hr>
<div class="normal">

View File

@ -1,27 +1,23 @@
import utils from "../../../assets/javascripts/utils.js"
// UNCOMMENT ALL COMMENTS ONCE OTHER FRONTENDS EXIST
const frontends = new Array("librarian")
const protocols = new Array("normal", "tor", "i2p", "loki")
const enable = document.getElementById("lbry-enable")
const lbry = document.getElementById("lbry_page")
//const frontend = document.getElementById("lbry-frontend");
const frontend = document.getElementById("lbry-frontend")
let protocol
/*
function changeFrontendsSettings() {
for (let i = 0; i < frontends.length; i++) {
const frontendDiv = document.getElementById(frontends[i])
if (frontends[i] == frontend.value) {
frontendDiv.style.display = 'block'
} else {
frontendDiv.style.display = 'none'
}
}
for (let i = 0; i < frontends.length; i++) {
const frontendDiv = document.getElementById(frontends[i])
if (frontends[i] == frontend.value) {
frontendDiv.style.display = "block"
} else {
frontendDiv.style.display = "none"
}
}
}
*/
function changeProtocolSettings() {
for (let i = 0; i < frontends.length; i++) {
@ -37,14 +33,20 @@ function changeProtocolSettings() {
}
}
browser.storage.local.get(["disableLbryTargets", "protocol"], r => {
browser.storage.local.get(["disableLbryTargets", "protocol", "lbryFrontend"], r => {
enable.checked = !r.disableLbryTargets
protocol = r.protocol
frontend.value = r.lbryFrontend
changeFrontendsSettings()
changeProtocolSettings()
})
lbry.addEventListener("change", () => {
browser.storage.local.set({ disableLbryTargets: !enable.checked })
browser.storage.local.set({
disableLbryTargets: !enable.checked,
lbryFrontend: frontend.value,
})
changeFrontendsSettings()
})
for (let i = 0; i < frontends.length; i++) {

View File

@ -1,11 +1,17 @@
section#lbry_page.option-block
.some-block.option-block
h1(data-localise="__MSG_lbry__") LBRY/Odysee
h1(data-localise="__MSG_lbry__") LBRY
hr
.some-block.option-block
h4(data-localise="__MSG_enable__") Enable
input#lbry-enable(type="checkbox")
.some-block.option-block
h4(data-localise="__MSG_frontend__") Frontend
select#lbry-frontend
option(value="librarian") Librarian
option(value="lbryDesktop" data-localise="__MSG_lbryDesktop__") LBRY Desktop
#librarian
hr
.normal