-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
97 lines (94 loc) · 2.92 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Generated by CoffeeScript 1.8.0
(function() {
var renderUser;
renderUser = function() {
return chrome.runtime.sendMessage({
type: 'user-info',
interactive: true
}, function(user_info) {
if (!user_info.error) {
$('#signin').hide();
$('#revoke').show();
return $('#user').html("<div>\n <span class=\"name\">Logged in as: " + user_info.login + "</span>\n <img src=\"" + user_info.avatar_url + "\"/>\n</div>");
} else {
$('#signin').show();
$('#revoke').hide();
return $('#user').html("<div>\n <span class=\"name\">Error detected: </span>\n <span class=\"error\">" + user_info.error + "</span>\n</div>");
}
});
};
$(document).ready(function() {
return chrome.runtime.sendMessage({
type: 'get-token'
}, function(data) {
var access_token, el, error, _i, _len, _ref, _results;
error = data.error, access_token = data.access_token;
$('#signin').on('click', function(e) {
return chrome.runtime.sendMessage({
type: 'user-info',
interactive: true
}, function(user_info) {
$('#signin').hide();
return $('#revoke').show();
});
});
$('#revoke').on('click', function(e) {
chrome.runtime.sendMessage({
type: 'revoke-token'
});
$('#user').empty();
$('#signin').show();
return $('#revoke').hide();
});
if (access_token) {
$('#user').empty();
$('#signin').hide();
$('#revoke').show();
renderUser();
} else {
$('#user').empty();
$('#signin').show();
$('#revoke').hide();
}
$('#navigation > div').on('click', function(e) {
var $nav, cls;
$nav = $(e.currentTarget);
cls = $nav.attr('class');
return $nav.closest('body').attr('class', cls);
});
$('.nav.config > input').on('click', function(e) {
var $check, val;
$check = $(e.currentTarget);
val = $check.val();
chrome.runtime.sendMessage({
type: 'set-config',
config: val,
val: $check.is(':checked')
});
if (val === 'disable') {
return $check.siblings('input').attr('disabled', $check.is(':checked'));
}
});
_ref = $('.nav.config > input');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
el = _ref[_i];
_results.push((function() {
var $el, val;
$el = $(el);
val = $el.val();
return chrome.runtime.sendMessage({
type: 'get-config',
config: val
}, function(data) {
if (val === 'disable') {
$el.siblings('input').attr('disabled', data === 'true');
}
return $el.prop('checked', data === 'true' || false);
});
})());
}
return _results;
});
});
}).call(this);