diff --git a/background.js b/background.js index 4d9e68a..4233adf 100644 --- a/background.js +++ b/background.js @@ -65,6 +65,7 @@ function handleMessage(request, sender, sendResponse) { browser.storage.sync.get({orangeIcon: false}).then(function(options){ let popup = new URL(browser.runtime.getURL('popup/popup.html')); + popup.searchParams.set('tabId', sender.tab.id.toString()); popup.searchParams.set('feeds', JSON.stringify(request)); if (options.orangeIcon) { diff --git a/popup/popup.js b/popup/popup.js index 879e7f9..4207a08 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -19,6 +19,8 @@ document.addEventListener("DOMContentLoaded", function(event) { const feedList = document.getElementById('feedList'); const url = new URL(location.href); + // `+` converts the string to an number + const tabId = +url.searchParams.get('tabId'); const feeds = JSON.parse(url.searchParams.get('feeds')); for (feed_url in feeds) { @@ -50,7 +52,7 @@ document.addEventListener("DOMContentLoaded", function(event) { let url = elem.getAttribute("data-href"); if (url) { if (options.newTab) - browser.tabs.create({url: url}); + browser.tabs.create({url: url, openerTabId: tabId}); else browser.tabs.update({url: url}).then(onUpdated, onError); }