forked from muan/github-gmail
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
58 lines (49 loc) · 1.67 KB
/
options.js
File metadata and controls
58 lines (49 loc) · 1.67 KB
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
$.getJSON('options.json', function(data) {
defaultOptions = data
initOptions(defaultOptions)
})
function initOptions (defaultOptions) {
options = defaultOptions
for (var key in defaultOptions) {
if( localStorage[key] ) { options[key].val = localStorage[key] }
}
optionsWrapper = document.getElementById('options')
for (var key in options) {
html = '<div class=\'option\'><label>' + key + ' ' + options[key].hint + '</label>'
html += '<p class=\'description\'>' + options[key].description + '</p>'
html += '<input name=\'' + key + '\' value=\'' + options[key].val +'\' type=\'text\' /></div>'
$(optionsWrapper).append(html)
}
}
$(document).on('keypress', '[name=Shortcut], [name=BackgroundShortcut]', function(e) {
if (e.keyCode == 13 && !e.shiftKey && !e.metaKey && !e.altKey && !e.ctrlKey ) return false
code = ''
keys = ['shift', 'alt', 'meta', 'ctrl']
keys.map(function(key) {
if( eval('e.' + key + 'Key' ) ) { code += key + " + " }
})
code += e.keyCode
$(this).val(code)
e.preventDefault()
})
$(document).on('keypress', 'input[type]', function(e) {
if( e.keyCode == 13 ) {
$(this).blur()
$('#save').click()
}
})
$(document).on('click', '#save', function() {
fields = []
$('input[name]').map(function(i, e) {
if( localStorage[e.name] != e.value ) fields.push(e)
localStorage[e.name] = e.value
})
// Update status to let user know options were saved.
var save = document.getElementById('save')
save.innerHTML = 'Updated!'
$(fields).closest('.option').removeClass('saved').addClass('saved')
setTimeout(function() {
$(fields).closest('.option').removeClass('saved')
save.innerHTML = 'Save'
}, 2050)
})