Add a menu item to open the next link in a new tab.

This commit is contained in:
Bauke 2020-11-16 22:28:31 +01:00
parent 13cd59bbe0
commit b2d92796a9
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 32 additions and 3 deletions

View File

@ -102,17 +102,31 @@ const contextMenus: Menus.CreateCreatePropertiesType[] = [
id: 'queue-add-new-link-tab', id: 'queue-add-new-link-tab',
title: 'Add to Queue', title: 'Add to Queue',
contexts: ['tab'] contexts: ['tab']
},
{
id: 'queue-open-next-link-in-new-tab',
title: 'Open next link in new tab',
contexts: ['browser_action']
} }
]; ];
const contextMenuIDs: Set<string> = new Set(
contextMenus.map((value) => value.id!)
);
for (const menu of contextMenus) { for (const menu of contextMenus) {
browser.contextMenus.create(menu, contextCreated); browser.contextMenus.create(menu, contextCreated);
} }
browser.contextMenus.onClicked.addListener(async (info, _tab) => { browser.contextMenus.onClicked.addListener(async (info, _tab) => {
if (info.menuItemId.toString().includes('queue-add-new-link')) { const id = info.menuItemId.toString();
if (!contextMenuIDs.has(id)) {
return;
}
const settings = await getSettings(); const settings = await getSettings();
if (id.includes('queue-add-new-link')) {
let url: string; let url: string;
if (info.menuItemId === 'queue-add-new-link') { if (info.menuItemId === 'queue-add-new-link') {
url = info.linkUrl!; url = info.linkUrl!;
@ -132,5 +146,13 @@ browser.contextMenus.onClicked.addListener(async (info, _tab) => {
await saveSettings(settings); await saveSettings(settings);
await updateBadge(settings); await updateBadge(settings);
} else if (id === 'queue-open-next-link-in-new-tab') {
const nextItem = await getNextQItem(settings);
if (nextItem === undefined) {
await openOptionsPage();
} else {
await browser.tabs.create({active: true, url: nextItem.url});
await removeQItem(nextItem.id);
}
} }
}); });

View File

@ -47,7 +47,14 @@ export function PageMain(props: MainProps): QComponent {
<p>Opening the next link from your queue:</p> <p>Opening the next link from your queue:</p>
<ul> <ul>
<li>Click on the extension icon.</li> <li>
Click on the extension icon to open it in the current tab (when
possible).
</li>
<li>
Right-click the extension icon and click "Open next link in new
tab".
</li>
</ul> </ul>
<p>Opening the extension page:</p> <p>Opening the extension page:</p>