forked from bobbyrne01/save-text-to-file-firefox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
58 lines (54 loc) · 2.38 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
'use strict';
/*******************************************************************************
* Copyright IBM Corp. 2017
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
const DEFAULT_FILE_NAME_PREFIX = 'save-text-to-file--';
function saveOptions() {
browser.storage.sync.set({
fileNamePrefix: document.getElementById('fileNamePrefix').value,
dateFormat: document.getElementById('dateFormat').value,
urlInFile: document.getElementById('urlInFile').checked,
directorySelectionDialog: document.getElementById('directorySelectionDialog').checked,
notifications: document.getElementById('notifications').checked,
conflictAction: document.getElementById('conflictAction').value
}, function() {
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 5000);
});
}
// Restores state using the preferences stored in chrome.storage.
function restoreOptions() {
// default values
browser.storage.sync.get({
fileNamePrefix: DEFAULT_FILE_NAME_PREFIX,
dateFormat: 0,
urlInFile: false,
directorySelectionDialog: false,
notifications: true,
conflictAction: 'uniquify'
}, function(items) {
document.getElementById('fileNamePrefix').value = items.fileNamePrefix;
document.getElementById('dateFormat').value = items.dateFormat;
document.getElementById('urlInFile').checked = items.urlInFile;
document.getElementById('directorySelectionDialog').checked = items.directorySelectionDialog;
document.getElementById('notifications').checked = items.notifications;
document.getElementById('conflictAction').value = items.conflictAction;
});
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);