-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstorageHandler.js
38 lines (34 loc) · 1.01 KB
/
storageHandler.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
/*
THIS FILE HANDLES YOUR STORAGE FUNCTIONS DEPENDING ON YOUR USER AGENT
THIS MAKES THE PLUGIN COMPATIBLE FOR FIREFOX
*/
function getStorage(name, forceLocal, callback) {
if (arguments.length == 2) {
if (Object.prototype.toString.call(forceLocal) == "[object Function]") {
callback = forceLocal;
forceLocal = false;
}
}
//Check if chrome sync is enabled
if (navigator.userAgent.includes("Chrome") && !forceLocal) {
//Chrome sync is enabled
//Therefore use the API
chrome.storage.sync.get(name, callback);
} else {
//Chrome sync is disabled
//Use the local storage instead
chrome.storage.local.get(name, callback);
}
}
function setStorage(value, forceLocal, callback) {
if (arguments.length == 1) forceLocal = false;
if (navigator.userAgent.includes("Chrome") && !forceLocal) {
//Chrome sync is enabled
//Therefore use the API
chrome.storage.sync.set(value, callback);
} else {
//Chrome sync is disabled
//Use the local storage instead
chrome.storage.local.set(value, callback);
}
}