Skip to content

Commit a98c283

Browse files
committed
Merge pull request #143 from marmolejo/master
add support for chrome apps
2 parents 85bd499 + 3f97ec6 commit a98c283

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

browser.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ exports.save = save;
1212
exports.load = load;
1313
exports.useColors = useColors;
1414

15+
/**
16+
* Use chrome.storage.local if we are in an app
17+
*/
18+
19+
var storage;
20+
21+
if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined')
22+
storage = chrome.storage.local;
23+
else
24+
storage = window.localStorage;
25+
1526
/**
1627
* Colors.
1728
*/
@@ -118,9 +129,9 @@ function log() {
118129
function save(namespaces) {
119130
try {
120131
if (null == namespaces) {
121-
localStorage.removeItem('debug');
132+
storage.removeItem('debug');
122133
} else {
123-
localStorage.debug = namespaces;
134+
storage.debug = namespaces;
124135
}
125136
} catch(e) {}
126137
}
@@ -135,7 +146,7 @@ function save(namespaces) {
135146
function load() {
136147
var r;
137148
try {
138-
r = localStorage.debug;
149+
r = storage.debug;
139150
} catch(e) {}
140151
return r;
141152
}

0 commit comments

Comments
 (0)