* 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') :
setTimeout(function() {
notification.cancel();
}, 5000);
+ });
}
/**
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();
+ }
+ });
}
/**
*/
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');
return;
}
runCleaner();
+ });
});
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();
+ });
});