-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
60 lines (51 loc) · 1.38 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
(function(){
var valid = true;
var init = function(){
initUI()
};
var initUI = function(){
chrome.runtime.sendMessage({cmd: 'app.getStatus'}, function(appStatus){
$('#app-status').prop('checked', appStatus);
});
chrome.runtime.sendMessage({cmd: 'app.getKey'}, function(response){
if(!response)
valid=false;
setupMenu();
});
$('#app-status').change(function() {
chrome.runtime.sendMessage({cmd: 'app.toggleStatus'}, function(appStatus){
$('#app-status').prop('checked', appStatus);
});
});
$('#validate').click(function() {
name = $('#name').val()
key = $('#key').val()
chrome.runtime.sendMessage({cmd: 'api.validate', data: {name: name, key: key}}, function(response){
valid = response
setupMenu();
});
});
};
function setupMenu(){
if(!valid){
$('.validator').removeClass('hidden');
}
else{
$('.validator').addClass('hidden');
$('li a').click(function(){
run($(this).attr('cmd'));
});
}
}
var run = function(action){
if (action === 'create') {
chrome.tabs.create({url: '/html/create.html'});
}
else if (action === 'newsfeed') {
chrome.tabs.create({url: '/html/newsfeed.html'});
}
};
return {
init: init
};
})().init();