forked from web-scrobbler/web-scrobbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
90 lines (66 loc) · 3.01 KB
/
options.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
// options ---------------------------------------------------------------------
$(function(){
// use immediate-change checkboxes
$('#use-notifications').click(function(){
localStorage['useNotifications'] = this.checked ? 1 : 0;
updateDisabled();
});
$('#use-notifications-nowplaying').click(function(){
localStorage['useNotificationsNowPlaying'] = this.checked ? 1 : 0;
});
$('#use-notifications-scrobbled').click(function(){
localStorage['useNotificationsScrobbled'] = this.checked ? 1 : 0;
});
$('#auto-hide-notifications').click(function(){
localStorage['autoHideNotifications'] = this.checked ? 1 : 0;
});
$('#use-autocorrect').click(function(){
localStorage['useAutocorrect'] = this.checked ? 1 : 0;
});
// preload options
$('#use-notifications').attr('checked', (localStorage['useNotifications'] == 1));
$('#use-notifications-nowplaying').attr('checked', (localStorage['useNotificationsNowPlaying'] == 1));
$('#use-notifications-scrobbled').attr('checked', (localStorage['useNotificationsScrobbled'] == 1));
$('#auto-hide-notifications').attr('checked', (localStorage['autoHideNotifications'] == 1));
$('#use-autocorrect').attr('checked', (localStorage['useAutocorrect'] == 1));
// disable subitems
function updateDisabled() {
$('#use-notifications-nowplaying').attr('disabled', (!$('#use-notifications').is(':checked')));
$('#use-notifications-scrobbled').attr('disabled', (!$('#use-notifications').is(':checked')));
$('#auto-hide-notifications').attr('disabled', (!$('#use-notifications').is(':checked')));
}
$('button#authorize').click(function() {
authorize();
});
// generate connectors and their checkboxes
createConnectors();
});
function createConnectors() {
var parent = $('ul#connectors');
// prevent mutation of original
var conns = connectors.slice(0);
// sort alphabetically
conns.sort(function(a, b){ return a.label.localeCompare(b.label); });
conns.forEach(function(connector, index){
var newEl = $('<li><input type="checkbox" id="conn-' + index + '"> \n\
<label for="conn-' + index + '">' + connector.label + '</label>\n\
</li>');
var domEl = newEl.appendTo(parent);
var checkbox = domEl.find('input');
checkbox.attr('checked', isConnectorEnabled(connector.label));
checkbox.click(function(){
var box = $(this);
var disabledArray = JSON.parse(localStorage.disabledConnectors);
// always remove, to prevent duplicates
var index = disabledArray.indexOf(connector.label);
if (index > -1) {
disabledArray.splice(index, 1);
}
if (!box.is(':checked')) {
disabledArray.push(connector.label);
}
localStorage.disabledConnectors = JSON.stringify(disabledArray);
console.log(localStorage.disabledConnectors);
});
});
}