forked from raindropio/old-chrome-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
50 lines (41 loc) · 1.07 KB
/
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
47
48
49
50
//Tabs functions
var tabs = {
id: null,
setIcon: function(src) {
if (typeof src=='undefined') src='icon-19.png';
chrome.pageAction.setIcon({
tabId: this.id,
path:'images/'+src
});
}
}
//Check URL
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if ((tab.url.indexOf('://raindrop.io')<0)&&(tab.url.indexOf('http')==0)) {
chrome.pageAction.show(tabId);
tabs.id = tabId;
tabs.setIcon();
}
});
//On Click
chrome.pageAction.onClicked.addListener(function(tab) {
chrome.tabs.sendMessage(tab.id, {action: "showPopup", url:tab.url}, function(response) {});
});
//Messages from inject js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
switch(request.action){
case 'getScreenshot':
//sendResponse(tempScreen);
chrome.tabs.captureVisibleTab(null, {format:'jpeg', quality: 100}, function(dataURI) {
sendResponse(dataURI);
});
break;
case 'close':
if (request.param=='save')
tabs.setIcon('icon-19-ok.png');
else if (request.param=='delete')
tabs.setIcon();
break;
}
return true;
});