Skip to content

Commit

Permalink
Merge pull request #15 from Rainyan/feat/polyfill
Browse files Browse the repository at this point in the history
Add browser API Polyfill
  • Loading branch information
Rainyan authored Nov 22, 2023
2 parents aeae92c + 077cf76 commit e743851
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
72 changes: 40 additions & 32 deletions jump_to_audio_tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,51 +240,59 @@ browser.contextMenus.onClicked.addListener((info, tab) => {
}, errorLog);
});

function populateMenu() {
browser.contextMenus.removeAll().then(() => {
if (AUDIBLE_TABS.length === 0 && MUTED_TABS.length === 0) {
return;
}
browser.contextMenus.create({
id: `${EXT_TAB_ID}latest`,
title: "Jump to latest audible tab",
contexts: CONTEXTS,
});
function onRemoveAllContextMenus() {
if (AUDIBLE_TABS.length === 0 && MUTED_TABS.length === 0) {
return;
}
browser.contextMenus.create({
id: `${EXT_TAB_ID}latest`,
title: "Jump to latest audible tab",
contexts: CONTEXTS,
});
browser.contextMenus.create({
id: `${EXT_TAB_ID}muteall`,
title: "Mute all audible tabs",
contexts: CONTEXTS,
});
browser.contextMenus.create({
id: `${EXT_TAB_ID}separator-1`,
type: "separator",
contexts: CONTEXTS,
});

for (const tab of AUDIBLE_TABS) {
browser.contextMenus.create({
id: `${EXT_TAB_ID}muteall`,
title: "Mute all audible tabs",
id: `${EXT_TAB_ID}${tab.id}`,
title: `${tab.title} (${tab.url})`,
contexts: CONTEXTS,
});
}

if (MUTED_TABS.length > 0) {
browser.contextMenus.create({
id: `${EXT_TAB_ID}separator-1`,
type: "separator",
id: `${EXT_TAB_ID}mutedtabs`,
title: "Muted tabs",
contexts: CONTEXTS,
});

for (const tab of AUDIBLE_TABS) {
for (const tab of MUTED_TABS) {
browser.contextMenus.create({
id: `${EXT_TAB_ID}${tab.id}`,
title: `${tab.title} (${tab.url})`,
contexts: CONTEXTS,
parentId: `${EXT_TAB_ID}mutedtabs`,
});
}
}
}

if (MUTED_TABS.length > 0) {
browser.contextMenus.create({
id: `${EXT_TAB_ID}mutedtabs`,
title: "Muted tabs",
contexts: CONTEXTS,
});
for (const tab of MUTED_TABS) {
browser.contextMenus.create({
id: `${EXT_TAB_ID}${tab.id}`,
title: `${tab.title} (${tab.url})`,
contexts: CONTEXTS,
parentId: `${EXT_TAB_ID}mutedtabs`,
});
}
}
});
function populateMenu() {
// Compatibility shim for Chromium, because Firefox/Polyfill behaviour
// differs here.
try {
chrome.contextMenus.removeAll(onRemoveAllContextMenus);
} catch (error) {
browser.contextMenus.removeAll(onRemoveAllContextMenus);
}
}

// As of writing this (2022/12), only Firefox supports the "tab" context,
Expand Down
5 changes: 3 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.4.0",
"version":"0.5.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 @@ -15,6 +15,7 @@
],
"background":{
"scripts":[
"thirdparty/polyfill/browser-polyfill.min.js",
"jump_to_audio_tab.js"
],
"persistent":true
Expand All @@ -34,7 +35,7 @@
},
"description": "Jump to a recently audible tab, from newest to oldest"
},
"jump-to-latest-audible-tab-next": {
"jump-to-latest-audible-tab-next": {
"suggested_key": {
"default": "Shift+Alt+J"
},
Expand Down
8 changes: 8 additions & 0 deletions thirdparty/polyfill/browser-polyfill.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e743851

Please sign in to comment.