-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
89 lines (75 loc) · 2.64 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
$(function() {
var toastIconUri = null,
toastSoundUri = null;
$('#lblVersion').text(chrome.runtime.getManifest().version);
$('#radToast').buttonset();
$('#radShowCount').buttonset();
$('#fileToastIcon').on('change', function(event) {
var file = event.target.files[0]; // TODO: can this array be empty?
if (!file.type.match('image.*')) {
// TODO: display an error of some kind
return;
}
// TODO: worthwhile to encapsulate file operations?
var fileReader = new FileReader();
fileReader.onload = function(event) {
toastIconUri = event.target.result;
$('#imgToastIcon').prop('src', toastIconUri);
};
fileReader.readAsDataURL(file);
});
$('#fileToastSound').on('change', function(event) {
var file = event.target.files[0]; // TODO: can this array be empty?
if (!file.type.match('audio.*')) {
// TODO: display an error of some kind
// specifically for midis... I bet a lot of people will want midis
return;
}
// TODO: worthwhile to encapsulate file operations?
var fileReader = new FileReader();
fileReader.onload = function(event) {
toastSoundUri = event.target.result;
$('#audToastSound').prop('src', toastSoundUri);
};
fileReader.readAsDataURL(file);
});
var _initializeSettings = function()
{
var areNotificationsOn = jmtyler.settings.get('notifications_on');
if (areNotificationsOn) {
$('#radToastOn').prop('checked', true);
} else {
$('#radToastOff').prop('checked', true);
}
$('#radToastOff').button('refresh');
var doShowPageCount = jmtyler.settings.get('show_page_count');
if (doShowPageCount) {
$('#radShowCountOn').prop('checked', true);
} else {
$('#radShowCountOff').prop('checked', true);
}
$('#radShowCountOff').button('refresh');
toastIconUri = jmtyler.settings.get('toast_icon_uri');
$('#imgToastIcon').prop('src', toastIconUri);
toastSoundUri = jmtyler.settings.get('toast_sound_uri');
$('#audToastSound').prop('src', toastSoundUri);
};
// TODO: eventually implement live edit
$('#btnSave').button();
$('#btnSave').on('click', function() {
var areNotificationsOn = $('#radToast :radio:checked').val() == 'on',
doShowPageCount = $('#radShowCount :radio:checked').val() == 'on';
jmtyler.settings.set('notifications_on', areNotificationsOn)
.set('show_page_count', doShowPageCount)
.set('toast_icon_uri', toastIconUri)
.set('toast_sound_uri', toastSoundUri);
chrome.runtime.sendMessage({ method: 'OnSettingsChange' });
});
$('#btnReset').button();
$('#btnReset').on('click', function() {
jmtyler.settings.clear();
_initializeSettings();
chrome.runtime.sendMessage({ method: 'OnSettingsChange' });
});
_initializeSettings();
});