-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.html
49 lines (44 loc) · 2.02 KB
/
background.html
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
<html>
<head>
<script>
//----------------------------------------------------------------------
// ForceReload extension for Google Chrome
// Fix for bug http://code.google.com/p/chromium/issues/detail?id=8742
//----------------------------------------------------------------------
// Author: Tim Meadowcroft -- http://schmerg.com -- 2011
//----------------------------------------------------------------------
var megaReloadTab = function(tab){
var currUrl = tab.url, currIndex = tab.index, currId = tab.id;
// if we make the new tab with the same URL (ie pass the url to the create call)
// then we seem to get the same cache issues, but if we let the tab make itself
// first and THEN go to the URL, it seems better....
// We make a new empty tab before removing the old one so that, if this is the
// only tab open, we don't close the browser itself :)
chrome.tabs.create({ index: currIndex},
function(newtab) {
chrome.tabs.remove(currId, function() {
chrome.tabs.update(newtab.id, { url: currUrl });
console.log("Made new tab for "+currUrl);
});
});
};
// On click of our toolbar button, reload the current tab
chrome.browserAction.onClicked.addListener(function() {
console.log("Chrome-Force-Reload triggered by browser button");
chrome.tabs.getSelected(undefined, megaReloadTab);
});
// We've also inserted a small key listener into each page - reload any page
// where it intercepts the hard refresh call
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
var interceptCtrlF5 = Boolean(localStorage["interceptCtrlF5"]);
if (request.rtype && request.rtype == "refresh" &&
sender.tab &&
(request.ctrl && interceptCtrlF5)) {
console.log("Chrome-Force-Reload triggered by content page");
megaReloadTab(sender.tab);
}
});
console.log("Background.html for Chrome-Force-Reload loaded");
</script>
</head>
</html>