File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
extension/src/json-viewer Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 11var extractJSON = require ( './extract-json' ) ;
2+ var bodyModified = false ;
23
34function allTextNodes ( nodes ) {
45 return ! Object . keys ( nodes ) . some ( function ( key ) {
@@ -39,12 +40,21 @@ function getPreWithSource() {
3940 pre . textContent = textContent ;
4041 document . body . removeChild ( childNode ) ;
4142 document . body . appendChild ( pre ) ;
43+ bodyModified = true ;
4244 return pre ;
4345 }
4446
4547 return null
4648}
4749
50+ function restoreNonJSONBody ( ) {
51+ var artificialPre = document . body . lastChild ;
52+ var removedChildNode = document . createElement ( "text" ) ;
53+ removedChildNode . textContent = artificialPre . textContent ;
54+ document . body . insertBefore ( removedChildNode , document . body . firstChild ) ;
55+ document . body . removeChild ( artificialPre ) ;
56+ }
57+
4858function isJSON ( jsonStr ) {
4959 var str = jsonStr ;
5060 if ( ! str || str . length === 0 ) {
@@ -69,6 +79,8 @@ function checkIfJson(sucessCallback, element) {
6979 ( isJSON ( pre . textContent ) || isJSONP ( pre . textContent ) ) ) {
7080
7181 sucessCallback ( pre ) ;
82+ } else if ( bodyModified ) {
83+ restoreNonJSONBody ( ) ;
7284 }
7385}
7486
You can’t perform that action at this time.
0 commit comments