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" ) return "BYPASSTAB"
randomInstance = utils.getRandomInstance(instanceList) 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 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) { async function copyRaw(url, test) {
const newUrl = await reverse(url) const newUrl = await reverse(url)
if (newUrl) { if (newUrl) {
@ -860,7 +827,6 @@ export default {
initDefaults, initDefaults,
upgradeOptions, upgradeOptions,
processUpdate, processUpdate,
modifyContentSecurityPolicy,
copyRaw, copyRaw,
switchInstance switchInstance
} }

View File

@ -135,7 +135,8 @@
"name": "Nitter", "name": "Nitter",
"embeddable": true, "embeddable": true,
"instanceList": true, "instanceList": true,
"url": "https://github.com/zedeus/nitter" "url": "https://github.com/zedeus/nitter",
"localhost": true
} }
}, },
"targets": [ "targets": [
@ -148,7 +149,8 @@
"options": { "options": {
"enabled": false, "enabled": false,
"redirectType": "main_frame", "redirectType": "main_frame",
"unsupportedUrls": "bypass" "unsupportedUrls": "bypass",
"instance": "public"
}, },
"imageType": "png", "imageType": "png",
"embeddable": true, "embeddable": true,
@ -179,7 +181,8 @@
"libreddit": { "libreddit": {
"name": "Libreddit", "name": "Libreddit",
"instanceList": true, "instanceList": true,
"url": "https://github.com/spikecodes/libreddit" "url": "https://github.com/spikecodes/libreddit",
"localhost": true
}, },
"teddit": { "teddit": {
"name": "Teddit", "name": "Teddit",
@ -195,7 +198,8 @@
"options": { "options": {
"enabled": false, "enabled": false,
"frontend": "libreddit", "frontend": "libreddit",
"unsupportedUrls": "bypass" "unsupportedUrls": "bypass",
"instance": "public"
}, },
"imageType": "png", "imageType": "png",
"embeddable": false, "embeddable": false,
@ -206,7 +210,8 @@
"rimgo": { "rimgo": {
"name": "rimgo", "name": "rimgo",
"instanceList": true, "instanceList": true,
"url": "https://codeberg.org/video-prize-ranch/rimgo" "url": "https://codeberg.org/video-prize-ranch/rimgo",
"localhost": true
} }
}, },
"targets": [ "targets": [
@ -216,7 +221,8 @@
"options": { "options": {
"enabled": false, "enabled": false,
"redirectType": "main_frame", "redirectType": "main_frame",
"unsupportedUrls": "bypass" "unsupportedUrls": "bypass",
"instance": "public"
}, },
"imageType": "png", "imageType": "png",
"embeddable": true, "embeddable": true,
@ -311,7 +317,8 @@
"breezeWiki": { "breezeWiki": {
"name": "BreezeWiki", "name": "BreezeWiki",
"instanceList": true, "instanceList": true,
"url": "https://breezewiki.com" "url": "https://breezewiki.com",
"localhost": true
} }
}, },
"targets": [ "targets": [
@ -320,7 +327,8 @@
"name": "Fandom", "name": "Fandom",
"options": { "options": {
"enabled": false, "enabled": false,
"unsupportedUrls": "bypass" "unsupportedUrls": "bypass",
"instance": "public"
}, },
"imageType": "svg", "imageType": "svg",
"embeddable": false, "embeddable": false,
@ -397,7 +405,8 @@
"simplyTranslate": { "simplyTranslate": {
"name": "SimplyTranslate", "name": "SimplyTranslate",
"instanceList": true, "instanceList": true,
"url": "https://git.sr.ht/~metalune/simplytranslate_web" "url": "https://git.sr.ht/~metalune/simplytranslate_web",
"localhost": true
}, },
"lingva": { "lingva": {
"name": "Lingva Translate", "name": "Lingva Translate",
@ -418,7 +427,8 @@
"options": { "options": {
"enabled": false, "enabled": false,
"frontend": "simplyTranslate", "frontend": "simplyTranslate",
"unsupportedUrls": "bypass" "unsupportedUrls": "bypass",
"instance": "public"
}, },
"imageType": "svgMono", "imageType": "svgMono",
"embeddable": false, "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) => { browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request == "reverseTab") { if (request == "reverseTab") {
browser.tabs.query({ active: true, currentWindow: true }, async tabs => { browser.tabs.query({ active: true, currentWindow: true }, async tabs => {

View File

@ -34,7 +34,15 @@ async function changeFrontendsSettings(service) {
const frontendDiv = document.getElementById(frontend) const frontendDiv = document.getElementById(frontend)
if (typeof divs[service].frontend !== "undefined") { if (typeof divs[service].frontend !== "undefined") {
if (frontend == divs[service].frontend.value) { 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 { } else {
frontendDiv.style.display = "none" frontendDiv.style.display = "none"
} }

View File

@ -26,6 +26,12 @@ each val, service in services
else else
option(value=frontend)=Object.values(services[service].frontends)[0].name 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 if services[service].embeddable
div(class="some-block option-block") div(class="some-block option-block")
h4(data-localise="__MSG_redirectType__") Redirect Type h4(data-localise="__MSG_redirectType__") Redirect Type