-
Notifications
You must be signed in to change notification settings - Fork 4
/
background.js
31 lines (28 loc) · 1020 Bytes
/
background.js
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
/* global browser */
async function onBrowserActionClicked(tab) {
await browser.tabs.executeScript(tab.id, { file: "content-script.js" });
browser.tabs.sendMessage(tab.id, { action: "highlight" });
}
["Export HTML", "Export TEXT", "Copy HTML", "Copy TEXT"].forEach((val) => {
browser.menus.create({
title: val,
documentUrlPatterns: ["<all_urls>"],
contexts: ["page", "link", "image", "editable"],
onclick: async (info, tab) => {
if (val.startsWith("Copy")) {
const requiredPermission = { permissions: ["clipboardWrite"] };
if (!(await browser.permissions.request(requiredPermission))) {
return;
}
}
await browser.tabs.executeScript(tab.id, { file: "content-script.js" });
await browser.tabs.sendMessage(tab.id, {
action: "export",
targetElementId: info.targetElementId,
mode: val.toLowerCase(),
});
},
});
});
// Register Listeners
browser.browserAction.onClicked.addListener(onBrowserActionClicked);