X-Git-Url: https://git.wh0rd.org/?p=chrome-ext%2Fclearhistory-advance-fork.git;a=blobdiff_plain;f=javascript%2Fclearhistory.js;h=7c9596f943ec287b28890ce8dd026176be9cb587;hp=b2d27149114ce6e33e9c1812334a3691c43bd94c;hb=6565d921d8384840180e5f61c09a6b51c2e2bc54;hpb=cc8be4269068a6dac17a2b163308152a0f6a3938 diff --git a/javascript/clearhistory.js b/javascript/clearhistory.js index b2d2714..7c9596f 100644 --- a/javascript/clearhistory.js +++ b/javascript/clearhistory.js @@ -90,6 +90,16 @@ function clearHistory() { } } +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} @@ -97,7 +107,6 @@ function clearHistory() { 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'); @@ -107,9 +116,18 @@ chrome.browserAction.onClicked.addListener(function(tab) { 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'); });