-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
560 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
*.xpi | ||
.tern-port | ||
/build | ||
/main.js | ||
/node_modules | ||
|
This file was deleted.
Oops, something went wrong.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
const jsonRequestIds = new Set<string>(); | ||
|
||
interface RequestDetails { | ||
requestId: string, | ||
url: string, | ||
method: string, | ||
frameId: number, | ||
parentFrameId: number, | ||
tabId: number, | ||
type: browser.webRequest.ResourceType, | ||
timeStamp: number, | ||
originUrl: string, | ||
statusLine: string, | ||
responseHeaders?: browser.webRequest.HttpHeaders, | ||
statusCode: number, | ||
} | ||
|
||
function listener(details: RequestDetails) { | ||
console.log("JSONView listener", details); | ||
if (!jsonRequestIds.has(details.requestId)) { | ||
console.log("JSONView this isn't JSON"); | ||
return; | ||
} | ||
|
||
const requestId = details.requestId; | ||
const filter = browser.webRequest.filterResponseData(details.requestId); | ||
|
||
// TODO: figure out encoding I guess | ||
const enc = new TextDecoder("utf-8"); | ||
let content = ""; | ||
|
||
function disconnect() { | ||
console.log("JSONView disconnect filter"); | ||
filter.disconnect(); | ||
jsonRequestIds.delete(requestId); | ||
} | ||
|
||
filter.onstart = (event: Event) => { | ||
console.log("JSONView started", event, details); | ||
|
||
if (jsonRequestIds.has(requestId)) { | ||
console.log("JSONView YEAH start"); | ||
} else { | ||
disconnect(); | ||
} | ||
}; | ||
|
||
filter.ondata = (event: Event & { | ||
data: ArrayBuffer | ||
}) => { | ||
console.log(event.data, event); | ||
filter.write(event.data); | ||
if (jsonRequestIds.has(requestId)) { | ||
console.log("JSONView YEAH data"); | ||
} | ||
content = content + enc.decode(event.data); | ||
}; | ||
|
||
filter.onstop = (event: Event) => { | ||
console.log("JSONView finished", event, details); | ||
console.log("CONTENT", content); | ||
disconnect(); | ||
}; | ||
} | ||
|
||
function detectJSON(event: RequestDetails) { | ||
console.log("JSONView headers", event); | ||
if (!event.responseHeaders) { | ||
return; | ||
} | ||
for (const header of event.responseHeaders) { | ||
if (header.name === "Content-Type" && header.value && header.value.includes("application/json")) { | ||
console.log("JSONView found some JSON!"); | ||
jsonRequestIds.add(event.requestId); | ||
listener(event); | ||
} | ||
} | ||
|
||
return { responseHeaders: event.responseHeaders }; | ||
} | ||
|
||
// Listen for onHeaderReceived for the target page. | ||
// Set "blocking" and "responseHeaders". | ||
browser.webRequest.onHeadersReceived.addListener( | ||
detectJSON, | ||
{ urls: ["https://jsonview.com/*"], types: ["main_frame"] }, | ||
["blocking", "responseHeaders"] | ||
); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "JSONView", | ||
"version": "2.0.0", | ||
"description": "View JSON documents in the browser.", | ||
"author": "Benjamin Hollis", | ||
"homepage_url": "https://jsonview.com/", | ||
"icons": { | ||
"32": "icon.png", | ||
"64": "icon64.png", | ||
"256": "icon256.png" | ||
}, | ||
"background": { | ||
"scripts": ["lib/main.js"] | ||
}, | ||
"permissions": [ | ||
"<all_urls>", | ||
"webRequest", | ||
"webRequestBlocking" | ||
], | ||
"applications": { | ||
"gecko": { | ||
"id": "[email protected]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,17 @@ | ||
{ | ||
"id": "[email protected]", | ||
"version": "1.2.4", | ||
"version": "2.0.0", | ||
"name": "jsonview", | ||
"title": "JSONView", | ||
"description": "View JSON documents in the browser.", | ||
"homepage": "https://jsonview.com/", | ||
"author": "Benjamin Hollis", | ||
"repository": "https://github.com/bhollis/jsonview", | ||
"license": "MIT", | ||
"main": "lib/main.js", | ||
"permissions": { | ||
"multiprocess": true | ||
"scripts": { | ||
"start": "tsc && rollup build/main.js --format iife --name 'main' --file main.js", | ||
"lint": "tslint -p tsconfig.json" | ||
}, | ||
"preferences": [ | ||
{ | ||
"name": "jsonHttpAccept", | ||
"type": "bool", | ||
"value": false, | ||
"title": "Include \"application/json\" in the HTTP Accept header for requests", | ||
"description": "Only enable this if you need it - this can cause problems with some websites." | ||
}, | ||
{ | ||
"name": "alternateContentTypes", | ||
"type": "string", | ||
"value": "", | ||
"title": "Alternate JSON content types", | ||
"description": "Other content types that should be treated as JSON, separated by commas." | ||
}, | ||
{ | ||
"name": "useNativeJsonView", | ||
"type": "bool", | ||
"value": false, | ||
"title": "Use built-in Firefox JSON viewer", | ||
"description": "Firefox now includes a built-in JSON viewer you can use instead of JSONView." | ||
} | ||
], | ||
"contributors": [ | ||
"Gabriel Barros", | ||
"Quoc-Viet Nguyen" | ||
|
@@ -122,5 +99,12 @@ | |
"zh-CN": { | ||
"description": "在浏览器中查看JSON 文件." | ||
} | ||
}, | ||
"devDependencies": { | ||
"rollup": "^0.58.2", | ||
"tslint": "^5.10.0", | ||
"tslint-eslint-rules": "^5.1.0", | ||
"typescript": "^2.8.3", | ||
"web-ext-types": "^2.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./build/", | ||
"sourceMap": true, | ||
"strictNullChecks": true, | ||
"noImplicitAny": true, | ||
"module": "ESNext", | ||
"target": "es6", | ||
"moduleResolution": "node", | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"allowJs": true, | ||
"checkJs": true, | ||
"typeRoots": ["node_modules/@types", "node_modules/web-ext-types"] | ||
}, | ||
"include": [ | ||
"./lib/main.*" | ||
] | ||
} |
Oops, something went wrong.