]> git.wh0rd.org - chrome-ext/clearhistory-advance-fork.git/blobdiff - javascript/options.js
rewrite options page to be more chrome-like
[chrome-ext/clearhistory-advance-fork.git] / javascript / options.js
index f40b46ce5b0872aec1a2364a9688df926e80d103..bd3a2275c1b341372d9bc3f7f7d0b61556d7fb42 100644 (file)
@@ -26,21 +26,15 @@ function init() {
     elements[1].innerText = message;
   });
 
-  $('#optionsTitle')[0].innerText = chrome.i18n.getMessage('optionsTitle');
-  $('#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');
-  $('#optionsDownloads')[0].innerText = chrome.i18n.getMessage('optionsDownloads');
-  $('#optionsAutoclear')[0].innerText = chrome.i18n.getMessage('optionsAutoclear');
-  $('#optionsSaved > b')[0].innerText = chrome.i18n.getMessage('optionsSaved');
+  $('[i18n-content]').forEach(function(ele) {
+    ele.innerText = chrome.i18n.getMessage(ele.getAttribute('i18n-content'));
+  });
 
   // Bind all the callbacks
-  $('#opt-time input.opt-chk[type=radio]').forEach(function(e) {
+  $('input[type=radio]').forEach(function(e) {
     e.onclick = toggle;
   });
-  $('input.opt-chk[type=checkbox]').forEach(function(e) {
+  $('input[type=checkbox]').forEach(function(e) {
     e.onclick = setCheck;
   });
 
@@ -56,7 +50,7 @@ function init() {
     var clearDownloads = s.downloads || CONSTANTS.NO;
     var autoClear = s.autoclear || CONSTANTS.NO;
 
-    $('input[name=timeStart]')[0].checked = (timeStart === CONSTANTS.YES);
+    $('input[name=timeStart][value="' + timeStart + '"]')[0].checked = true;
     $('input[name=time][value="' + time + '"]')[0].checked = true;
     $('input[name=prompt]')[0].checked = (showPrompt === CONSTANTS.YES);
     $('input[name=cookies]')[0].checked = (clearCookies === CONSTANTS.YES);
@@ -70,7 +64,9 @@ function init() {
  * @this {HTMLInputElement} The element (radio button) that was clicked.
  */
 function toggle() {
-  chrome.storage.sync.set({'time': this.value});
+  var setting = {};
+  setting[this.name] = this.value;
+  chrome.storage.sync.set(setting);
   optionSaved();
 }