-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbackground.js
40 lines (34 loc) · 1.42 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
var id = 100;
var url = '';
chrome.runtime.onMessage.addListener(openPivotate);
function openPivotate(request, sender, sendResponse) {
chrome.tabs.captureVisibleTab(function(screenshotUrl) {
var currentId = id++;
var viewTabUrl = chrome.extension.getURL('pivotate.html?id=' + (currentId));
chrome.tabs.create({url: viewTabUrl}, function(tab) {
var targetId = tab.id;
var addSnapshotImageToTab = function(tabId, changedProps) {
if (tabId != targetId || changedProps.status != "complete") {
return;
}
chrome.tabs.onUpdated.removeListener(addSnapshotImageToTab);
var views = chrome.extension.getViews();
for (var i = 0; i < views.length; i++) {
var view = views[i];
if (view.location.href == viewTabUrl) {
view.pivotate.setTabData({url: request.location.href});
view.pivotate.setScreenShot(screenshotUrl, currentId);
break;
}
}
};
chrome.tabs.onUpdated.addListener(addSnapshotImageToTab);
});
});
}
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript({
// Dummy code for future use
code: 'chrome.runtime.sendMessage({location: window.location})'
});
});