-
Notifications
You must be signed in to change notification settings - Fork 3
/
shared.js
97 lines (91 loc) · 2.6 KB
/
shared.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
90
91
92
93
94
95
96
97
/**
* Copyright (c) 2018 Andy Bao
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* Shared JS
*/
let isChrome = typeof browser === "undefined";
function DEFAULT_OPTIONS() {
return {
dangerDomains: '',
safeDomains: '',
badWords: '',
historyProcessor: '',
doRegexDangerDomains: false,
doRegexSafeDomains: false,
doRegexDangerKeywords: false,
doCheckEntireUrl: false,
scanAll: false,
continuousMatching: false,
doPrefix: true,
doOutline: true,
doBadge: true,
injectCss: false,
injectJs: false,
prefixText: '[DH] ',
outlineColor: '#ff0000',
badgeText: '!',
badgeColor: '#ff0000',
cssCode: '',
jsCode: ''
};
}
//Get proper storage mechanism
function storage() {
// Reliable storage shim
return {
get: function(def, callback) {
// Always try sync storage first
if(chrome.storage.sync != null) {
chrome.storage.sync.get(def, function(items) {
if(items != null) {
// Sync storage works! Use sync storage items!
callback(items);
} else {
// Sync storage not available
// use local
chrome.storage.local.get(def, callback);
}
});
} else {
// Sync storage not enabled so only choice is local
chrome.storage.local.get(def, callback);
}
},
set: function(contents, callback) {
// Set both storages (cannot reliably detect which is available)
if(chrome.storage.sync != null) {
// Set sync first (callback will still be called even
// if sync is disabled)
chrome.storage.sync.set(contents, function() {
// Done setting sync, set local
chrome.storage.local.set(contents, callback);
});
} else {
// Sync not enabled, only set local
chrome.storage.local.set(contents, callback);
}
},
clear: function(callback) {
// Clear both storages (cannot reliably detect which is available)
if(chrome.storage.sync != null) {
// Clear sync first (callback will still be called even
// if sync is disabled)
chrome.storage.sync.clear(function() {
// Done clearing sync, clear local
chrome.storage.local.clear(callback);
});
} else {
// Sync not enabled, only clear local
chrome.storage.local.clear(callback);
}
}
};
}