]> git.wh0rd.org - chrome-ext/clearhistory-advance-fork.git/commitdiff
use chrome.storage.sync v1.5.1
authorMike Frysinger <vapier@gentoo.org>
Sun, 3 Feb 2013 05:14:32 +0000 (00:14 -0500)
committerMike Frysinger <vapier@gentoo.org>
Sat, 2 Mar 2013 22:49:17 +0000 (17:49 -0500)
javascript/clearhistory.js
javascript/options.js
manifest.json
views/options.html

index d05a2f694f9581438c57bcad119b50bd9d354583..73206ce175b6d6b37d031c4b1cbae9cbed3eeca7 100644 (file)
@@ -43,7 +43,8 @@ function clearCookies(callback) {
  * Callback for when history deletion is successful
  */
 function didClearHistory() {
-  var time = ~~(localStorage['time']) || CONSTANTS.DEFAULT_TIME;
+  chrome.storage.sync.get('time', function(s) {
+  var time = ~~(s.time) || CONSTANTS.DEFAULT_TIME;
   time = getUnitsForTime(time);
   var timeString = (time.time === -1) ?
                    chrome.i18n.getMessage('notificationTimeAll') :
@@ -58,6 +59,7 @@ function didClearHistory() {
   setTimeout(function() {
     notification.cancel();
   }, 5000);
+  });
 }
 
 /**
@@ -66,38 +68,42 @@ function didClearHistory() {
 function clearHistory() {
   //Get the values from localStorage
   // time is in hours
-  var time = ~~(localStorage['time']) || CONSTANTS.DEFAULT_TIME;
-  if (time === -1) {
-    // Delete everything
-    chrome.history.deleteAll(didClearHistory);
-  } else {
-    // Create the range
-    var timeStart = localStorage['timeStart'] === CONSTANTS.YES;
-    var now = (new Date).getTime();
-    var startTime = (now - time * 60 * 60 * 1000);  // time from hrs to ms
-    if (timeStart) {
-      var endTime = now;
+  chrome.storage.sync.get(['time', 'timeStart'], function(s) {
+    var time = ~~(s.time) || CONSTANTS.DEFAULT_TIME;
+    if (time === -1) {
+      // Delete everything
+      chrome.history.deleteAll(didClearHistory);
     } else {
-      var endTime = startTime;
-      startTime = 0;
+      // Create the range
+      var timeStart = s.timeStart === CONSTANTS.YES;
+      var now = (new Date).getTime();
+      var startTime = (now - time * 60 * 60 * 1000);  // time from hrs to ms
+      if (timeStart) {
+        var endTime = now;
+      } else {
+        var endTime = startTime;
+        startTime = 0;
+      }
+      var range = {
+        startTime: startTime,
+        endTime: endTime
+      };
+      // Delete history in the range
+      chrome.history.deleteRange(range, didClearHistory);
     }
-    var range = {
-      startTime: startTime,
-      endTime: endTime
-    };
-    // Delete history in the range
-    chrome.history.deleteRange(range, didClearHistory);
-  }
+  });
 }
 
 function runCleaner() {
-  var clearCookies = localStorage['cookies'] || CONSTANTS.NO;
+  chrome.storage.sync.get('cookies', function(s) {
+    var clearCookies = s.cookies || CONSTANTS.NO;
 
-  if (clearCookies === CONSTANTS.YES) {
-    clearCookies(clearHistory);
-  } else {
-    clearHistory();
-  }
+    if (clearCookies === CONSTANTS.YES) {
+      clearCookies(clearHistory);
+    } else {
+      clearHistory();
+    }
+  });
 }
 
 /**
@@ -106,7 +112,8 @@ function runCleaner() {
  */
 chrome.browserAction.onClicked.addListener(function(tab) {
   // Get the value from localStorage
-  var showPrompt = localStorage['prompt'] || CONSTANTS.YES;
+  chrome.storage.sync.get('prompt', function(s) {
+  var showPrompt = s.prompt || CONSTANTS.YES;
 
   // The confirmation message to ask
   var message = chrome.i18n.getMessage('confirmPrompt');
@@ -117,6 +124,7 @@ chrome.browserAction.onClicked.addListener(function(tab) {
       return;
   }
   runCleaner();
+  });
 });
 
 chrome.alarms.get(CONSTANTS.CLEANER_ALARM, function(a) {
@@ -131,8 +139,9 @@ chrome.alarms.get(CONSTANTS.CLEANER_ALARM, function(a) {
 });
 
 chrome.alarms.onAlarm.addListener(function(alarm) {
-  var autoCleaner = localStorage['autoclear'] || CONSTANTS.NO;
-  if (autoCleaner === CONSTANTS.YES)
-    runCleaner();
-  console.log('running');
+  chrome.storage.sync.get('autoclear', function(s) {
+    var autoCleaner = s.autoclear || CONSTANTS.NO;
+    if (autoCleaner === CONSTANTS.YES)
+      runCleaner();
+  });
 });
index f6dfcadec4533dfb4ef075ea94761270ee991bc3..94ea31eb9da15c656258146c9604d41bdaf51d85 100644 (file)
@@ -42,24 +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 autoClear = localStorage['autoclear'] || 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=autoclear]')[0].checked = (autoClear === 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);
+  });
 }
 
 /**
@@ -67,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();
 }
 
@@ -75,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();
 }
 
index d089fb60ff01020ba2f89288ff5907404a15bced..266ee17a8a63e77341ead6a448debb60c132933b 100644 (file)
@@ -10,6 +10,7 @@
     "history",
     "cookies",
     "notifications",
+    "storage",
     "http://*/*",
     "https://*/*"
   ],
index 6ac4f678c2c4349efd90a3875a470571d01d3508..97b42fd418bdcb603db0e1a520d859b1dd798403 100644 (file)
@@ -33,7 +33,7 @@
           <div class="opt-value">
             <div class="opt-option">   <!-- 1 hour -->
               <input name="time" class="opt-chk" type="radio" value="1"
-                tabindex="1" checked>
+                tabindex="1">
               <div class="opt-label" id="opt-1"></div>
             </div>
             <!-- <br> -->