1
0
mirror of https://github.com/aureliendavid/rsspreview.git synced 2025-08-22 19:28:39 +00:00

Pass the opener tab ID to browser.tabs.create

This means that:
- the RSS preview tab opens in the same container in which the opener
  tab was open (without need for extra permissions);
- the RSS preview tab appears right next to the tab from which it was
  opened, not at the end of the tab bar; and
- if the user closes the tab without switching tabs between opening and
  closing the tab, Firefox activates the previous tab (i.e. from which
  the RSS preview was opened), not the next one.
This commit is contained in:
J. Tóth Tamás 2022-03-17 23:33:56 +01:00
parent 177aacd95c
commit 4c68719d6d
2 changed files with 4 additions and 1 deletions

View File

@ -65,6 +65,7 @@ function handleMessage(request, sender, sendResponse) {
browser.storage.sync.get({orangeIcon: false}).then(function(options){ browser.storage.sync.get({orangeIcon: false}).then(function(options){
let popup = new URL(browser.runtime.getURL('popup/popup.html')); 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)); popup.searchParams.set('feeds', JSON.stringify(request));
if (options.orangeIcon) { if (options.orangeIcon) {

View File

@ -19,6 +19,8 @@ document.addEventListener("DOMContentLoaded", function(event) {
const feedList = document.getElementById('feedList'); const feedList = document.getElementById('feedList');
const url = new URL(location.href); 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')); const feeds = JSON.parse(url.searchParams.get('feeds'));
for (feed_url in feeds) { for (feed_url in feeds) {
@ -50,7 +52,7 @@ document.addEventListener("DOMContentLoaded", function(event) {
let url = elem.getAttribute("data-href"); let url = elem.getAttribute("data-href");
if (url) { if (url) {
if (options.newTab) if (options.newTab)
browser.tabs.create({url: url}); browser.tabs.create({url: url, openerTabId: tabId});
else else
browser.tabs.update({url: url}).then(onUpdated, onError); browser.tabs.update({url: url}).then(onUpdated, onError);
} }