-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpopup.js
More file actions
46 lines (42 loc) · 1.57 KB
/
popup.js
File metadata and controls
46 lines (42 loc) · 1.57 KB
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
function onMenuSelected(tab, id) {
function sendRequestCallbackHandler(response) {
var data = response;
chrome.extension.sendMessage({
command: 'setClipboard',
data: data
});
window.close();
}
if(id == 'copyall') {
chrome.tabs.sendMessage(tab.id, 'getAllLinks', sendRequestCallbackHandler);
} else if(id == 'copytext') {
chrome.tabs.sendMessage(tab.id, 'getTextLinks', sendRequestCallbackHandler);
} else if (id == 'copyselection') {
chrome.tabs.sendMessage(tab.id, 'getSelectionLinks', sendRequestCallbackHandler);
} else if(id == 'copytextselection') {
chrome.tabs.sendMessage(tab.id, 'getTextLinksSelection', sendRequestCallbackHandler);
}
}
function setupEventHandlers() {
document.addEventListener('mouseup', function(ev) {
chrome.windows.getCurrent(function(w) {
chrome.tabs.getSelected(w.id, function(t) {
onMenuSelected(t, ev.target.id);
});
});
}, false);
}
window.addEventListener('load', function() {
chrome.tabs.executeScript(null, { "file": "content.js" }, function () {
chrome.windows.getCurrent(function(w) {
chrome.tabs.getSelected(w.id, function(t) {
if(t.url.indexOf("chrome.google.com/webstore") != -1) {
// Extensions generally don't work on Google Chrome Webstore!
document.body.innerHTML = "<h4>Extensions generally won't work on Chrome Webstore due to Google policies. Please go to another page in order to use the extension.</h4>";
} else {
setupEventHandlers();
}
});
});
});
}, false);