-
Notifications
You must be signed in to change notification settings - Fork 3
/
pdfHeaderRemover.js
41 lines (40 loc) · 1.38 KB
/
pdfHeaderRemover.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
// For Chrome we have to use "extraHeaders" to get all headers
let extraInfoSpec = ["responseHeaders", "blocking"];
if (
chrome.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty("EXTRA_HEADERS")
) {
}
// Register receiver for reponse headers
chrome.webRequest.onHeadersReceived.addListener(
(data) => {
var url = data.url;
var cont = false;
var cont2 = false;
for (var i = 0; i < data.responseHeaders.length; i++) {
var rH = data.responseHeaders[i];
if (rH.name.toLowerCase() == "content-disposition") {
cont = i + 1;
}
if (
rH.name.toLowerCase() == "content-type" &&
(rH.value == "application/pdf" || rH.value=="application/octet-stream")
) {
cont2 = i + 1;
}
}
if (cont && cont2) {
cont = cont - 1;
cont2=cont2-1;
data.responseHeaders[cont].value = data.responseHeaders[
cont
].value.replace("attachment", "inline");
data.responseHeaders[cont2].value="application/pdf";
return { responseHeaders: data.responseHeaders };
}
},
{
types: ["main_frame", "sub_frame", "other"],
urls: ['*://files-cdn.schoology.com/*', '*://resources.harker.org/download/*']
},
["responseHeaders", "blocking", "extraHeaders"]
);