about summary refs log tree commit diff stats
path: root/src/pages/background
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/pages/background
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/pages/background')
-rw-r--r--src/pages/background/background.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/pages/background/background.js b/src/pages/background/background.js
index 77128612..1d1cbe46 100644
--- a/src/pages/background/background.js
+++ b/src/pages/background/background.js
@@ -38,6 +38,14 @@ browser.runtime.onInstalled.addListener(async details => {
 })
 
 let tabIdRedirects = {}
+
+browser.storage.onChanged.addListener(() => {
+	browser.storage.local.get(["embedTabs"], r => {
+		embedTabs = r.embedTabs
+	})
+})
+let embedTabs = {}
+
 // true == Always redirect, false == Never redirect, null/undefined == follow options for services
 browser.webRequest.onBeforeRequest.addListener(
 	details => {
@@ -51,7 +59,7 @@ browser.webRequest.onBeforeRequest.addListener(
 			return null
 		}
 		if (tabIdRedirects[details.tabId] == false) return null
-		let newUrl = servicesHelper.redirect(url, details.type, initiator, tabIdRedirects[details.tabId])
+		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
 
@@ -81,6 +89,11 @@ browser.tabs.onRemoved.addListener(tabId => {
 		delete tabIdRedirects[tabId]
 		console.log("Removed tab " + tabId + " from tabIdRedirects")
 	}
+	if (embedTabs[tab] != undefined) {
+		delete embedTabs[tabId]
+		browser.storage.local.set(embedTabs)
+		console.log("Removed tab " + tabId + " from embedTabs")
+	}
 })
 
 browser.commands.onCommand.addListener(command => {
@@ -185,4 +198,4 @@ browser.webRequest.onHeadersReceived.addListener(
 	},
 	{ urls: ["<all_urls>"] },
 	["blocking", "responseHeaders"]
-)
\ No newline at end of file
+)