include/webutil.js: fix when 'chrome' global not present.
This commit is contained in:
parent
6f955236e6
commit
d5fe15096b
|
@ -126,8 +126,8 @@ WebUtil.eraseCookie = function(name) {
|
||||||
|
|
||||||
WebUtil.initSettings = function(callback) {
|
WebUtil.initSettings = function(callback) {
|
||||||
var callbackArgs = Array.prototype.slice.call(arguments, 1);
|
var callbackArgs = Array.prototype.slice.call(arguments, 1);
|
||||||
if (chrome && chrome.storage) {
|
if (window.chrome && window.chrome.storage) {
|
||||||
chrome.storage.sync.get(function (cfg) {
|
window.chrome.storage.sync.get(function (cfg) {
|
||||||
WebUtil.settings = cfg;
|
WebUtil.settings = cfg;
|
||||||
console.log(WebUtil.settings);
|
console.log(WebUtil.settings);
|
||||||
if (callback) {
|
if (callback) {
|
||||||
|
@ -144,11 +144,11 @@ WebUtil.initSettings = function(callback) {
|
||||||
|
|
||||||
// No days means only for this browser session
|
// No days means only for this browser session
|
||||||
WebUtil.writeSetting = function(name, value) {
|
WebUtil.writeSetting = function(name, value) {
|
||||||
if (chrome && chrome.storage) {
|
if (window.chrome && window.chrome.storage) {
|
||||||
//console.log("writeSetting:", name, value);
|
//console.log("writeSetting:", name, value);
|
||||||
if (WebUtil.settings[name] !== value) {
|
if (WebUtil.settings[name] !== value) {
|
||||||
WebUtil.settings[name] = value;
|
WebUtil.settings[name] = value;
|
||||||
chrome.storage.sync.set(WebUtil.settings);
|
window.chrome.storage.sync.set(WebUtil.settings);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem(name, value);
|
localStorage.setItem(name, value);
|
||||||
|
@ -157,7 +157,7 @@ WebUtil.writeSetting = function(name, value) {
|
||||||
|
|
||||||
WebUtil.readSetting = function(name, defaultValue) {
|
WebUtil.readSetting = function(name, defaultValue) {
|
||||||
var value;
|
var value;
|
||||||
if (chrome && chrome.storage) {
|
if (window.chrome && window.chrome.storage) {
|
||||||
value = WebUtil.settings[name];
|
value = WebUtil.settings[name];
|
||||||
} else {
|
} else {
|
||||||
value = localStorage.getItem(name);
|
value = localStorage.getItem(name);
|
||||||
|
@ -173,8 +173,8 @@ WebUtil.readSetting = function(name, defaultValue) {
|
||||||
};
|
};
|
||||||
|
|
||||||
WebUtil.eraseSetting = function(name) {
|
WebUtil.eraseSetting = function(name) {
|
||||||
if (chrome && chrome.storage) {
|
if (window.chrome && window.chrome.storage) {
|
||||||
chrome.storage.sync.remove(name);
|
window.chrome.storage.sync.remove(name);
|
||||||
delete WebUtil.settings[name];
|
delete WebUtil.settings[name];
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem(name);
|
localStorage.removeItem(name);
|
||||||
|
|
Loading…
Reference in New Issue