|
1
|
|
|
////////////////////////////////////////////////////////////////////////////////////// |
|
2
|
|
|
// Copyright © 2017 TangDongxin |
|
3
|
|
|
// |
|
4
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining |
|
5
|
|
|
// a copy of this software and associated documentation files (the "Software"), |
|
6
|
|
|
// to deal in the Software without restriction, including without limitation |
|
7
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
8
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the |
|
9
|
|
|
// Software is furnished to do so, subject to the following conditions: |
|
10
|
|
|
// |
|
11
|
|
|
// The above copyright notice and this permission notice shall be included |
|
12
|
|
|
// in all copies or substantial portions of the Software. |
|
13
|
|
|
// |
|
14
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
15
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
16
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
17
|
|
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
18
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
19
|
|
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
|
20
|
|
|
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
21
|
|
|
////////////////////////////////////////////////////////////////////////////////////// |
|
22
|
|
|
|
|
23
|
|
|
// =========================================== |
|
24
|
|
|
// JSON HEADER REWRITE |
|
25
|
|
|
// =========================================== |
|
26
|
|
|
|
|
27
|
|
|
function findJsonMimeType(header) { |
|
28
|
|
|
if (header.name === undefined) { |
|
29
|
|
|
return false; |
|
30
|
|
|
} |
|
31
|
|
|
return header.name.toLowerCase() === 'content-type' && header.value.includes('json'); |
|
32
|
|
|
}; |
|
33
|
|
|
|
|
34
|
|
|
function addJsonHandler(request) { |
|
35
|
|
|
return new Promise((resolve) => { |
|
36
|
|
|
if (request.responseHeaders.find(findJsonMimeType)) { |
|
37
|
|
|
const jsonHeader = { |
|
38
|
|
|
name: 'Content-Type', |
|
39
|
|
|
value: 'application/json' |
|
40
|
|
|
}; |
|
41
|
|
|
request.responseHeaders.push(jsonHeader); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
resolve({ |
|
45
|
|
|
responseHeaders: request.responseHeaders |
|
46
|
|
|
}); |
|
47
|
|
|
}); |
|
48
|
|
|
}; |
|
49
|
|
|
|
|
50
|
|
|
browser.webRequest.onHeadersReceived.addListener( |
|
|
|
|
|
|
51
|
|
|
addJsonHandler, { |
|
52
|
|
|
urls: ['<all_urls>'] |
|
53
|
|
|
}, [ |
|
54
|
|
|
'blocking', |
|
55
|
|
|
'responseHeaders' |
|
56
|
|
|
] |
|
57
|
|
|
); |
|
58
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.