feat: Add context menu options for summarizing, rephrasing, translating, and explaining text selections in background.ts
This commit is contained in:
parent
36fc8b6be1
commit
48a4af50ee
@ -194,6 +194,61 @@ export default defineBackground({
|
||||
browser.tabs.create({
|
||||
url: browser.runtime.getURL("/options.html")
|
||||
})
|
||||
} else if (info.menuItemId === "summarize-pa") {
|
||||
if (!isCopilotRunning) {
|
||||
browser.sidebarAction.toggle()
|
||||
}
|
||||
setTimeout(async () => {
|
||||
await browser.runtime.sendMessage({
|
||||
from: "background",
|
||||
type: "summary",
|
||||
text: info.selectionText
|
||||
})
|
||||
}, isCopilotRunning ? 0 : 5000)
|
||||
} else if (info.menuItemId === "rephrase-pa") {
|
||||
if (!isCopilotRunning) {
|
||||
browser.sidebarAction.toggle()
|
||||
}
|
||||
setTimeout(async () => {
|
||||
await browser.runtime.sendMessage({
|
||||
type: "rephrase",
|
||||
from: "background",
|
||||
text: info.selectionText
|
||||
})
|
||||
}, isCopilotRunning ? 0 : 5000)
|
||||
} else if (info.menuItemId === "translate-pg") {
|
||||
if (!isCopilotRunning) {
|
||||
browser.sidebarAction.toggle()
|
||||
}
|
||||
setTimeout(async () => {
|
||||
await browser.runtime.sendMessage({
|
||||
type: "translate",
|
||||
from: "background",
|
||||
text: info.selectionText
|
||||
})
|
||||
}, isCopilotRunning ? 0 : 5000)
|
||||
} else if (info.menuItemId === "explain-pa") {
|
||||
if (!isCopilotRunning) {
|
||||
browser.sidebarAction.toggle()
|
||||
}
|
||||
setTimeout(async () => {
|
||||
await browser.runtime.sendMessage({
|
||||
type: "explain",
|
||||
from: "background",
|
||||
text: info.selectionText
|
||||
})
|
||||
}, isCopilotRunning ? 0 : 5000)
|
||||
} else if (info.menuItemId === "custom-pg") {
|
||||
if (!isCopilotRunning) {
|
||||
browser.sidebarAction.toggle()
|
||||
}
|
||||
setTimeout(async () => {
|
||||
await browser.runtime.sendMessage({
|
||||
type: "custom",
|
||||
from: "background",
|
||||
text: info.selectionText
|
||||
})
|
||||
}, isCopilotRunning ? 0 : 5000)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -23,7 +23,7 @@ Ensure that your rephrased version conveys the same information and intent as th
|
||||
|
||||
Response:`
|
||||
|
||||
const DEFAULT_TRANSLATE_PROMPT = `Translate the following text from its original language into "english"0. Maintain the tone and style of the original text as much as possible:
|
||||
const DEFAULT_TRANSLATE_PROMPT = `Translate the following text from its original language into "english". Maintain the tone and style of the original text as much as possible:
|
||||
|
||||
Text:
|
||||
---------
|
||||
|
Loading…
x
Reference in New Issue
Block a user