-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.html
71 lines (58 loc) · 1.89 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html>
<script>
var zoom_of_tabs = {};
var redirected_requests = {};
chrome.experimental.webNavigation.onCommitted.addListener(
function(details) {
chrome.tabs.sendRequest(details.tabId, {}, function(response) {
if (response.zoom_level){
zoom_of_tabs[details.tabId]=response.zoom_level;
}
});
});
function onMediaRequestCompleted(details) {
alert(details.statusCode)
if (redirected_requests[details.requestId]) {
if (details.statusCode = 500) {
var correctedURL = details.url.replace(new RegExp("/[0-9]+px-"), "/" + new_resolution + "px-");
details.url
}
delete redirected_requests[details.requestId];
}
};
function onMediaRequestFailed(details) {
delete redirected_requests[details.requestId];
};
chrome.experimental.webRequest.onCompleted.addListener(
onMediaRequestCompleted
,
{urls:["http://upload.wikimedia.org/wikipedia/commons/*"]}
);
chrome.experimental.webRequest.onErrorOccurred.addListener(
onMediaRequestFailed
,
{urls:["http://upload.wikimedia.org/wikipedia/commons/*"]}
);
chrome.experimental.webRequest.onBeforeRequest.addListener(
function(details) {
if (!redirected_requests[details.requestId]) {
if (details.type=="image") {
var matches = details.url.match("/[0-9]+px-");
if (matches != null) {
var cached_zoom_level=zoom_of_tabs[details.tabId]
var zoom_level=cached_zoom_level?cached_zoom_level:1;
var resolution = Number(matches[0].match("[0-9]+"));
var new_resolution = Math.round(resolution*zoom_level);
var correctedURL = details.url.replace(new RegExp("/[0-9]+px-"), "/" + new_resolution + "px-");
redirected_requests[details.requestId] = "true";
return {redirectUrl:correctedURL};
}
};
}
}
,
{urls:["http://upload.wikimedia.org/wikipedia/commons/*"]
},["blocking"]
);
</script>
</html>