-
Notifications
You must be signed in to change notification settings - Fork 2
/
form.js
executable file
·62 lines (43 loc) · 1.69 KB
/
form.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
var Extension = (function(){
function Extension() {
var parent = this;
// On populate
document.querySelector('#populate').addEventListener('click', function(){
return parent.request.apply(parent);
});
document.querySelector('#manage').addEventListener('click', function(){
return parent.manage.apply(parent);
});
// On message receive
chrome.extension.onMessage.addListener(this.store);
}
Extension.prototype.request = function() {
var genderElement = document.querySelector('select[name=gender]');
var nameElement = document.querySelector('select[name=name]');
var countryElement = document.querySelector('select[name=country]');
var parameters = {
gender: genderElement.options[genderElement.selectedIndex].value,
country: countryElement.options[countryElement.selectedIndex].value,
name: nameElement.options[nameElement.selectedIndex].value
};
var request = new Request(parameters);
request.aftercomplete = this.store; // TODO: Use pubsub
request.send();
};
Extension.prototype.manage = function() {
chrome.tabs.create({
url: chrome.extension.getURL('manage.html')
});
};
Extension.prototype.store = function(data) {
if (localStorage['rows'] === undefined) {
localStorage['rows'] = JSON.stringify({});
}
// Get rows
var rows = JSON.parse(localStorage['rows']);
rows[data.emailAddress] = data;
localStorage['rows'] = JSON.stringify(rows);
};
return Extension;
})();
new Extension();