ignored http from url exclusions https://github.com/libredirect/browser_extension/issues/665. Cleaned other things

This commit is contained in:
ManeraKai 2023-05-12 08:48:16 +03:00
parent 2196db43eb
commit 03d0b41a7f
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
5 changed files with 23 additions and 43 deletions

View File

@ -17,8 +17,8 @@ Requirements: [Node.js LTS](https://nodejs.org/)
git clone https://github.com/libredirect/browser_extension
cd browser_extension
npm install
npm run html
npm run start # Runs on firefox using web-ext
npm run html # Generates html files using Pug
npm run start # Runs in debug mode in firefox using Web-ext
```
### Run on Chromium manually
1. Open `chrome://extensions`

View File

@ -1,30 +0,0 @@
"use strict"
import utils from "./utils.js"
window.browser = window.browser || window.chrome
let exceptions
function isException(url) {
if (exceptions && url) {
if (exceptions.url) for (const item of exceptions.url) if (item == url.href) return true
if (exceptions.regex) for (const item of exceptions.regex) if (new RegExp(item).test(url.href)) return true
}
return false
}
function init() {
return new Promise(async resolve => {
const options = await utils.getOptions()
if (options) exceptions = options.exceptions
resolve()
})
}
init()
browser.storage.onChanged.addListener(init)
export default {
isException,
}

View File

@ -83,7 +83,6 @@ 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`
}
@ -819,6 +818,15 @@ async function copyRaw(url, test) {
}
}
function isException(url) {
let exceptions = options.exceptions
if (exceptions && url) {
if (exceptions.url) for (const item of exceptions.url) if (item == url.href) return true
if (exceptions.regex) for (const item of exceptions.regex) if (new RegExp(item).test(url.href)) return true
}
return false
}
export default {
redirect,
redirectAsync,
@ -828,5 +836,6 @@ export default {
upgradeOptions,
processUpdate,
copyRaw,
switchInstance
switchInstance,
isException
}

View File

@ -1,6 +1,5 @@
"use strict"
import generalHelper from "../../assets/javascripts/general.js"
import utils from "../../assets/javascripts/utils.js"
import servicesHelper from "../../assets/javascripts/services.js"
@ -44,9 +43,10 @@ browser.webRequest.onBeforeRequest.addListener(
if (tabIdRedirects[details.tabId] == false) return null
let newUrl = servicesHelper.redirect(url, details.type, initiator, tabIdRedirects[details.tabId], details.tabId)
if (details.frameAncestors && details.frameAncestors.length > 0 && generalHelper.isException(new URL(details.frameAncestors[0].url))) newUrl = null
if (details.frameAncestors && details.frameAncestors.length > 0 && servicesHelper.isException(new URL(details.frameAncestors[0].url))) newUrl = null
if (generalHelper.isException(url)) {
console.log(servicesHelper.isException(url))
if (servicesHelper.isException(url)) {
if (details.type == "main_frame")
newUrl = "BYPASSTAB"
else

View File

@ -152,14 +152,15 @@ function calcExceptionsCustomInstances() {
}
calcExceptionsCustomInstances()
document.getElementById("custom-exceptions-instance-form").addEventListener("submit", async event => {
console.log('something plz.... :\')')
event.preventDefault()
let val
if (instanceType == "url") {
if (nameCustomInstanceInput.validity.valid) {
val = nameCustomInstanceInput.value
if (!exceptionsCustomInstances.url.includes(val)) exceptionsCustomInstances.url.push(val)
}
if (instanceType == "url" && nameCustomInstanceInput.validity.valid) {
val = nameCustomInstanceInput.value
const url = new URL(val)
val = url.href
val = val.replace(/^http:\/\//, 'https://')
if (!exceptionsCustomInstances.url.includes(val)) exceptionsCustomInstances.url.push(val)
} else if (instanceType == "regex") {
val = nameCustomInstanceInput.value
if (val.trim() != "" && !exceptionsCustomInstances.regex.includes(val)) exceptionsCustomInstances.regex.push(val)