X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=javascript%2Foptions.js;h=94ea31eb9da15c656258146c9604d41bdaf51d85;hb=03eef92c55cf1da39e0151aaeb5aa756c243246f;hp=17139d59e576a283115724d70f99b41135b1ac96;hpb=cc8be4269068a6dac17a2b163308152a0f6a3938;p=chrome-ext%2Fclearhistory-advance-fork.git diff --git a/javascript/options.js b/javascript/options.js index 17139d5..94ea31e 100644 --- a/javascript/options.js +++ b/javascript/options.js @@ -32,6 +32,7 @@ function init() { $('#optionsTimeFor')[0].innerText = chrome.i18n.getMessage('optionsTimeFor'); $('#optionsTimeStart')[0].innerText = chrome.i18n.getMessage('optionsTimeStart'); $('#optionsCookies')[0].innerText = chrome.i18n.getMessage('optionsCookies'); + $('#optionsAutoclear')[0].innerText = chrome.i18n.getMessage('optionsAutoclear'); $('#optionsSaved > b')[0].innerText = chrome.i18n.getMessage('optionsSaved'); // Bind all the callbacks @@ -41,22 +42,24 @@ function init() { $('input.opt-chk[type=checkbox]').forEach(function(e) { e.onclick = setCheck; }); - $('#opt-prompt input.opt-chk[type=checkbox]').forEach(function(e) { - e.onclick = setPrompt; - }); // Load or set localStorage data - var timeStart = localStorage['timeStart'] || CONSTANTS.YES; - var time = ~~(localStorage['time']) || - (localStorage['time'] = CONSTANTS.DEFAULT_TIME); - var showPrompt = localStorage['prompt'] || - (localStorage['prompt'] = CONSTANTS.YES); - var clearCookies = localStorage['cookies'] || CONSTANTS.NO; + var settings = [ + 'timeStart', 'time', 'prompt', 'cookies', 'autoclear', + ]; + chrome.storage.sync.get(settings, function(s) { + var timeStart = s.timeStart || CONSTANTS.YES; + var time = ~~(s.time) || (s.time = CONSTANTS.DEFAULT_TIME); + var showPrompt = s.prompt || (s.prompt = CONSTANTS.YES); + var clearCookies = s.cookies || CONSTANTS.NO; + var autoClear = s.autoclear || CONSTANTS.NO; - $('input[name=timeStart]')[0].checked = (timeStart === CONSTANTS.YES); - $('input[name=time][value="' + time + '"]')[0].checked = true; - $('input[name=prompt]')[0].checked = (showPrompt === CONSTANTS.YES); - $('input[name=cookies]')[0].checked = (clearCookies === CONSTANTS.YES); + $('input[name=timeStart]')[0].checked = (timeStart === CONSTANTS.YES); + $('input[name=time][value="' + time + '"]')[0].checked = true; + $('input[name=prompt]')[0].checked = (showPrompt === CONSTANTS.YES); + $('input[name=cookies]')[0].checked = (clearCookies === CONSTANTS.YES); + $('input[name=autoclear]')[0].checked = (autoClear === CONSTANTS.YES); + }); } /** @@ -64,7 +67,7 @@ function init() { * @this {HTMLInputElement} The element (radio button) that was clicked. */ function toggle() { - localStorage['time'] = this.value; + chrome.storage.sync.set({'time': this.value}); optionSaved(); } @@ -72,13 +75,10 @@ function toggle() { * Sets the {@code localStorage.prompt} property when selected * @this {HTMLInputElement} The element (checkbox) that was clicked. */ -function setPrompt() { - localStorage['prompt'] = this.checked ? CONSTANTS.YES : CONSTANTS.NO; - optionSaved(); -} - function setCheck() { - localStorage[this.name] = this.checked ? CONSTANTS.YES : CONSTANTS.NO; + var setting = {}; + setting[this.name] = this.checked ? CONSTANTS.YES : CONSTANTS.NO; + chrome.storage.sync.set(setting); optionSaved(); }