Added option to use github, codeberg, disable for fetching instances https://github.com/libredirect/libredirect/issues/626
This commit is contained in:
parent
d0961f5d1f
commit
356fd321d9
|
@ -618,6 +618,7 @@ function initDefaults() {
|
||||||
}
|
}
|
||||||
options['theme'] = "detect"
|
options['theme'] = "detect"
|
||||||
options['popupServices'] = ["youtube", "twitter", "tiktok", "imgur", "reddit", "quora", "translate", "maps"]
|
options['popupServices'] = ["youtube", "twitter", "tiktok", "imgur", "reddit", "quora", "translate", "maps"]
|
||||||
|
options['fetchInstances'] = 'github'
|
||||||
|
|
||||||
options = { ...options, ...defaultInstances }
|
options = { ...options, ...defaultInstances }
|
||||||
|
|
||||||
|
@ -631,45 +632,10 @@ function initDefaults() {
|
||||||
function upgradeOptions() {
|
function upgradeOptions() {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
const oldOptions = await utils.getOptions()
|
const oldOptions = await utils.getOptions()
|
||||||
const config = await utils.getConfig()
|
|
||||||
|
|
||||||
let options = {}
|
let options = {}
|
||||||
|
options = [...oldOptions]
|
||||||
options.exceptions = oldOptions.exceptions
|
options.fetchInstances = 'github'
|
||||||
options.theme = oldOptions.theme
|
|
||||||
options.popupServices = oldOptions.popupServices
|
|
||||||
|
|
||||||
for (const service in config.services) {
|
|
||||||
if (service in oldOptions) {
|
|
||||||
options[service] = oldOptions[service]
|
|
||||||
delete options[service].embedFrontend
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
options[service] = {}
|
|
||||||
for (const defaultOption in config.services[service].options) {
|
|
||||||
options[service][defaultOption] = config.services[service].options[defaultOption]
|
|
||||||
}
|
|
||||||
for (const frontend in config.services[service].frontends) {
|
|
||||||
if (config.services[service].frontends[frontend].instanceList) {
|
|
||||||
options[frontend] = []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const frontend in config.services[service].frontends) {
|
|
||||||
if (config.services[service].frontends[frontend].instanceList) {
|
|
||||||
if (frontend in oldOptions) {
|
|
||||||
options[frontend] = [
|
|
||||||
...oldOptions[frontend].clearnet.enabled,
|
|
||||||
...oldOptions[frontend].clearnet.custom
|
|
||||||
]
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
options[frontend] = defaultInstances[frontend]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
browser.storage.local.clear(() => {
|
browser.storage.local.clear(() => {
|
||||||
browser.storage.local.set({ options }, () => {
|
browser.storage.local.set({ options }, () => {
|
||||||
|
|
|
@ -32,30 +32,68 @@ function getOptions() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBlacklist() {
|
function getBlacklist(options) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
let url
|
||||||
|
if (options.fetchInstances == 'github') {
|
||||||
|
url = 'https://raw.githubusercontent.com/libredirect/instances/main/blacklist.json'
|
||||||
|
}
|
||||||
|
else if (options.fetchInstances == 'codeberg') {
|
||||||
|
url = 'https://codeberg.org/LibRedirect/instances/raw/branch/main/blacklist.json'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolve('disabled')
|
||||||
|
return
|
||||||
|
}
|
||||||
const http = new XMLHttpRequest()
|
const http = new XMLHttpRequest()
|
||||||
http.open("GET", "https://raw.githubusercontent.com/libredirect/instances/main/blacklist.json", true)
|
http.open("GET", url, true)
|
||||||
http.onreadystatechange = () => {
|
http.onreadystatechange = () => {
|
||||||
if (http.status === 200 && http.readyState == XMLHttpRequest.DONE) {
|
if (http.status === 200 && http.readyState == XMLHttpRequest.DONE) {
|
||||||
resolve(JSON.parse(http.responseText))
|
resolve(JSON.parse(http.responseText))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
http.onerror = () => {
|
||||||
|
resolve()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
http.ontimeout = () => {
|
||||||
|
resolve()
|
||||||
|
return
|
||||||
|
}
|
||||||
http.send(null)
|
http.send(null)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getList() {
|
function getList(options) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
let url
|
||||||
|
if (options.fetchInstances == 'github') {
|
||||||
|
url = 'https://raw.githubusercontent.com/libredirect/instances/main/data.json'
|
||||||
|
}
|
||||||
|
else if (options.fetchInstances == 'codeberg') {
|
||||||
|
url = 'https://codeberg.org/LibRedirect/instances/raw/branch/main/data.json'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolve('disabled')
|
||||||
|
return
|
||||||
|
}
|
||||||
const http = new XMLHttpRequest()
|
const http = new XMLHttpRequest()
|
||||||
http.open("GET", "https://raw.githubusercontent.com/libredirect/instances/main/data.json", true)
|
http.open("GET", url, true)
|
||||||
http.onreadystatechange = () => {
|
http.onreadystatechange = () => {
|
||||||
if (http.status === 200 && http.readyState == XMLHttpRequest.DONE) {
|
if (http.status === 200 && http.readyState == XMLHttpRequest.DONE) {
|
||||||
resolve(JSON.parse(http.responseText))
|
resolve(JSON.parse(http.responseText))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
http.onerror = () => {
|
||||||
|
resolve()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
http.ontimeout = () => {
|
||||||
|
resolve()
|
||||||
|
return
|
||||||
|
}
|
||||||
http.send(null)
|
http.send(null)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,16 @@
|
||||||
"instanceList": true,
|
"instanceList": true,
|
||||||
"url": "https://github.com/mmjee/Piped-Material"
|
"url": "https://github.com/mmjee/Piped-Material"
|
||||||
},
|
},
|
||||||
|
"poketube": {
|
||||||
|
"excludeTargets": [
|
||||||
|
2,
|
||||||
|
3
|
||||||
|
],
|
||||||
|
"name": "PokeTube",
|
||||||
|
"embeddable": true,
|
||||||
|
"instanceList": true,
|
||||||
|
"url": "https://codeberg.org/Ashley/poketube"
|
||||||
|
},
|
||||||
"cloudtube": {
|
"cloudtube": {
|
||||||
"name": "CloudTube",
|
"name": "CloudTube",
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
|
@ -71,16 +81,6 @@
|
||||||
"embeddable": false,
|
"embeddable": false,
|
||||||
"instanceList": false,
|
"instanceList": false,
|
||||||
"url": "https://github.com/yattee/yattee"
|
"url": "https://github.com/yattee/yattee"
|
||||||
},
|
|
||||||
"poketube": {
|
|
||||||
"excludeTargets": [
|
|
||||||
2,
|
|
||||||
3
|
|
||||||
],
|
|
||||||
"name": "PokeTube",
|
|
||||||
"embeddable": true,
|
|
||||||
"instanceList": true,
|
|
||||||
"url": "https://codeberg.org/Ashley/poketube/"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"targets": [
|
"targets": [
|
||||||
|
@ -611,4 +611,4 @@
|
||||||
"url": "https://www.snopes.com"
|
"url": "https://www.snopes.com"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ browser.runtime.onInstalled.addListener(async details => {
|
||||||
browser.runtime.openOptionsPage()
|
browser.runtime.openOptionsPage()
|
||||||
}
|
}
|
||||||
else if (details.reason == "update") {
|
else if (details.reason == "update") {
|
||||||
if (details.previousVersion == '2.3.4') {
|
if (details.previousVersion == '2.5.2') {
|
||||||
await servicesHelper.upgradeOptions()
|
await servicesHelper.upgradeOptions()
|
||||||
} else {
|
} else {
|
||||||
await servicesHelper.processUpdate()
|
await servicesHelper.processUpdate()
|
||||||
|
@ -115,7 +115,7 @@ browser.contextMenus.create({
|
||||||
})
|
})
|
||||||
|
|
||||||
browser.contextMenus.create({
|
browser.contextMenus.create({
|
||||||
id: "reverse",
|
id: "reverseTab",
|
||||||
title: 'Reverse redirect',
|
title: 'Reverse redirect',
|
||||||
contexts: ["browser_action"],
|
contexts: ["browser_action"],
|
||||||
})
|
})
|
||||||
|
@ -157,7 +157,7 @@ browser.contextMenus.onClicked.addListener(async (info, tab) => {
|
||||||
servicesHelper.copyRaw(url)
|
servicesHelper.copyRaw(url)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case 'reverse': {
|
case 'reverseTab': {
|
||||||
const url = new URL(info.pageUrl)
|
const url = new URL(info.pageUrl)
|
||||||
const newUrl = await servicesHelper.reverse(url)
|
const newUrl = await servicesHelper.reverse(url)
|
||||||
if (newUrl) {
|
if (newUrl) {
|
||||||
|
|
|
@ -99,11 +99,25 @@ async function loadPage(path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
!async function () {
|
!async function () {
|
||||||
const blacklist = await utils.getBlacklist()
|
const blacklist = await utils.getBlacklist(options)
|
||||||
const redirects = await utils.getList()
|
const redirects = await utils.getList(options)
|
||||||
|
|
||||||
for (const frontend in config.services[service].frontends) {
|
for (const frontend in config.services[service].frontends) {
|
||||||
if (config.services[service].frontends[frontend].instanceList) {
|
if (config.services[service].frontends[frontend].instanceList) {
|
||||||
createList(frontend, config.networks, document, redirects, blacklist)
|
if (redirects == 'disabled' || blacklist == 'disabled') {
|
||||||
|
document.getElementById(frontend).getElementsByClassName('clearnet')[0].style.display = 'none'
|
||||||
|
document.getElementById(frontend).getElementsByClassName('ping')[0].style.display = 'none'
|
||||||
|
}
|
||||||
|
else if (!redirects || !blacklist) {
|
||||||
|
document.getElementById(frontend)
|
||||||
|
.getElementsByClassName('clearnet')[0]
|
||||||
|
.getElementsByClassName("checklist")[0]
|
||||||
|
.getElementsByClassName('loading')[0]
|
||||||
|
.innerHTML = 'Could not fetch instances.'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
createList(frontend, config.networks, document, redirects, blacklist)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -240,8 +254,9 @@ async function ping(frontend) {
|
||||||
.getElementsByClassName('clearnet')[0]
|
.getElementsByClassName('clearnet')[0]
|
||||||
.getElementsByTagName('x')
|
.getElementsByTagName('x')
|
||||||
for (const element of instanceElements) {
|
for (const element of instanceElements) {
|
||||||
let span = element.getElementsByTagName('span')[0]
|
let span = element.getElementsByClassName('ping')[0]
|
||||||
if (!span) span = document.createElement('span')
|
if (!span) span = document.createElement('span')
|
||||||
|
span.classList = ['ping']
|
||||||
span.innerHTML = '<span style="color:lightblue">pinging...</span>'
|
span.innerHTML = '<span style="color:lightblue">pinging...</span>'
|
||||||
element.appendChild(span)
|
element.appendChild(span)
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,11 @@ resetSettings.addEventListener("click", async () => {
|
||||||
location.reload()
|
location.reload()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
document.getElementById('fetch-instances').addEventListener('change', event => {
|
||||||
|
setOption('fetchInstances', 'select', event)
|
||||||
|
location.reload()
|
||||||
|
})
|
||||||
|
|
||||||
let themeElement = document.getElementById("theme")
|
let themeElement = document.getElementById("theme")
|
||||||
themeElement.addEventListener("change", event => {
|
themeElement.addEventListener("change", event => {
|
||||||
setOption("theme", "select", event)
|
setOption("theme", "select", event)
|
||||||
|
|
|
@ -10,6 +10,13 @@ section(class="option-block" id="general_page")
|
||||||
option(value="light" data-localise="__MSG_light__") Light
|
option(value="light" data-localise="__MSG_light__") Light
|
||||||
option(value="dark" data-localise="__MSG_dark__") Dark
|
option(value="dark" data-localise="__MSG_dark__") Dark
|
||||||
|
|
||||||
|
div(class="some-block option-block")
|
||||||
|
h4 Fetch public instances
|
||||||
|
select(id="fetch-instances")
|
||||||
|
option(value="github") GitHub
|
||||||
|
option(value="codeberg") Codeberg
|
||||||
|
option(value="disable") Disable
|
||||||
|
|
||||||
div(class="some-block option-block")
|
div(class="some-block option-block")
|
||||||
h4(data-localise="__MSG_excludeFromRedirecting__") Excluded from redirecting
|
h4(data-localise="__MSG_excludeFromRedirecting__") Excluded from redirecting
|
||||||
|
|
||||||
|
|
|
@ -44,22 +44,22 @@ each val, service in services
|
||||||
|
|
||||||
form(class="custom-instance-form")
|
form(class="custom-instance-form")
|
||||||
div(class="some-block option-block")
|
div(class="some-block option-block")
|
||||||
input(class="custom-instance" type="url" )
|
input(class="custom-instance" type="url" placeholder="https://instance.com")
|
||||||
button(class="add add-instance" type="submit")
|
button(class="add add-instance" type="submit")
|
||||||
svg(xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor")
|
svg(xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor")
|
||||||
path(d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z")
|
path(d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z")
|
||||||
|
|
||||||
div(class="checklist custom-checklist")
|
div(class="checklist custom-checklist")
|
||||||
|
|
||||||
div(class="some-block")
|
div(class="ping some-block")
|
||||||
a(class="button button-inline" id=`ping-${frontend}`)
|
a(class="button button-inline" id=`ping-${frontend}`)
|
||||||
svg(xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor")
|
svg(xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor")
|
||||||
path(d="M10.45 15.5q.6.6 1.55.587.95-.012 1.4-.687L19 7l-8.4 5.6q-.675.45-.712 1.375-.038.925.562 1.525ZM12 4q1.475 0 2.838.412Q16.2 4.825 17.4 5.65l-1.9 1.2q-.825-.425-1.712-.637Q12.9 6 12 6 8.675 6 6.338 8.337 4 10.675 4 14q0 1.05.287 2.075Q4.575 17.1 5.1 18h13.8q.575-.95.838-1.975Q20 15 20 13.9q0-.9-.212-1.75-.213-.85-.638-1.65l1.2-1.9q.75 1.175 1.188 2.5.437 1.325.462 2.75.025 1.425-.325 2.725-.35 1.3-1.025 2.475-.275.45-.75.7-.475.25-1 .25H5.1q-.525 0-1-.25t-.75-.7q-.65-1.125-1-2.387Q2 15.4 2 14q0-2.075.788-3.888.787-1.812 2.15-3.175Q6.3 5.575 8.125 4.787 9.95 4 12 4Zm.175 7.825Z")
|
path(d="M10.45 15.5q.6.6 1.55.587.95-.012 1.4-.687L19 7l-8.4 5.6q-.675.45-.712 1.375-.038.925.562 1.525ZM12 4q1.475 0 2.838.412Q16.2 4.825 17.4 5.65l-1.9 1.2q-.825-.425-1.712-.637Q12.9 6 12 6 8.675 6 6.338 8.337 4 10.675 4 14q0 1.05.287 2.075Q4.575 17.1 5.1 18h13.8q.575-.95.838-1.975Q20 15 20 13.9q0-.9-.212-1.75-.213-.85-.638-1.65l1.2-1.9q.75 1.175 1.188 2.5.437 1.325.462 2.75.025 1.425-.325 2.725-.35 1.3-1.025 2.475-.275.45-.75.7-.475.25-1 .25H5.1q-.525 0-1-.25t-.75-.7q-.65-1.125-1-2.387Q2 15.4 2 14q0-2.075.788-3.888.787-1.812 2.15-3.175Q6.3 5.575 8.125 4.787 9.95 4 12 4Zm.175 7.825Z")
|
||||||
|
|
|
|
||||||
x() Ping instances
|
x() Ping instances
|
||||||
|
|
||||||
each val, network in networks
|
each val, network in networks
|
||||||
div(class=network)
|
div(class=network)
|
||||||
div(class="checklist")
|
div(class="checklist")
|
||||||
if (network == 'clearnet')
|
if (network == 'clearnet')
|
||||||
div(class="some-block option-block") Loading...
|
div(class="some-block option-block loading") Loading...
|
Loading…
Reference in New Issue