Skip to content

Instantly share code, notes, and snippets.

@skopp
Created March 31, 2013 19:25
Show Gist options
  • Save skopp/5281690 to your computer and use it in GitHub Desktop.
Save skopp/5281690 to your computer and use it in GitHub Desktop.

#Clear for Google Chrome

Clear is a simple Google Chrome Extension to easily clear you browsing data.

Clear on Chrome WebStore.

image

NOTE: Clear uses browsingData and contextMenu APIs, so you need to add the permissions in your manifest file.

//create the menu itens
chrome.contextMenus.create({
"title": "Cache: Last Hour",
"onclick": function () {
clear("Cache", 1000 * 60 * 60)
}
});
chrome.contextMenus.create({
"title": "Cache: Last Day",
"onclick": function () {
clear("Cache", 1000 * 60 * 60 * 24)
}
});
chrome.contextMenus.create({
"title": "Cache: Last Week",
"onclick": function () {
clear("Cache", 1000 * 60 * 60 * 24 * 7)
}
});
chrome.contextMenus.create({
"title": "Cache: All Time",
"onclick": function () {
clear("Cache", 0)
}
});
chrome.contextMenus.create({
"type": "separator"
});
chrome.contextMenus.create({
"title": "History: Last Hour",
"onclick": function () {
clear("History", 1000 * 60 * 60)
}
});
chrome.contextMenus.create({
"title": "History: Last Day",
"onclick": function () {
clear("History", 1000 * 60 * 60 * 24)
}
});
chrome.contextMenus.create({
"title": "History: Last Week",
"onclick": function () {
clear("History", 1000 * 60 * 60 * 24 * 7)
}
});
chrome.contextMenus.create({
"title": "History: All Time",
"onclick": function () {
clear("History", 0)
}
});
chrome.contextMenus.create({
"type": "separator"
});
chrome.contextMenus.create({
"title": "Cookies: Last Hour",
"onclick": function () {
clear("Cookies", 1000 * 60 * 60)
}
});
chrome.contextMenus.create({
"title": "Cookies: Last Day",
"onclick": function () {
clear("Cookies", 1000 * 60 * 60 * 24)
}
});
chrome.contextMenus.create({
"title": "Cookies: Last Week",
"onclick": function () {
clear("Cookies", 1000 * 60 * 60 * 24 * 7)
}
});
chrome.contextMenus.create({
"title": "Cookies: All Time",
"onclick": function () {
clear("Cookies", 0)
}
});
//clear function
function clear(what, time) { //function to clear the cache
var date;
if (time === 0) { //if time is 0 then is to clear all
date = 0;
} else { //else calculate since
var date = (new Date()).getTime() - time;
}
switch (what) { //
case "Cache":
chrome.browsingData.removeCache({
"since": date
});
break;
case "Cookies":
chrome.browsingData.removeCookies({
"since": date
});
break;
case "History":
chrome.browsingData.removeHistory({
"since": date
});
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment