/
popup.js
79 lines (77 loc) · 1.91 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(function() {
// Error handling
var error = document.getElementById('errorarea');
var showError = function(msg) {
error.innerText = msg;
setTimeout(function() {
error.innerText = '';
}, 4000);
}
// Presets
var addy = document.getElementById('addy');
var presets = {
'near': {
'Now': '1minute',
'1 Hour': '1hour',
'Tomorrow': 'tomorrow'
},
'week1': {
'Monday': 'monday',
'Tuesday': 'tuesday',
'Wednesday': 'wednesday',
},
'week2': {
'Thursday': 'thursday',
'Friday': 'friday',
'Saturday': 'saturday',
'Sunday': 'sunday'
}
}
var presetarea = document.getElementById('presetarea');
var generatePresetButton = function(name, action) {
if(typeof(action) == "string") {
action = function() {
return this;
}.bind(action);
}
var button = document.createElement('button');
button.textContent = name;
button.addEventListener('click', function() {
addy.value = action();
});
return button;
}
for(var preset in presets) {
var container = document.createElement('div');
var subpresets = presets[preset];
if (typeof(presets[preset]) == "string") {
container = presetarea
subpresets = {};
subpresets[preset] = presets[preset];
}
for(var subpreset in subpresets) {
container.appendChild(generatePresetButton(subpreset, subpresets[subpreset]));
}
presetarea.appendChild(container);
}
// Send button
var send = document.getElementById('send');
send.addEventListener('click', function() {
chrome.tabs.query({
"active": true,
"currentWindow": true
}, function(tab) {
if(tab == undefined || tab == null || tab.length == 0) {
showError('Could not get active tab');
return;
}
tab = tab[0];
var subject = encodeURIComponent(tab.title);
var body = encodeURIComponent(tab.url);
chrome.tabs.create({
'url': 'mailto:'+addy.value+'@followupthen.com?subject='+subject+'&body='+body,
'active': true
});
});
});
})()