Skip to content

Commit

Permalink
Feat/toolbar (#10)
Browse files Browse the repository at this point in the history
* Add toolbar button for focus on latest audible tab

Fix #5

For now, this is just a simple implementation of targeting the latest
audible tab, without any additional options.

This will allow users to have a big, easily reachable button for
accessing the addon's main function.

* Update README.md
  • Loading branch information
Rainyan authored Nov 2, 2023
1 parent 86404a4 commit a2b2ad4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ Firefox add-on. Quickly jump to a tab that is making noise. Convenient if you ha
* [Currently unsupported](https://github.com/Rainyan/jump-to-audible-tabs/issues/1), but if you are a developer you may be able to load it manually by following [the dev docs](https://developer.chrome.com/docs/extensions/), and substituting Chromium specific calls with Polyfill.

## Usage
### Toolbar icon
For Firefox, the main toolbar button is available from the *Extensions* button:

![jat_example](https://github.com/Rainyan/jump-to-audible-tabs/assets/6595066/306a4860-dbde-4561-83f7-97e9192da620)

From this list, you can pin it to your browser toolbar if you'd like. Pressing the button will focus on the latest audible tab.

### Context menu
For more control, the addon also offers a context menu with some additional options.

Right-click on any browser page or a tab (Firefox only), and choose the corresponding action from the "Jump to Audible Tabs" context menu:

![Example image of the context menu](https://user-images.githubusercontent.com/6595066/234595280-1a239852-5c34-4db2-a8c3-8a4152e7c33f.png)
Expand Down
39 changes: 39 additions & 0 deletions jump_to_audio_tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,45 @@ function errorLog() {
console.error(arguments);
}

browser.browserAction.onClicked.addListener((tab, info) => {
let targetTabs = AUDIBLE_TABS.sort((a, b) => b.lastAccessed - a.lastAccessed);
if (targetTabs.length === 0) {
return;
}
let targetTabId = targetTabs[0].id;
console.assert(targetTabId !== -1);

browser.tabs.update(targetTabId, { active: true }).then(() => {
browser.tabs
.get(targetTabId)
.catch((e) => {
console.error(e);
})
.then((tab) => {
browser.windows
.getAll()
.catch((e) => {
console.error(e);
})
.then((windows) => {
for (const [_, wnd] of Object.entries(windows)) {
if (wnd.id === tab.windowId) {
browser.windows
.update(wnd.id, {
drawAttention: true,
focused: true,
})
.catch((e) => {
console.error(e);
});
break;
}
}
});
});
});
});

browser.contextMenus.onClicked.addListener((info, tab) => {
if (!info.menuItemId.startsWith(EXT_TAB_ID)) {
return;
Expand Down
12 changes: 10 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version":2,
"name":"Jump to Audible Tabs",
"version":"0.1.2",
"version":"0.2.0",
"description":"Jump to tabs that are playing audio. Activate with the mouse right-click context menu.",
"icons":{
"48":"icons/Volume_Mute.svg",
Expand All @@ -18,5 +18,13 @@
"jump_to_audio_tab.js"
],
"persistent":true
},

"browser_action": {
"default_icon": {
"16": "icons/Volume_Mute.svg",
"32": "icons/Volume_Mute.svg",
"64": "icons/Volume_Mute.svg"
}
}
}
}

0 comments on commit a2b2ad4

Please sign in to comment.