Skip to content

Commit

Permalink
Allow to copy all tabs from subcommands #43
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Nov 7, 2023
1 parent 925c698 commit 12a9b2c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
7 changes: 4 additions & 3 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
"context_clipboard_html_link_label": { "message": "&HTML Link" },
"context_clipboard_markdown_label": { "message": "&Markdown" },
"context_clipboard_markdown_list_label": { "message": "M&arkdown (List)" },
"context_action_tab_label": { "message": "Individual Tab" },
"context_action_tree_label": { "message": "Whole Tree" },
"context_action_descendants_label": { "message": "Descendants" },
"context_action_tab_label": { "message": "&Individual Tab" },
"context_action_tree_label": { "message": "Whole &Tree" },
"context_action_descendants_label": { "message": "&Descendants" },
"context_action_all_label": { "message": "&All Tabs" },

"command_copySelectedTabs": { "message": "Copy Selected Tabs to Clipboard" },
"command_copySelectedTabs_title": { "message": "Which format to copy?" },
Expand Down
7 changes: 4 additions & 3 deletions _locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
"context_clipboard_html_link_label": { "message": "&HTMLのリンク" },
"context_clipboard_markdown_label": { "message": "&Markdown" },
"context_clipboard_markdown_list_label": { "message": "M&arkdown(リスト)" },
"context_action_tab_label": { "message": "単独のタブ" },
"context_action_tree_label": { "message": "ツリー全体" },
"context_action_descendants_label": { "message": "配下のタブ" },
"context_action_tab_label": { "message": "単独のタブ(&I)" },
"context_action_tree_label": { "message": "ツリー全体(&T)" },
"context_action_descendants_label": { "message": "配下のタブ(&D)" },
"context_action_all_label": { "message": "すべてのタブ(&A)" },

"command_copySelectedTabs": { "message": "選択中のタブをクリップボードにコピー" },
"command_copySelectedTabs_title": { "message": "どの形式でコピーしますか?" },
Expand Down
65 changes: 63 additions & 2 deletions background/context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ async function refreshFormatItemsSubcommands(hasChildren) {
contexts: ['tab'],
parentId: `${id}:clipboardOnTabTopLevel`,
});
createItem({
id: `${id}:clipboardOnTabTopLevel:separator`,
type: 'separator',
contexts: ['tab'],
parentId: `${id}:clipboardOnTabTopLevel`,
});
createItem({
id: `${id}:clipboardOnTabTopLevel:all`,
title: browser.i18n.getMessage('context_action_all_label'),
contexts: ['tab'],
parentId: `${id}:clipboardOnTabTopLevel`,
});

createItem({
id: `${id}:under_clipboardOnTab:tab`,
title: browser.i18n.getMessage('context_action_tab_label'),
Expand All @@ -217,6 +230,19 @@ async function refreshFormatItemsSubcommands(hasChildren) {
contexts: ['tab'],
parentId: `${id}:under_clipboardOnTab`,
});
createItem({
id: `${id}:under_clipboardOnTab:separator`,
type: 'separator',
contexts: ['tab'],
parentId: `${id}:under_clipboardOnTab`,
});
createItem({
id: `${id}:under_clipboardOnTab:all`,
title: browser.i18n.getMessage('context_action_all_label'),
contexts: ['tab'],
parentId: `${id}:under_clipboardOnTab`,
});

createItem({
id: `${id}:clipboardOnPageTopLevel:tab`,
title: browser.i18n.getMessage('context_action_tab_label'),
Expand All @@ -235,6 +261,19 @@ async function refreshFormatItemsSubcommands(hasChildren) {
contexts: ['page'],
parentId: `${id}:clipboardOnPageTopLevel`,
});
createItem({
id: `${id}:clipboardOnPageTopLevel:separator`,
type: 'separator',
contexts: ['tab'],
parentId: `${id}:clipboardOnPageTopLevel`,
});
createItem({
id: `${id}:clipboardOnPageTopLevel:all`,
title: browser.i18n.getMessage('context_action_all_label'),
contexts: ['page'],
parentId: `${id}:clipboardOnPageTopLevel`,
});

createItem({
id: `${id}:under_clipboardOnPage:tab`,
title: browser.i18n.getMessage('context_action_tab_label'),
Expand All @@ -253,20 +292,40 @@ async function refreshFormatItemsSubcommands(hasChildren) {
contexts: ['page'],
parentId: `${id}:under_clipboardOnPage`,
});
createItem({
id: `${id}:under_clipboardOnPage:separator`,
type: 'separator',
contexts: ['tab'],
parentId: `${id}:under_clipboardOnPage`,
});
createItem({
id: `${id}:under_clipboardOnPage:all`,
title: browser.i18n.getMessage('context_action_all_label'),
contexts: ['page'],
parentId: `${id}:under_clipboardOnPage`,
});
}
else {
removeItem(`${id}:clipboardOnTabTopLevel:tab`);
removeItem(`${id}:clipboardOnTabTopLevel:tree`);
removeItem(`${id}:clipboardOnTabTopLevel:descendants`);
removeItem(`${id}:clipboardOnTabTopLevel:separator`);
removeItem(`${id}:clipboardOnTabTopLevel:all`);
removeItem(`${id}:under_clipboardOnTab:tab`);
removeItem(`${id}:under_clipboardOnTab:tree`);
removeItem(`${id}:under_clipboardOnTab:descendants`);
removeItem(`${id}:clipboardOnTabTopLevel:separator`);
removeItem(`${id}:clipboardOnPageTopLevel:all`);
removeItem(`${id}:clipboardOnPageTopLevel:tab`);
removeItem(`${id}:clipboardOnPageTopLevel:tree`);
removeItem(`${id}:clipboardOnPageTopLevel:descendants`);
removeItem(`${id}:clipboardOnTabTopLevel:separator`);
removeItem(`${id}:clipboardOnPageTopLevel:all`);
removeItem(`${id}:under_clipboardOnPage:tab`);
removeItem(`${id}:under_clipboardOnPage:tree`);
removeItem(`${id}:under_clipboardOnPage:descendants`);
removeItem(`${id}:under_clipboardOnPage:separator`);
removeItem(`${id}:under_clipboardOnPage:all`);
}
}
await Promise.all(promises);
Expand Down Expand Up @@ -351,7 +410,7 @@ async function onClick(info, tab, selectedTabs = null) {
if (info.menuItemId.indexOf('clipboard:') != 0)
return;

const [, id, action] = info.menuItemId.match(/^(?:clipboard:)?(.+?)(?::under_clipboardOn(?:Tab|Page))?(?::(tab|tree|descendants))?$/);
const [, id, action] = info.menuItemId.match(/^(?:clipboard:)?(.+?)(?::under_clipboardOn(?:Tab|Page))?(?::(tab|tree|descendants|all))?$/);
log('command: ', { id, action });
let format;
if (Array.isArray(configs.copyToClipboardFormats)) {
Expand All @@ -369,7 +428,9 @@ async function onClick(info, tab, selectedTabs = null) {
Constants.kCOPY_TREE :
action == 'descendants' ?
Constants.kCOPY_TREE_DESCENDANTS :
Constants.kCOPY_INDIVIDUAL_TAB
action == 'all' ?
Constants.kCOPY_ALL :
Constants.kCOPY_INDIVIDUAL_TAB
) : undefined;
const withContainer = Constants.WITH_CONTAINER_MATCHER.test(format);
log('params: ', { withContainer, mode });
Expand Down

0 comments on commit 12a9b2c

Please sign in to comment.