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;
+ } else {
+ var endTime = startTime;
+ startTime = 0;
+ }
var range = {
- startTime: (now - time * 60 * 60 * 1000), // time from hrs to ms
- endTime: now
+ startTime: startTime,
+ endTime: endTime
};
// Delete history in the range
chrome.history.deleteRange(range, didClearHistory);
}
}
+function runCleaner() {
+ var clearCookies = localStorage['cookies'] || CONSTANTS.NO;
+
+ if (clearCookies === CONSTANTS.YES) {
+ clearCookies(clearHistory);
+ } else {
+ clearHistory();
+ }
+}
+
/**
* Executes when the user clicks the browser action. Uses stored values from
* {@code localStorage}
chrome.browserAction.onClicked.addListener(function(tab) {
// Get the value from localStorage
var showPrompt = localStorage['prompt'] || CONSTANTS.YES;
- var clearCookies = localStorage['cookies'] || CONSTANTS.NO;
// The confirmation message to ask
var message = chrome.i18n.getMessage('confirmPrompt');
if (!confirm(message))
return;
}
- if (clearCookies === CONSTANTS.YES) {
- clearCookies(clearHistory);
- } else {
- clearHistory();
- }
+ runCleaner();
+});
+
+chrome.alarms.create(CONSTANTS.CLEANER_ALARM, {
+ // First fire 10 minutes from now.
+ 'when': Date.now() + (10 * 60 * 1000),
+ 'periodInMinutes': 24 * 60
+});
+
+chrome.alarms.onAlarm.addListener(function(alarm) {
+ var autoCleaner = localStorage['autoclear'] || CONSTANTS.NO;
+ if (autoCleaner === CONSTANTS.YES)
+ runCleaner();
+ console.log('running');
});