diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 84a7ee6..723e39d 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -433,5 +433,11 @@ }, "confirmation": { "message": "Are you sure you want to delete this item?" + }, + "sendLeftTabs": { + "message": "Send All tabs on the left" + }, + "sendRightTabs": { + "message": "Send All tabs on the right" } } diff --git a/_locales/zh_CN/messages.json b/_locales/zh_CN/messages.json index 8027cf2..589262f 100644 --- a/_locales/zh_CN/messages.json +++ b/_locales/zh_CN/messages.json @@ -30,7 +30,7 @@ "message": "查看配置" }, "restoreKey": { - "message": "点击“打开整组”或点击单个标签时:" + "message": "点击 “打开整组” 或点击 单个标签 时:" }, "restoreValueDelete": { "message": "打开标签并将其从标签列表中删除" @@ -39,7 +39,7 @@ "message": "打开标签但不将其从标签列表中删除" }, "openBackgroundAfterSendTab": { - "message": "点击“发送当前标签”或“发送所有标签”或“发送其他标签”后:" + "message": "点击 “发送当前标签” 或 “发送所有标签” 或 “发送其他标签” 后:" }, "openBackgroundAfterSendTabYes": { "message": "打开后台页" @@ -433,5 +433,11 @@ }, "confirmation": { "message": "您确定要删除吗?" + }, + "sendLeftTabs": { + "message": "发送左侧所有标签" + }, + "sendRightTabs": { + "message": "发送右侧所有标签" } } diff --git a/js/background.js b/js/background.js index d35fccd..30b40cf 100644 --- a/js/background.js +++ b/js/background.js @@ -831,29 +831,34 @@ chrome.storage.onChanged.addListener(function (changes, areaName) { // Add a listener to create the initial context menu items, // context menu items only need to be created at runtime.onInstalled chrome.runtime.onInstalled.addListener(async () => { - // 任何网页创建右键菜单,发送当前tab + // 发送当前标签 chrome.contextMenus.create({ - id: "rightClickSendCurrentTab", title: `${chrome.i18n.getMessage("sendCurrentTab")}` + id: "sendCurrentTab", title: `${chrome.i18n.getMessage("sendCurrentTab")}`, contexts: ["all"] }); // 打开后台管理页 chrome.contextMenus.create({ - id: "showAllTabs", title: `${chrome.i18n.getMessage("showAllTabs")}`, contexts: ["action"] + id: "showAllTabs", title: `${chrome.i18n.getMessage("showAllTabs")}`, contexts: ["all"] }); // 发送所有标签 chrome.contextMenus.create({ - id: "sendAllTabs", title: `${chrome.i18n.getMessage("sendAllTabs")}`, contexts: ["action"] + id: "sendAllTabs", title: `${chrome.i18n.getMessage("sendAllTabs")}`, contexts: ["all"] }); - // 发送当前标签 + // 发送其他标签 chrome.contextMenus.create({ - id: "sendCurrentTab", title: `${chrome.i18n.getMessage("sendCurrentTab")}`, contexts: ["action"] + id: "sendOtherTabs", title: `${chrome.i18n.getMessage("sendOtherTabs")}`, contexts: ["all"] }); - // 发送其他标签 + // 发送左侧标签页 chrome.contextMenus.create({ - id: "sendOtherTabs", title: `${chrome.i18n.getMessage("sendOtherTabs")}`, contexts: ["action"] + id: "sendLeftTabs", title: `${chrome.i18n.getMessage("sendLeftTabs")}`, contexts: ["all"] + }); + + // 发送右侧标签页 + chrome.contextMenus.create({ + id: "sendRightTabs", title: `${chrome.i18n.getMessage("sendRightTabs")}`, contexts: ["all"] }); }); @@ -862,7 +867,7 @@ chrome.runtime.onInstalled.addListener(async () => { chrome.contextMenus.onClicked.addListener(function (info, tab) { console.log(info, tab); switch (info.menuItemId) { - case "rightClickSendCurrentTab": + case "sendCurrentTab": chrome.storage.local.get(function (storage) { chrome.tabs.query({ url: ["https://*/*", "http://*/*", "chrome://*/*", "file://*/*"], @@ -911,7 +916,69 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) { } }); break; - case 'sendCurrentTab': + case 'sendLeftTabs': + chrome.storage.local.get(function (storage) { + let opts = storage.options + let openBackgroundAfterSendTab = "yes" + if (opts) { + openBackgroundAfterSendTab = opts.openBackgroundAfterSendTab || "yes" + } + chrome.tabs.query({ + url: ["https://*/*", "http://*/*", "chrome://*/*", "file://*/*"], currentWindow: true + }, function (tabs) { + let req = [] + for (let i = 0; i < tabs.length; i++) { + if (tabs[i].active) { + break; + } + req.push(tabs[i]); + } + if (req.length > 0) { + saveTabs(req); + if (openBackgroundAfterSendTab === "yes") { + openBackgroundPage(); + } + closeTabs(req); + } else { + if (openBackgroundAfterSendTab === "yes") { + openBackgroundPage(); + } + } + }); + }); + break; + case 'sendRightTabs': + chrome.storage.local.get(function (storage) { + let opts = storage.options + let openBackgroundAfterSendTab = "yes" + if (opts) { + openBackgroundAfterSendTab = opts.openBackgroundAfterSendTab || "yes" + } + chrome.tabs.query({ + url: ["https://*/*", "http://*/*", "chrome://*/*", "file://*/*"], currentWindow: true + }, function (tabs) { + let req = [] + for (let i = tabs.length - 1; i >= 0; i--) { + if (tabs[i].active) { + break; + } + req.push(tabs[i]); + } + if (req.length > 0) { + saveTabs(req); + if (openBackgroundAfterSendTab === "yes") { + openBackgroundPage(); + } + closeTabs(req); + } else { + if (openBackgroundAfterSendTab === "yes") { + openBackgroundPage(); + } + } + }); + }); + break; + case 'sendOtherTabs': chrome.storage.local.get(function (storage) { let opts = storage.options let openBackgroundAfterSendTab = "yes" @@ -920,10 +987,9 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) { } chrome.tabs.query({ url: ["https://*/*", "http://*/*", "chrome://*/*", "file://*/*"], - highlighted: true, + highlighted: false, currentWindow: true }, function (tabs) { - console.log(tabs) var req = tabs.filter(function (tab) { return !tab.pinned; }); @@ -941,24 +1007,6 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) { }); }); break; - case 'sendOtherTabs': - chrome.tabs.query({ - url: ["https://*/*", "http://*/*", "chrome://*/*", "file://*/*"], - highlighted: false, - currentWindow: true - }, function (tabs) { - var req = tabs.filter(function (tab) { - return !tab.pinned; - }); - if (req.length > 0) { - saveTabs(req); - openBackgroundPage(); - closeTabs(req); - } else { - openBackgroundPage(); - } - }); - break; default: break; }