Skip to content

Commit

Permalink
Merge pull request #33 from shgysk8zer0/feature/30
Browse files Browse the repository at this point in the history
Add option to control opening of feeds
  • Loading branch information
Chris Zuber authored Sep 22, 2017
2 parents 3b7988e + 3e6ec30 commit 3b91bfa
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 23 deletions.
40 changes: 27 additions & 13 deletions background.js
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 8 additions & 4 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
<option value="icons/subscribe-orange-16.svg">Orange icon</option>
</select>
</fieldset>
<!--<fieldset>
<fieldset>
<legend>Popup Options</legend>
<label for="bold">Use bold text</label>
<input type="checkbox" name="bold" id="bold" />
</fieldset>-->
<label for="openFeed">Use bold text</label>
<select name="openFeed" id="openFeed" required="">
<option value="current">Current tab</option>
<option value="tab">New tab</option>
<option value="window">New window</option>
</select>
</fieldset>
<button type="submit">Save</button>
<button type="reset">Reset all to defaults</button>
<hr />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 20 additions & 4 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 3b91bfa

Please sign in to comment.