-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
37 lines (33 loc) · 1009 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
32
33
34
35
36
37
chrome.runtime.onInstalled.addListener(() => {
// Context menu for selected text
chrome.contextMenus.create({
id: "generateQRText",
title: "Share this text as QR code",
contexts: ["selection"]
});
// Context menu for links
chrome.contextMenus.create({
id: "generateQRLink",
title: "Share this link as QR code",
contexts: ["link"]
});
});
chrome.contextMenus.onClicked.addListener((info) => {
if (info.menuItemId === "generateQRText" && info.selectionText) {
const popupUrl = chrome.runtime.getURL(`popup.html?text=${encodeURIComponent(info.selectionText)}`);
chrome.windows.create({
url: popupUrl,
type: "popup",
width: 300,
height: 300
});
} else if (info.menuItemId === "generateQRLink" && info.linkUrl) {
const popupUrl = chrome.runtime.getURL(`popup.html?text=${encodeURIComponent(info.linkUrl)}`);
chrome.windows.create({
url: popupUrl,
type: "popup",
width: 300,
height: 300
});
}
});