Added option for localhost frontends

This commit is contained in:
ManeraKai 2023-04-19 21:35:21 +03:00
parent 1a0fbed9f0
commit d7848d6730
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
5 changed files with 40 additions and 57 deletions

View File

@ -83,6 +83,10 @@ function redirect(url, type, initiator, forceRedirection) {
) return "BYPASSTAB"
randomInstance = utils.getRandomInstance(instanceList)
console.log(options[service].localhost)
if (config.services[service].frontends[frontend].localhost && options[service].instance == "localhost") {
randomInstance = `http://${frontend}.localhost:8080`
}
break
}
@ -795,43 +799,6 @@ function processUpdate() {
})
}
// For websites that have a strict policy that would not normally allow these frontends to be embedded within the website.
function modifyContentSecurityPolicy(details) {
let isChanged = false
if (details.type != "main_frame") return
for (const header in details.responseHeaders) {
if (details.responseHeaders[header].name == "content-security-policy") {
let instancesList = []
for (const service in config.services) {
if (config.services[service].embeddable) {
for (const frontend in config.services[service].frontends) {
if (config.services[service].frontends[frontend].embeddable) {
for (const network in config.networks) {
instancesList.push(...options[frontend])
}
}
}
}
}
let securityPolicyList = details.responseHeaders[header].value.split(";")
for (const i in securityPolicyList) securityPolicyList[i] = securityPolicyList[i].trim()
let newSecurity = ""
for (const item of securityPolicyList) {
if (item.trim() == "") continue
let regex = item.match(/([a-z-]{0,}) (.*)/)
if (regex == null) continue
let [, key, vals] = regex
if (key == "frame-src") vals = vals + " " + instancesList.join(" ")
newSecurity += key + " " + vals + "; "
}
details.responseHeaders[header].value = newSecurity
isChanged = true
}
}
if (isChanged) return { details }
}
async function copyRaw(url, test) {
const newUrl = await reverse(url)
if (newUrl) {
@ -860,7 +827,6 @@ export default {
initDefaults,
upgradeOptions,
processUpdate,
modifyContentSecurityPolicy,
copyRaw,
switchInstance
}

View File

@ -135,7 +135,8 @@
"name": "Nitter",
"embeddable": true,
"instanceList": true,
"url": "https://github.com/zedeus/nitter"
"url": "https://github.com/zedeus/nitter",
"localhost": true
}
},
"targets": [
@ -148,7 +149,8 @@
"options": {
"enabled": false,
"redirectType": "main_frame",
"unsupportedUrls": "bypass"
"unsupportedUrls": "bypass",
"instance": "public"
},
"imageType": "png",
"embeddable": true,
@ -179,7 +181,8 @@
"libreddit": {
"name": "Libreddit",
"instanceList": true,
"url": "https://github.com/spikecodes/libreddit"
"url": "https://github.com/spikecodes/libreddit",
"localhost": true
},
"teddit": {
"name": "Teddit",
@ -195,7 +198,8 @@
"options": {
"enabled": false,
"frontend": "libreddit",
"unsupportedUrls": "bypass"
"unsupportedUrls": "bypass",
"instance": "public"
},
"imageType": "png",
"embeddable": false,
@ -206,7 +210,8 @@
"rimgo": {
"name": "rimgo",
"instanceList": true,
"url": "https://codeberg.org/video-prize-ranch/rimgo"
"url": "https://codeberg.org/video-prize-ranch/rimgo",
"localhost": true
}
},
"targets": [
@ -216,7 +221,8 @@
"options": {
"enabled": false,
"redirectType": "main_frame",
"unsupportedUrls": "bypass"
"unsupportedUrls": "bypass",
"instance": "public"
},
"imageType": "png",
"embeddable": true,
@ -311,7 +317,8 @@
"breezeWiki": {
"name": "BreezeWiki",
"instanceList": true,
"url": "https://breezewiki.com"
"url": "https://breezewiki.com",
"localhost": true
}
},
"targets": [
@ -320,7 +327,8 @@
"name": "Fandom",
"options": {
"enabled": false,
"unsupportedUrls": "bypass"
"unsupportedUrls": "bypass",
"instance": "public"
},
"imageType": "svg",
"embeddable": false,
@ -397,7 +405,8 @@
"simplyTranslate": {
"name": "SimplyTranslate",
"instanceList": true,
"url": "https://git.sr.ht/~metalune/simplytranslate_web"
"url": "https://git.sr.ht/~metalune/simplytranslate_web",
"localhost": true
},
"lingva": {
"name": "Lingva Translate",
@ -418,7 +427,8 @@
"options": {
"enabled": false,
"frontend": "simplyTranslate",
"unsupportedUrls": "bypass"
"unsupportedUrls": "bypass",
"instance": "public"
},
"imageType": "svgMono",
"embeddable": false,

View File

@ -214,13 +214,6 @@ browser.contextMenus.onClicked.addListener(async (info) => {
}
})
browser.webRequest.onHeadersReceived.addListener(
servicesHelper.modifyContentSecurityPolicy,
{ urls: ["<all_urls>"] },
["blocking", "responseHeaders"]
)
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request == "reverseTab") {
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {

View File

@ -34,7 +34,15 @@ async function changeFrontendsSettings(service) {
const frontendDiv = document.getElementById(frontend)
if (typeof divs[service].frontend !== "undefined") {
if (frontend == divs[service].frontend.value) {
frontendDiv.style.display = "block"
frontendDiv.style.display = ""
if (config.services[service].frontends[frontend].localhost == true) {
document.getElementById(`${service}-instance-div`).style.display = ""
if (options[service].instance == "localhost") {
frontendDiv.style.display = "none"
}
} else {
document.getElementById(`${service}-instance-div`).style.display = "none"
}
} else {
frontendDiv.style.display = "none"
}

View File

@ -26,6 +26,12 @@ each val, service in services
else
option(value=frontend)=Object.values(services[service].frontends)[0].name
div(class="some-block option-block" id=service+"-instance-div")
h4() Instance
select(id=service+"-instance")
option(value="localhost") localhost
option(value="public") public instances
if services[service].embeddable
div(class="some-block option-block")
h4(data-localise="__MSG_redirectType__") Redirect Type