forked from litejs/json-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
39 lines (34 loc) · 1.06 KB
/
content.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
/*!
* Copyright (c) 2016-2018 Lauri Rooden
* https://www.litejs.com/MIT-LICENSE.txt
*/
!function() {
var str, jsonpMatch, add
, chrome = this.chrome || this.browser
, jsonRe = /^\s*(?:\[\s*(?=-?\d|true|false|null|["[{])[^]*\]|\{\s*"[^]+\})\s*$/
, body = document.body
, first = body && body.firstChild
if (
first && (
// pure json put inside PRE by browser
first.tagName === "PRE" ||
// HTML page contains only one textNode
first === body.lastChild && first.nodeType === 3
) && (str = first.textContent) && (
/\bjson\b/i.test(document.contentType) ||
(jsonpMatch = /^\s*((?:\/\*\*\/\s*)?([$a-z_][$\w]*)\s*(?:&&\s*\2\s*)?\()([^]+)(\)[\s;]*)$/i.exec(str)) && jsonRe.test(jsonpMatch[3]) ||
jsonRe.test(str)
)
) {
body.style.display = "none"
if (jsonpMatch) {
body.textContent = jsonpMatch[3]
add = [jsonpMatch[1], jsonpMatch[4]]
}
chrome.runtime.sendMessage({op: "formatBody", len: body.textContent.length, add: add}, function(response) {
if (!response || response.op === "abort") {
body.style.display = ""
}
})
}
}()