forked from johnmave126/better-history
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathchrome_sync.js
45 lines (38 loc) · 1.09 KB
/
chrome_sync.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
(function() {
var chromeAPI;
var wrappedCallback = function(operation, data, callback) {
if(chromeAPI.runtime.lastError) {
var message = chromeAPI.runtime.lastError.message;
// handle error
}
if(typeof callback !== 'undefined') {
callback(data);
}
};
var ChromeSync = function(options) {
if(typeof options === 'undefined') {
options = {};
}
chromeAPI = options.chrome || chrome;
};
ChromeSync.prototype.save = function(object, callback) {
chromeAPI.storage.sync.set(object, function(data) {
wrappedCallback('Set', data, callback);
});
};
ChromeSync.prototype.remove = function(key, callback) {
chromeAPI.storage.sync.remove(key, function(data) {
wrappedCallback('Remove', data, callback);
});
};
ChromeSync.prototype.get = function(key, callback) {
chromeAPI.storage.sync.get(key, function(data) {
wrappedCallback('Get', data, callback);
});
};
if(typeof module !== 'undefined' && module.exports) {
module.exports = ChromeSync;
} else {
window.ChromeSync = ChromeSync;
}
})();