Added lbry desktop
Closes https://github.com/libredirect/libredirect/issues/365
This commit is contained in:
parent
2a0596f08f
commit
0803eb5e04
|
@ -8,7 +8,6 @@
|
||||||
{
|
{
|
||||||
"files": ["*.js", "*.json"],
|
"files": ["*.js", "*.json"],
|
||||||
"options": {
|
"options": {
|
||||||
"tabWidth": 2,
|
|
||||||
"singleQuote": false
|
"singleQuote": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -207,5 +207,8 @@
|
||||||
},
|
},
|
||||||
"protocolFallback": {
|
"protocolFallback": {
|
||||||
"message": "Fallback to normal if no instances are available for the current protocol"
|
"message": "Fallback to normal if no instances are available for the current protocol"
|
||||||
|
},
|
||||||
|
"lbryDesktop": {
|
||||||
|
"message": "LBRY Desktop"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ function setRedirects(val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let disableLbryTargets,
|
let disableLbryTargets,
|
||||||
|
lbryFrontend,
|
||||||
protocol,
|
protocol,
|
||||||
protocolFallback,
|
protocolFallback,
|
||||||
lbryTargetsRedirects,
|
lbryTargetsRedirects,
|
||||||
|
@ -48,6 +49,7 @@ function init() {
|
||||||
browser.storage.local.get(
|
browser.storage.local.get(
|
||||||
[
|
[
|
||||||
"disableLbryTargets",
|
"disableLbryTargets",
|
||||||
|
"lbryFrontend",
|
||||||
"protocol",
|
"protocol",
|
||||||
"protocolFallback",
|
"protocolFallback",
|
||||||
"lbryTargetsRedirects",
|
"lbryTargetsRedirects",
|
||||||
|
@ -61,6 +63,7 @@ function init() {
|
||||||
],
|
],
|
||||||
r => {
|
r => {
|
||||||
disableLbryTargets = r.disableLbryTargets
|
disableLbryTargets = r.disableLbryTargets
|
||||||
|
lbryFrontend = r.lbryFrontend
|
||||||
protocol = r.protocol
|
protocol = r.protocol
|
||||||
protocolFallback = r.protocolFallback
|
protocolFallback = r.protocolFallback
|
||||||
lbryTargetsRedirects = r.lbryTargetsRedirects
|
lbryTargetsRedirects = r.lbryTargetsRedirects
|
||||||
|
@ -120,17 +123,34 @@ function redirect(url, type, initiator, disableOverride) {
|
||||||
if (disableLbryTargets && !disableOverride) return
|
if (disableLbryTargets && !disableOverride) return
|
||||||
if (initiator && (all().includes(initiator.origin) || targets.includes(initiator.host))) return
|
if (initiator && (all().includes(initiator.origin) || targets.includes(initiator.host))) return
|
||||||
if (!targets.includes(url.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 = []
|
let instancesList = []
|
||||||
if (protocol == "loki") instancesList = [...librarianLokiCustomRedirects]
|
switch (lbryFrontend) {
|
||||||
else if (protocol == "i2p") instancesList = [...librarianI2pCustomRedirects]
|
case "librarian":
|
||||||
else if (protocol == "tor") instancesList = [...librarianTorRedirectsChecks, ...librarianTorCustomRedirects]
|
switch (protocol) {
|
||||||
if ((instancesList.length === 0 && protocolFallback) || protocol == "normal") {
|
case "loki":
|
||||||
instancesList = [...librarianNormalRedirectsChecks, ...librarianNormalCustomRedirects]
|
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)
|
const randomInstance = utils.getRandomInstance(instancesList)
|
||||||
return `${randomInstance}${url.pathname}${url.search}`
|
return `${randomInstance}${url.pathname}${url.search}`
|
||||||
}
|
}
|
||||||
|
@ -147,6 +167,7 @@ function initDefaults() {
|
||||||
browser.storage.local.set(
|
browser.storage.local.set(
|
||||||
{
|
{
|
||||||
disableLbryTargets: true,
|
disableLbryTargets: true,
|
||||||
|
lbryFrontend: "librarian",
|
||||||
lbryTargetsRedirects: redirects,
|
lbryTargetsRedirects: redirects,
|
||||||
|
|
||||||
librarianNormalRedirectsChecks: [...redirects.librarian.normal],
|
librarianNormalRedirectsChecks: [...redirects.librarian.normal],
|
||||||
|
|
|
@ -2,7 +2,7 @@ window.browser = window.browser || window.chrome
|
||||||
|
|
||||||
import utils from "./utils.js"
|
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 frontends = new Array("wikiless")
|
||||||
const protocols = new Array("normal", "tor", "i2p", "loki")
|
const protocols = new Array("normal", "tor", "i2p", "loki")
|
||||||
|
|
|
@ -2195,13 +2195,20 @@
|
||||||
</section>
|
</section>
|
||||||
<section class="option-block" id="lbry_page">
|
<section class="option-block" id="lbry_page">
|
||||||
<div class="some-block option-block">
|
<div class="some-block option-block">
|
||||||
<h1 data-localise="__MSG_lbry__">LBRY/Odysee</h1>
|
<h1 data-localise="__MSG_lbry__">LBRY</h1>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div class="some-block option-block">
|
<div class="some-block option-block">
|
||||||
<h4 data-localise="__MSG_enable__">Enable</h4>
|
<h4 data-localise="__MSG_enable__">Enable</h4>
|
||||||
<input id="lbry-enable" type="checkbox">
|
<input id="lbry-enable" type="checkbox">
|
||||||
</div>
|
</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">
|
<div id="librarian">
|
||||||
<hr>
|
<hr>
|
||||||
<div class="normal">
|
<div class="normal">
|
||||||
|
|
|
@ -1,27 +1,23 @@
|
||||||
import utils from "../../../assets/javascripts/utils.js"
|
import utils from "../../../assets/javascripts/utils.js"
|
||||||
|
|
||||||
// UNCOMMENT ALL COMMENTS ONCE OTHER FRONTENDS EXIST
|
|
||||||
|
|
||||||
const frontends = new Array("librarian")
|
const frontends = new Array("librarian")
|
||||||
const protocols = new Array("normal", "tor", "i2p", "loki")
|
const protocols = new Array("normal", "tor", "i2p", "loki")
|
||||||
|
|
||||||
const enable = document.getElementById("lbry-enable")
|
const enable = document.getElementById("lbry-enable")
|
||||||
const lbry = document.getElementById("lbry_page")
|
const lbry = document.getElementById("lbry_page")
|
||||||
//const frontend = document.getElementById("lbry-frontend");
|
const frontend = document.getElementById("lbry-frontend")
|
||||||
let protocol
|
let protocol
|
||||||
|
|
||||||
/*
|
|
||||||
function changeFrontendsSettings() {
|
function changeFrontendsSettings() {
|
||||||
for (let i = 0; i < frontends.length; i++) {
|
for (let i = 0; i < frontends.length; i++) {
|
||||||
const frontendDiv = document.getElementById(frontends[i])
|
const frontendDiv = document.getElementById(frontends[i])
|
||||||
if (frontends[i] == frontend.value) {
|
if (frontends[i] == frontend.value) {
|
||||||
frontendDiv.style.display = 'block'
|
frontendDiv.style.display = "block"
|
||||||
} else {
|
} else {
|
||||||
frontendDiv.style.display = 'none'
|
frontendDiv.style.display = "none"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
function changeProtocolSettings() {
|
function changeProtocolSettings() {
|
||||||
for (let i = 0; i < frontends.length; i++) {
|
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
|
enable.checked = !r.disableLbryTargets
|
||||||
protocol = r.protocol
|
protocol = r.protocol
|
||||||
|
frontend.value = r.lbryFrontend
|
||||||
|
changeFrontendsSettings()
|
||||||
changeProtocolSettings()
|
changeProtocolSettings()
|
||||||
})
|
})
|
||||||
|
|
||||||
lbry.addEventListener("change", () => {
|
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++) {
|
for (let i = 0; i < frontends.length; i++) {
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
section#lbry_page.option-block
|
section#lbry_page.option-block
|
||||||
.some-block.option-block
|
.some-block.option-block
|
||||||
h1(data-localise="__MSG_lbry__") LBRY/Odysee
|
h1(data-localise="__MSG_lbry__") LBRY
|
||||||
hr
|
hr
|
||||||
.some-block.option-block
|
.some-block.option-block
|
||||||
h4(data-localise="__MSG_enable__") Enable
|
h4(data-localise="__MSG_enable__") Enable
|
||||||
input#lbry-enable(type="checkbox")
|
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
|
#librarian
|
||||||
hr
|
hr
|
||||||
.normal
|
.normal
|
||||||
|
|
Loading…
Reference in New Issue