-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
29 lines (26 loc) · 954 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
/**
* Opens the configured Palette pal url in a new tab.
*
* @param info: OnClickData https://developer.chrome.com/docs/extensions/reference/contextMenus/#type-OnClickData
* @return {void}
*/
function openPalettePal(info) {
// Get the configured PalettePal url
chrome.storage.sync.get("url", ({ url }) => {
// Open a new Tab with the Palette Pal URL
chrome.tabs.create({url: url}, (tab) => {
// Set the image URL from the context into storage, which is used by the
// content script.
chrome.storage.sync.set({image: info.srcUrl});
});
});
}
/* Create a listener to bind to the onClick event in the context menu */
const listener = chrome.contextMenus.onClicked.addListener(openPalettePal)
/* Add a menu item to the context menu, but only trigger on images. */
chrome.contextMenus.create({
id: "palettel-pal-ext",
title: "Extract colors with Palette Pal",
contexts:["image"],
onclick: listener
});