-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
34 lines (31 loc) · 1.05 KB
/
Copy pathbackground.js
File metadata and controls
34 lines (31 loc) · 1.05 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
chrome.runtime.onInstalled.addListener(async () => {
const defaults = {
enabled: true,
sourceLang: "auto",
targetLang: "en",
devFallback: false,
bubbleFontSize: "14px",
bubbleMaxWidth: "420px"
};
const cur = await chrome.storage.sync.get(Object.keys(defaults));
const patch = {};
for (const k of Object.keys(defaults)) if (typeof cur[k] === "undefined") patch[k] = defaults[k];
if (Object.keys(patch).length) await chrome.storage.sync.set(patch);
chrome.contextMenus.removeAll(() => {
chrome.contextMenus.create({
id: "translate-selection",
title: "Translate selection (Inline Translate)",
contexts: ["selection"]
});
});
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
if (info.menuItemId === "translate-selection" && tab?.id) {
chrome.tabs.sendMessage(tab.id, { type: "TRANSLATE_SELECTION" });
}
});
chrome.commands.onCommand.addListener((cmd, tab) => {
if (cmd === "retranslate-last-selection" && tab?.id) {
chrome.tabs.sendMessage(tab.id, { type: "RETRANSLATE_LAST" });
}
});