-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
41 lines (35 loc) · 1.01 KB
/
background.js
File metadata and controls
41 lines (35 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const CONTEXT_MENU_ID = "openpm-generate-prd";
const MAX_INPUT_CHARS = 10000;
chrome.runtime.onInstalled.addListener(async () => {
await chrome.contextMenus.removeAll();
chrome.contextMenus.create({
id: CONTEXT_MENU_ID,
title: "Generate PRD with OpenPM",
contexts: ["selection"]
});
try {
await chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true });
} catch {
// Some Chrome builds may not support panel behavior in all contexts.
}
});
chrome.contextMenus.onClicked.addListener(async (info, tab) => {
if (info.menuItemId !== CONTEXT_MENU_ID) {
return;
}
const selectedText = (info.selectionText || "").trim().slice(0, MAX_INPUT_CHARS);
if (!selectedText) {
return;
}
await chrome.storage.local.set({
pendingUserPrompt: selectedText,
pendingPromptSource: "selection"
});
if (tab?.id) {
try {
await chrome.sidePanel.open({ tabId: tab.id });
} catch {
// If opening fails, user can click extension action manually.
}
}
});