@@ -40,9 +40,8 @@ SOFTWARE.
4040 isToolbarOpen = false ,
4141 options = Object . assign ( { } , globalThis . sharedData . defaultOptions ) ,
4242 bucket = "JSON_FORMATTER_OPTIONS" ,
43- wordWrap = false ;
44-
45- let IS_PREPARE_SCRIPT_RUN = false ;
43+ wordWrap = false ,
44+ IS_PREPARE_SCRIPT_RUN = false ;
4645
4746 if ( document . readyState === "complete" && ! IS_PREPARE_SCRIPT_RUN ) {
4847 _ ( ) ;
@@ -72,7 +71,7 @@ SOFTWARE.
7271 }
7372 else {
7473 // legacy support
75- if ( ! data [ bucket ] . hasOwnProperty ( "themes" ) || ! data [ bucket ] . hasOwnProperty ( "colorScheme" ) || ! data [ bucket ] . hasOwnProperty ( "wordWrap" ) || ! data [ bucket ] . hasOwnProperty ( "sortingOrder" ) ) {
74+ if ( ! data [ bucket ] . hasOwnProperty ( "themes" ) || ! data [ bucket ] . hasOwnProperty ( "colorScheme" ) || ! data [ bucket ] . hasOwnProperty ( "wordWrap" ) || ! data [ bucket ] . hasOwnProperty ( "sortingOrder" ) || ! data [ bucket ] . hasOwnProperty ( "rawUnicodeEscapes" ) ) {
7675 // still has old data format, update it to new format
7776 let newDataFormat = Object . assign ( { } , globalThis . sharedData . defaultOptions ) ;
7877 if ( data [ bucket ] . themeMode == "auto" ) {
@@ -86,7 +85,14 @@ SOFTWARE.
8685 newDataFormat . colorScheme = "light" ;
8786 }
8887 }
89- newDataFormat . tab = data [ bucket ] . defaultTab ;
88+ if ( data [ bucket ] . defaultTab ) {
89+ newDataFormat . tab = data [ bucket ] . defaultTab ;
90+ }
91+ delete data [ bucket ] . themeMode ;
92+ delete data [ bucket ] . currentTheme ;
93+ delete data [ bucket ] . defaultTab ;
94+
95+ newDataFormat = { ...newDataFormat , ...data [ bucket ] } ;
9096
9197 Object . assign ( options , newDataFormat ) ;
9298 await chrome . storage . local . set ( { [ bucket ] : newDataFormat } ) ;
@@ -167,7 +173,10 @@ SOFTWARE.
167173 sortingFuncton = normalize ( ) ;
168174 }
169175 formattedRawCode . innerHTML =
170- JSON . stringify ( JSON . parse ( code . replace ( / \\ u / g, "\u" ) ) , sortingFuncton , 2 ) ;
176+ JSON . stringify ( JSON . parse (
177+ options . rawUnicodeEscapes === true ?
178+ code . replace ( / \\ u / g, "\u" ) : code
179+ ) , sortingFuncton , 2 ) ;
171180
172181 globalThis . code = code ;
173182
@@ -177,18 +186,26 @@ SOFTWARE.
177186 leadingLine . style = 'margin-left: 0px; height: 18px;' ;
178187 formattedRawCode . appendChild ( leadingLine ) ;
179188
180- rawCode . innerHTML = JSON . stringify ( JSON . parse ( code . replace ( / \\ u / g, "\u" ) ) , sortingFuncton ) ;
189+ rawCode . innerHTML = JSON . stringify ( JSON . parse (
190+ options . rawUnicodeEscapes === true ?
191+ code . replace ( / \\ u / g, "\u" ) : code
192+ ) , sortingFuncton ) ;
181193
182194 let leadingLine1 = document . createElement ( 'div' ) ;
183195 leadingLine1 . className = 'line emptyLine' ;
184196 leadingLine1 . textContent = '' ;
185197 leadingLine1 . style = 'margin-left: 0px; height: 18px;' ;
186198 rawCode . appendChild ( leadingLine1 ) ;
187-
188- tree = createTree ( JSON . parse ( code
189- . replace ( / \\ / g, "\\\\" )
190- . replace ( / \\ \\ \" / g, "\\\\\\\"" ) ,
191- sortingFuncton ) ) ;
199+ tree = createTree (
200+ JSON . parse (
201+ code
202+ . replace ( / \\ / g, "\\\\" )
203+ . replace ( / \\ \\ \" / g, "\\\\\\\"" )
204+ . replace ( / \\ \\ u / g,
205+ options . rawUnicodeEscapes === true ? "\\\\u" : "\\u"
206+ ) ,
207+ sortingFuncton )
208+ ) ;
192209 var thme = isDark ? "dark" : "light" ;
193210 var renderedCode = render ( tree , parsedCode , { theme : thme , string : true } ) ;
194211 expandChildren ( tree ) ;
0 commit comments