diff --git a/background.js b/background.js index 0a0502d..cf5ff1f 100644 --- a/background.js +++ b/background.js @@ -1,23 +1,37 @@ const TABS = {}; -function clickHandler(tab) { - browser.tabs.create({ - url: TABS[tab.id][0].href - }); +async function clickHandler(tab) { + const opts = await browser.storage.local.get('openFeed'); + if (opts.hasOwnProperty('openFeed')) { + switch (opts.openFeed) { + case 'window': + browser.windows.create({url: TABS[tab.id][0].href}); + break; + case 'tab': + browser.tabs.create({url: TABS[tab.id][0].href}); + break; + case 'current': + browser.tabs.update(null, {url: TABS[tab.id][0].href}); + break; + default: + throw new Error(`Unsupported open feed method: ${opts.openFeed}`); + } + } else { + browser.tabs.update(null, {url: TABS[tab.id][0].href}); + } } function removeHandler(tabId) { delete TABS[tabId]; } -function updatePageAction(tab, links) { +async function updatePageAction(tab, links) { if (links.length > 0) { TABS[tab.id] = links; - browser.storage.local.get('icon').then(icon => { - browser.pageAction.setIcon({ - tabId: tab.id, - path: icon.icon || 'icons/subscribe-16.svg' - }); + const opts = await browser.storage.local.get('icon'); + browser.pageAction.setIcon({ + tabId: tab.id, + path: opts.icon || 'icons/subscribe-16.svg' }); browser.pageAction.show(tab.id); } @@ -50,10 +64,10 @@ function scanPage(tab) { } } -function refreshAllTabsPageAction() { - browser.tabs.query({}).then(tabs => tabs.forEach(scanPage)).catch(console.error); +async function refreshAllTabsPageAction() { + const tabs = await browser.tabs.query({}); + tabs.forEach(scanPage); } - browser.runtime.onMessage.addListener(messageHandler); browser.tabs.onRemoved.addListener(removeHandler); browser.tabs.onUpdated.addListener(scanPage); diff --git a/manifest.json b/manifest.json index 1c22d37..c8b518c 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "name": "Chris Zuber", "url": "https://chriszuber.com" }, - "version": "0.4.0", + "version": "0.4.1", "description": "__MSG_extensionDescription__", "homepage_url": "https://github.com/shgysk8zer0/awesome-rss", "icons": { diff --git a/options.html b/options.html index 5656328..053b1c4 100644 --- a/options.html +++ b/options.html @@ -17,11 +17,15 @@ - + + +
diff --git a/package.json b/package.json index adc5273..400e14e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "awesome-rss", - "version": "0.4.0", + "version": "0.4.1", "description": "Puts an RSS/Atom subscribe button back in URL bar", "keywords": [ "WebExtension", diff --git a/popup.js b/popup.js index 8ae2352..12b6ad5 100644 --- a/popup.js +++ b/popup.js @@ -20,11 +20,27 @@ function init() { } } -function openFeed(click) { +async function openFeed(click) { click.preventDefault(); - browser.tabs.create({ - url: this.href, - }); + const opts = await browser.storage.local.get('openFeed'); + if (opts.hasOwnProperty('openFeed')) { + switch (opts.openFeed) { + case 'window': + browser.windows.create({url: this.href}); + break; + case 'tab': + browser.tabs.create({url: this.href}); + break; + case 'current': + browser.tabs.update(null, {url: this.href}); + break; + default: + throw new Error(`Unsupported open feed method: ${opts.openFeed}`); + } + } else { + browser.tabs.update(null, {url: this.href}); + } + } if (['interactive', 'complete'].includes(document.readyState)) {