-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpopup.js
60 lines (53 loc) · 1.7 KB
/
popup.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
51
52
53
54
55
56
57
58
59
60
// Convienence function to convert a setTimeout to a delay.
function later(delay) {
return new Promise(function(resolve) {
setTimeout(resolve, delay);
});
}
// Convienence function to send a message to a remote tab.
msg = function(text, payload, callback=console.log, tab_id=null) {
if (tab_id) {
chrome.tabs.sendMessage(tabid, {text: text, payload: payload}, callback);
} else {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
var tab = tabs[0];
var tabid = tab_id || tab.id;
chrome.tabs.sendMessage(tabid, {text: text, payload: payload}, callback);
});
}
}
$(function() {
msg("log", "initialized");
$("#cached-message").click(function() {
msg("cached-message", $("#message").val());
window.close();
});
// Collect all of the tabs information, put it in the clipboard
$("#harvest").click(function() {
var result = [];
msg("log", "starting harvest");
msg("harvest", "");
window.close();
/*
// Failed attempt to iterate over all of the open tabs and perform
// the harvest action on each one.
chrome.tabs.query({currentWindow: true}, function(tabs) {
msg("log", "total tabs: " + tabs.length);
for (let i = 0; i < tabs.length; i++) {
let tab_id = tabs[i].id;
later(500 * i).then(function() {
msg("log", "" + i + ": harvesting id: " + tab_id);
chrome.tabs.update(tab_id, {active: true});
msg("harvest", "", console.log, tab_id);
});
}
});
*/
});
// When content is added to the message box, populate it with details from
// facts.
$("#message").keyup(function() {
msg("message", $("#message").val());
window.close();
});
})