Allow tabs to be right-clicked and added to queue.
This commit is contained in:
parent
6ce6b9ba28
commit
fe9509cec0
|
@ -1,4 +1,4 @@
|
||||||
import {browser} from 'webextension-polyfill-ts';
|
import {browser, Menus} from 'webextension-polyfill-ts';
|
||||||
import {
|
import {
|
||||||
error,
|
error,
|
||||||
getManifest,
|
getManifest,
|
||||||
|
@ -86,24 +86,42 @@ function contextCreated() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.contextMenus.create(
|
const contextMenus: Menus.CreateCreatePropertiesType[] = [
|
||||||
{
|
{
|
||||||
id: 'queue-add-new-link',
|
id: 'queue-add-new-link',
|
||||||
title: 'Add to Queue',
|
title: 'Add to Queue',
|
||||||
contexts: ['link']
|
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) => {
|
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();
|
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({
|
settings.queue.push({
|
||||||
added: new Date(),
|
added: new Date(),
|
||||||
id: newQItemID(settings.queue),
|
id: newQItemID(settings.queue),
|
||||||
text: info.linkText!,
|
text: info.linkText ?? url,
|
||||||
url: info.linkUrl!
|
url
|
||||||
});
|
});
|
||||||
|
|
||||||
await saveSettings(settings);
|
await saveSettings(settings);
|
||||||
|
|
|
@ -42,7 +42,7 @@ export function PageMain(props: MainProps): QComponent {
|
||||||
|
|
||||||
<p>Adding links to your queue:</p>
|
<p>Adding links to your queue:</p>
|
||||||
<ul>
|
<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>
|
</ul>
|
||||||
|
|
||||||
<p>Opening the next link from your queue:</p>
|
<p>Opening the next link from your queue:</p>
|
||||||
|
|
Loading…
Reference in New Issue