-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
73 lines (64 loc) · 1.87 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
// SETTINGS
var default_options = {
inactivity_time: 30
}
// SCRIPT
// Get the option fields DOM
var $inactivity_time = document.getElementById('inactivity_time')
// Option page load
document.addEventListener('DOMContentLoaded', get_options)
// Save button click
document.getElementById('save').addEventListener('click', save_options)
// Restore button click
document.getElementById('restore').addEventListener('click', restore_options)
// FUNCTIONS
/**
* Save the extension options
* from option fields to chrome sync data
*/
function save_options () {
var inactivity_time = parseInt(document.getElementById('inactivity_time').value, 10)
chrome.storage.sync.set({
inactivity_time: inactivity_time
}, function () {
// Update status to let user know options were saved.
var status = document.getElementById('status')
status.textContent = 'Options saved.'
setTimeout(function () {
status.textContent = ''
}, 750)
})
}
/**
* Get the extensions options from chrome sync data
* and set the option fields
*/
function get_options () {
chrome.storage.sync.get(['inactivity_time'], function (data) {
console.log('get options ->', data)
if (!data) {
chrome.storage.sync.set(default_options, function () {
$inactivity_time.value = default_options.inactivity_time
})
} else {
if (data.inactivity_time) {
$inactivity_time.value = data.inactivity_time
}
}
console.log('options ->', data)
})
}
/**
* Restore the default extension options
* to option fields and chrome sync data
*/
function restore_options () {
chrome.storage.sync.set(default_options, function () {
$inactivity_time.value = default_options.inactivity_time
var status = document.getElementById('status')
status.textContent = 'Options restored.'
setTimeout(function () {
status.textContent = ''
}, 750)
})
}