* @author arunjit@google.com (Arunjit Singh)
*/
+import {CONSTANTS} from './background.js';
+import {getUnitsForTime} from './util.js';
+
function getClearDate(s) {
var time = ~~(s.time) || CONSTANTS.DEFAULT_TIME;
if (time == -1)
* Callback for when history deletion is successful
*/
function didClearHistory(s) {
+ if (s.notify !== CONSTANTS.YES)
+ return;
+
var time = ~~(s.time) || CONSTANTS.DEFAULT_TIME;
time = getUnitsForTime(time);
- var timeString = (time.time === -1) ?
- chrome.i18n.getMessage('notificationTimeAll') :
- chrome.i18n.getMessage('notificationTime',
- [time.time, time.units]);
+ var timeMsg = (time.time === -1) ? 'notificationTimeAll' :
+ (s.timeStart === CONSTANTS.YES) ? 'notificationTimeNewer' :
+ 'notificationTimeOlder';
+ var timeString = chrome.i18n.getMessage(timeMsg, [time.time, time.units]);
var message = chrome.i18n.getMessage('notificationBody', timeString);
- var notification = webkitNotifications.createNotification(
- chrome.extension.getURL('/images/icon48.png'),
- chrome.i18n.getMessage('notificationTitle'),
- message);
- notification.show();
- setTimeout(function() {
- notification.cancel();
- }, 5000);
+ var options = {
+ type: 'basic',
+ title: chrome.i18n.getMessage('notificationTitle'),
+ message: message,
+ iconUrl: chrome.extension.getURL('/images/icon128.png'),
+ };
+
+ var id = 'clearhistory advance notify';
+ chrome.notifications.clear(id, function(wasCleared) {
+ chrome.notifications.create(id, options, function(){});
+ });
}
/**
var endTime = Date.now();
} else {
var endTime = time;
- time = 0;
+ startTime = 0;
}
var range = {
startTime: startTime,
function runCleaner() {
var keys = [
- 'cookies', 'downloads', 'time', 'timeStart',
+ 'cookies', 'downloads', 'time', 'timeStart', 'notify',
];
chrome.storage.sync.get(keys, function(s) {
if (s.cookies === CONSTANTS.YES) {
}
/**
- * Executes when the user clicks the browser action. Uses stored values from
- * {@code localStorage}
+ * Callback from other pages (like the popup).
*/
-chrome.browserAction.onClicked.addListener(function(tab) {
- // Get the value from localStorage
- chrome.storage.sync.get('prompt', function(s) {
- var showPrompt = s.prompt || CONSTANTS.YES;
-
- // The confirmation message to ask
- var message = chrome.i18n.getMessage('confirmPrompt');
-
- // Clear cookies, and then clear the history
- if (showPrompt === CONSTANTS.YES) {
- if (!confirm(message))
- return;
+chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
+ switch (request?.action) {
+ case 'runCleaner':
+ runCleaner();
+ break;
}
- runCleaner();
- });
});
chrome.alarms.get(CONSTANTS.CLEANER_ALARM, function(a) {