Allow tabs to be right-clicked and added to queue.

This commit is contained in:
Bauke 2020-11-14 14:12:49 +01:00
parent 6ce6b9ba28
commit fe9509cec0
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
2 changed files with 26 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import {browser} from 'webextension-polyfill-ts';
import {browser, Menus} from 'webextension-polyfill-ts';
import {
error,
getManifest,
@ -86,24 +86,42 @@ function contextCreated() {
}
}
browser.contextMenus.create(
const contextMenus: Menus.CreateCreatePropertiesType[] = [
{
id: 'queue-add-new-link',
title: 'Add to Queue',
contexts: ['link']
},
contextCreated
);
{
id: 'queue-add-new-link-tab',
title: 'Add to Queue',
contexts: ['tab']
}
];
for (const menu of contextMenus) {
browser.contextMenus.create(menu, contextCreated);
}
browser.contextMenus.onClicked.addListener(async (info, _tab) => {
if (info.menuItemId === 'queue-add-new-link') {
if (info.menuItemId.toString().includes('queue-add-new-link')) {
const settings = await getSettings();
let url: string;
if (info.menuItemId === 'queue-add-new-link') {
url = info.linkUrl!;
} else if (info.menuItemId === 'queue-add-new-link-tab') {
url = info.pageUrl!;
} else {
error(`Unknown menuItemId: ${info.menuItemId}`);
return;
}
settings.queue.push({
added: new Date(),
id: newQItemID(settings.queue),
text: info.linkText!,
url: info.linkUrl!
text: info.linkText ?? url,
url
});
await saveSettings(settings);

View File

@ -42,7 +42,7 @@ export function PageMain(props: MainProps): QComponent {
<p>Adding links to your queue:</p>
<ul>
<li>Right-click any link and click "Add to Queue".</li>
<li>Right-click any link or tab and click "Add to Queue".</li>
</ul>
<p>Opening the next link from your queue:</p>