From 03d0b41a7fff3ee339944570d982db62312b9447 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Fri, 12 May 2023 08:48:16 +0300 Subject: [PATCH] ignored http from url exclusions https://github.com/libredirect/browser_extension/issues/665. Cleaned other things --- README.md | 4 ++-- src/assets/javascripts/general.js | 30 ---------------------------- src/assets/javascripts/services.js | 13 ++++++++++-- src/pages/background/background.js | 6 +++--- src/pages/options/widgets/general.js | 13 ++++++------ 5 files changed, 23 insertions(+), 43 deletions(-) delete mode 100644 src/assets/javascripts/general.js diff --git a/README.md b/README.md index e597053..f22e037 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/assets/javascripts/general.js b/src/assets/javascripts/general.js deleted file mode 100644 index 588c67d..0000000 --- a/src/assets/javascripts/general.js +++ /dev/null @@ -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, -} diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 12a08d3..37847a5 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -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 } diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 02b705c..8071305 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -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 diff --git a/src/pages/options/widgets/general.js b/src/pages/options/widgets/general.js index 484edc0..3dd52af 100644 --- a/src/pages/options/widgets/general.js +++ b/src/pages/options/widgets/general.js @@ -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)