aboutsummaryrefslogtreecommitdiffstats
path: root/src/assets/javascripts
diff options
context:
space:
mode:
authorManeraKai <manerakai@protonmail.com>2023-01-07 12:33:38 +0300
committerManeraKai <manerakai@protonmail.com>2023-01-07 12:33:38 +0300
commit91528e21924e2258bfbfc0b255b31fd6316a261e (patch)
treefbc2c216f5005fdf900c2cea5aff9882bb67b759 /src/assets/javascripts
parentImproved UX/UI. Fixed https://github.com/libredirect/libredirect/issues/552 (diff)
downloadlibredirect-91528e21924e2258bfbfc0b255b31fd6316a261e.zip
Redirect all embeds in tab to same instance https://github.com/libredirect/libredirect/issues/461
Diffstat (limited to 'src/assets/javascripts')
-rw-r--r--src/assets/javascripts/services.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js
index 845c5f4e..988f6348 100644
--- a/src/assets/javascripts/services.js
+++ b/src/assets/javascripts/services.js
@@ -2,13 +2,14 @@ window.browser = window.browser || window.chrome
import utils from "./utils.js"
-let config, options, redirects, targets
+let config, options, targets
function init() {
return new Promise(async resolve => {
- browser.storage.local.get(["options", "redirects", "targets"], r => {
+ browser.storage.local.get(["options", "targets", "embedTabs"], r => {
options = r.options
targets = r.targets
+ embedTabs = r.embedTabs
fetch("/config.json")
.then(response => response.text())
.then(configData => {
@@ -55,7 +56,8 @@ function regexArray(service, url, config, frontend) {
return false
}
-function redirect(url, type, initiator, forceRedirection) {
+let embedTabs = {}
+function redirect(url, type, initiator, forceRedirection, tabId) {
if (type != "main_frame" && type != "sub_frame" && type != "image") return
let randomInstance
let frontend
@@ -76,7 +78,19 @@ function redirect(url, type, initiator, forceRedirection) {
instanceList.push(...options[frontend])
}
if (instanceList.length === 0) return
- randomInstance = utils.getRandomInstance(instanceList)
+
+ if ((type == "sub_frame" || type == "image") && embedTabs[tabId] && embedTabs[tabId][frontend] !== undefined) {
+ randomInstance = embedTabs[tabId][frontend]
+ } else {
+ randomInstance = utils.getRandomInstance(instanceList)
+ }
+
+ if ((type == "sub_frame" || type == "image") && embedTabs[tabId] === undefined) {
+ embedTabs[tabId] = {}
+ embedTabs[tabId][frontend] = randomInstance
+ browser.storage.local.set(embedTabs)
+ }
+
break
}
if (!frontend || !randomInstance) return
@@ -533,7 +547,7 @@ function initDefaults() {
}
}
browser.storage.local.set(
- { options, targets, localstorage },
+ { options, targets, localstorage, embedTabs: {} },
() => resolve()
)
})