diff --git a/etc/Settings.plist b/etc/Settings.plist index 64e724a..9e365fb 100644 --- a/etc/Settings.plist +++ b/etc/Settings.plist @@ -2,6 +2,16 @@ + + DefaultValue + + Key + unescape_unicode + Title + Unescape Unicode + Type + CheckBox + DefaultValue diff --git a/src/formattedJSON.js b/src/formattedJSON.js index bdda14e..4d90600 100644 --- a/src/formattedJSON.js +++ b/src/formattedJSON.js @@ -10,25 +10,28 @@ return; } - // attempt to parse the body as JSON - try { - var obj = JSON.parse( document.body.textContent - .split( "\\" ).join( "\\\\" ) // double-up on escape sequences - .split( '\\\"' ).join( "\\\\\"" ) // at this point quotes have been unescaped. re-escape them. - ); - } catch( e ) { - // invalid JSON :( - return; - } - - this.preparePage(); - // receive settings from proxy.html safari.self.addEventListener( "message", function( e ) { if( e.name === "setData" ) { var data = e.message; settings = data.settings; + // attempt to parse the body as JSON + try { + var s = document.body.textContent; + if ( settings.unescape_unicode ) { + s = JSON.stringify( JSON.parse( s ) ); + } + var obj = JSON.parse( s + .split( "\\" ).join( "\\\\" ) // double-up on escape sequences + .split( '\\\"' ).join( "\\\\\"" ) // at this point quotes have been unescaped. re-escape them. + ); + } catch( e ) { + // invalid JSON :( + return; + } + + formatJSON.preparePage(); formatJSON.addStyle( data.css ); formatJSON.addToolbar( data.toolbar ); formatJSON.renderRoot( obj ); diff --git a/src/proxy.html b/src/proxy.html index 5875835..1620137 100644 --- a/src/proxy.html +++ b/src/proxy.html @@ -10,6 +10,7 @@ settings: { fold_strings: safari.extension.settings.getItem( "fold_strings" ), long_string_length: safari.extension.settings.getItem( "long_string_length" ), + unescape_unicode: safari.extension.settings.getItem( "unescape_unicode" ), sort_keys: safari.extension.settings.getItem( "sort_keys" ) } } );