108 |
109 |
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/addon/options.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | /*******************************************************************************
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | *******************************************************************************/
15 |
16 | const DEFAULT_FILE_NAME_PREFIX = 'save-text-to-file--';
17 | const HOST_APPLICATION_NAME = 'savetexttofile';
18 | const TEST_CONNECTIVITY_ACTION = 'TEST_CONNECTIVITY';
19 |
20 | function saveOptions() {
21 |
22 | chrome.storage.sync.set({
23 | fileNamePrefix: document.getElementById('fileNamePrefix').value,
24 | dateFormat: document.getElementById('dateFormat').value,
25 | fileNameComponentOrder: document.getElementById('fileNameComponentOrder').value,
26 | prefixPageTitleInFileName: document.getElementById('prefixPageTitleInFileName').checked,
27 | fileNameComponentSeparator: document.getElementById('fileNameComponentSeparator').value,
28 | pageTitleInFile: document.getElementById('pageTitleInFile').checked,
29 | urlInFile: document.getElementById('urlInFile').checked,
30 | templateText: document.getElementById('templateText').value,
31 | positionOfTemplateText: document.getElementById('positionOfTemplateText').value,
32 | directory: document.getElementById('directory').value,
33 | directorySelectionDialog: document.getElementById('directorySelectionDialog').checked,
34 | notifications: document.getElementById('notifications').checked,
35 | conflictAction: document.getElementById('conflictAction').value
36 | }, function() {
37 | var status = document.getElementById('status');
38 | status.style.visibility = 'visible';
39 | setTimeout(function() {
40 | status.style.visibility = 'hidden';
41 | }, 5000);
42 | });
43 | }
44 |
45 | function restoreOptions() {
46 | chrome.storage.sync.get({
47 | fileNamePrefix: DEFAULT_FILE_NAME_PREFIX,
48 | dateFormat: 0,
49 | fileNameComponentOrder: 0,
50 | prefixPageTitleInFileName: false,
51 | fileNameComponentSeparator: '-',
52 | pageTitleInFile: false,
53 | urlInFile: false,
54 | templateText: '',
55 | positionOfTemplateText: 0,
56 | directory: '',
57 | directorySelectionDialog: false,
58 | notifications: true,
59 | conflictAction: 'uniquify'
60 | }, function(items) {
61 | document.getElementById('fileNamePrefix').value = items.fileNamePrefix;
62 | document.getElementById('dateFormat').value = items.dateFormat;
63 | document.getElementById('fileNameComponentOrder').value = items.fileNameComponentOrder;
64 | document.getElementById('prefixPageTitleInFileName').checked = items.prefixPageTitleInFileName;
65 | document.getElementById('fileNameComponentSeparator').value = items.fileNameComponentSeparator;
66 | document.getElementById('pageTitleInFile').checked = items.pageTitleInFile;
67 | document.getElementById('urlInFile').checked = items.urlInFile;
68 | document.getElementById('templateText').value = items.templateText;
69 | document.getElementById('positionOfTemplateText').value = items.positionOfTemplateText;
70 | document.getElementById('directory').value = items.directory;
71 | document.getElementById('directorySelectionDialog').checked = items.directorySelectionDialog;
72 | document.getElementById('notifications').checked = items.notifications;
73 | document.getElementById('conflictAction').value = items.conflictAction;
74 | });
75 | }
76 |
77 | function appConnectionTest() {
78 | var testConnectivityPayload = {
79 | action: TEST_CONNECTIVITY_ACTION
80 | };
81 | chrome.runtime.sendNativeMessage(HOST_APPLICATION_NAME, testConnectivityPayload, function(response) {
82 | if (chrome.runtime.lastError) {
83 |
84 | document.getElementById('nativeAppMessage').innerHTML =
85 | '' +
86 | 'The \'Save Text to File\' host application was not found on this device.
' +
87 | 'To enable all extension features, follow setup instructions outlined here' +
88 | '
';
89 | document.getElementById('directoryMessage').innerHTML =
90 | '' +
91 | 'The ability to specify a save directory requires installation of the \'Save Text to File\' host application.
' +
92 | 'The extension can then communicate with the application to perform certain tasks.' +
93 | '
' +
94 | '