-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
46 lines (41 loc) · 1005 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
38
39
40
41
42
43
44
45
46
/* background.js
*
* Copyright (c) 2016 Seth T
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
chrome.runtime.onInstalled.addListener(function() {
chrome.contextMenus.create({
title: 'Snip it!',
id: 'p^3 context menu',
contexts: ['image']
});
});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
if(info.menuItemId == 'p^3 context menu') {
snip(info.srcUrl);
}
});
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript({
file: 'ClickGetImg.js'
});
});
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
snip(request.image);
});
function snip(imgUrl) {
chrome.notifications.create({
type: 'image',
title: 'Snipped!',
message: 'I like it.',
iconUrl: 'icons/icon128.png',
imageUrl: imgUrl,
buttons: [
{ title: 'Me too!' },
{ title: 'Oops, undo that' }
]
});
}