From e9c730a6e26da297f350c6c7a03f3d5564e28d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zeus=20G=C3=B3mez=20Marmolejo?= Date: Tue, 30 Sep 2014 18:34:48 +0200 Subject: [PATCH] add support for chrome apps --- browser.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/browser.js b/browser.js index ce6369f1..aab31cac 100644 --- a/browser.js +++ b/browser.js @@ -12,6 +12,17 @@ exports.save = save; exports.load = load; exports.useColors = useColors; +/** + * Use chrome.storage.local if we are in an app + */ + +var storage; + +if (chrome.storage.local !== undefined) + storage = chrome.storage.local; +else + storage = window.localStorage; + /** * Colors. */ @@ -118,9 +129,9 @@ function log() { function save(namespaces) { try { if (null == namespaces) { - localStorage.removeItem('debug'); + storage.removeItem('debug'); } else { - localStorage.debug = namespaces; + storage.debug = namespaces; } } catch(e) {} } @@ -135,7 +146,7 @@ function save(namespaces) { function load() { var r; try { - r = localStorage.debug; + r = storage.debug; } catch(e) {} return r; }