]> git.wh0rd.org - chrome-ext/clearhistory-advance-fork.git/blobdiff - javascript/options.js
allow people to delete *old* history rather than *new* history
[chrome-ext/clearhistory-advance-fork.git] / javascript / options.js
index a3f3b01f93d78baf9653dcbc89e26c2a8e3d4475..17139d59e576a283115724d70f99b41135b1ac96 100644 (file)
@@ -7,9 +7,6 @@
 
 window.addEventListener('load', init, false);
 
-//Get the constants from the background page
-var CONSTANTS = chrome.extension.getBackgroundPage().CONSTANTS;
-
 /**
  * Initializes the i18n strings.
  * Loads values from localStorage and applies them to the elements
@@ -33,24 +30,33 @@ function init() {
   $('#optionsHeader')[0].innerText = chrome.i18n.getMessage('optionsHeader');
   $('#optionsPrompt')[0].innerText = chrome.i18n.getMessage('optionsPrompt');
   $('#optionsTimeFor')[0].innerText = chrome.i18n.getMessage('optionsTimeFor');
+  $('#optionsTimeStart')[0].innerText = chrome.i18n.getMessage('optionsTimeStart');
+  $('#optionsCookies')[0].innerText = chrome.i18n.getMessage('optionsCookies');
   $('#optionsSaved > b')[0].innerText = chrome.i18n.getMessage('optionsSaved');
 
   // Bind all the callbacks
   $('#opt-time input.opt-chk[type=radio]').forEach(function(e) {
     e.onclick = toggle;
   });
+  $('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;
 
+  $('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);
 }
 
 /**
@@ -71,6 +77,11 @@ function setPrompt() {
   optionSaved();
 }
 
+function setCheck() {
+  localStorage[this.name] = this.checked ? CONSTANTS.YES : CONSTANTS.NO;
+  optionSaved();
+}
+
 // For rapid changes/saves
 var isSaving = null;
 /**