-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
51 lines (44 loc) · 1.8 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(function() {
var chromeCachingEnabled = false;
var clearExistingCache = false;
var notifyUser = false;
var clearCache = (function() {
if (!clearExistingCache) {
if (typeof(chrome.browsingData) !== 'undefined') {
clearExistingCache = true;
var millisecondsPerWeek = 1000 * 60 * 60 * 24 * 7;
var oneWeekAgo = (new Date()).getTime() - millisecondsPerWeek;
//Chrome 19:
chrome.browsingData.removeCache({
"since": oneWeekAgo
}, function() {
clearExistingCache = false;
});
} else if (!notifyUser) {
notifyUser = true;
alert("Your browser does not supported");
}
}
});
var disableChromeCaching = (function() {
chrome.browserAction.setIcon({path:"icon-on.png"});
chrome.browserAction.setTitle({title:"No Cache enabled"});
chromeCachingEnabled = false;
chrome.webRequest.onBeforeRequest.addListener(clearCache, {urls: ["<all_urls>"]});
});
var enableChromeCaching = (function() {
chrome.browserAction.setIcon({path:"icon-off.png"});
chrome.browserAction.setTitle({title:"No Cache disabled"});
chromeCachingEnabled = true;
chrome.webRequest.onBeforeRequest.removeListener(clearCache);
});
var extentionStatus = (function() {
chromeCachingEnabled ? disableChromeCaching() : enableChromeCaching();
});
chrome.browserAction.onClicked.addListener(extentionStatus);
if (localStorage && localStorage["NoCacheOnDefault"] && localStorage["NoCacheOnDefault"] === "on") {
disableChromeCaching();
} else {
enableChromeCaching();
}
})();