MikeCoder /
MJsonViewer
| 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 | 'use strict'; |
||
| 28 | |||
| 29 | const findJsonMimeType = function(header) { |
||
| 30 | if (header.name === undefined) { |
||
| 31 | return false; |
||
| 32 | } |
||
| 33 | return header.name.toLowerCase() === 'content-type' && header.value.includes('json'); |
||
| 34 | }; |
||
| 35 | |||
| 36 | const addJsonHandler = function(request) { |
||
| 37 | return new Promise((resolve) => { |
||
| 38 | if (request.responseHeaders.find(findJsonMimeType)) { |
||
| 39 | const jsonHeader = { |
||
| 40 | name: 'Content-Type', |
||
| 41 | value: 'application/json' |
||
| 42 | }; |
||
| 43 | request.responseHeaders.push(jsonHeader); |
||
| 44 | } |
||
| 45 | |||
| 46 | resolve({ |
||
| 47 | responseHeaders: request.responseHeaders |
||
| 48 | }); |
||
| 49 | }); |
||
| 50 | }; |
||
| 51 | |||
| 52 | browser.webRequest.onHeadersReceived.addListener( |
||
|
0 ignored issues
–
show
|
|||
| 53 | addJsonHandler, { |
||
| 54 | urls: ['<all_urls>'] |
||
| 55 | }, [ |
||
| 56 | 'blocking', |
||
| 57 | 'responseHeaders' |
||
| 58 | ] |
||
| 59 | ); |
||
| 60 |
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.