@@ -269,8 +269,9 @@ function base64urlToArrayBuffer(str) {
269269
270270async function updateHash ( ) {
271271 const source = inputEl . value ;
272+ const qs = location . search ;
272273 if ( ! source . trim ( ) ) {
273- history . replaceState ( null , '' , '/' ) ;
274+ history . replaceState ( null , '' , '/' + qs ) ;
274275 cmBtn . style . display = 'none' ;
275276 canShareUrl = false ;
276277 updateShareButton ( ) ;
@@ -280,13 +281,13 @@ async function updateHash() {
280281 const encoded = await compressToBase64url ( source ) ;
281282 const prefix = currentMode === 'embedded' ? '1' : '0' ;
282283 const fragment = `${ prefix } :${ encoded } ` ;
283- const url = `${ location . origin } /#${ fragment } ` ;
284+ const url = `${ location . origin } /${ qs } #${ fragment } ` ;
284285 if ( url . length > 2000 ) {
285- history . replaceState ( null , '' , '/' ) ;
286+ history . replaceState ( null , '' , '/' + qs ) ;
286287 cmBtn . style . display = 'none' ;
287288 canShareUrl = false ;
288289 } else {
289- history . replaceState ( null , '' , `/#${ fragment } ` ) ;
290+ history . replaceState ( null , '' , `/${ qs } #${ fragment } ` ) ;
290291 // cm CLI button only for cm mode (embedded not supported by /d/ endpoint)
291292 cmBtn . style . display = currentMode === 'cm' ? '' : 'none' ;
292293 canShareUrl = true ;
@@ -570,7 +571,7 @@ inputEl.addEventListener('input', () => {
570571 lastRawSource = '' ;
571572 showPreviewMode ( ) ;
572573 writeToPreview ( '' , 0 ) ;
573- history . replaceState ( null , '' , location . pathname ) ;
574+ history . replaceState ( null , '' , location . pathname + location . search ) ;
574575 cliHint . textContent = '' ;
575576 return ;
576577 }
@@ -582,11 +583,27 @@ inputEl.addEventListener('input', () => {
582583 } , DEBOUNCE_MS ) ;
583584} ) ;
584585
585- outputMode . addEventListener ( 'change' , ( ) => renderCurrent ( ) ) ;
586+ // Sync format/locale into URL query string without replacing path or hash.
587+ function syncQueryParams ( ) {
588+ const params = new URLSearchParams ( location . search ) ;
589+ const fmt = outputMode . value ;
590+ if ( fmt && fmt !== 'preview' ) { params . set ( 'format' , fmt ) ; } else { params . delete ( 'format' ) ; }
591+ const loc = localeSel . value ;
592+ if ( loc ) { params . set ( 'locale' , loc ) ; } else { params . delete ( 'locale' ) ; }
593+ const qs = params . toString ( ) ;
594+ const url = location . pathname + ( qs ? `?${ qs } ` : '' ) + location . hash ;
595+ history . replaceState ( null , '' , url ) ;
596+ }
597+
598+ outputMode . addEventListener ( 'change' , ( ) => {
599+ syncQueryParams ( ) ;
600+ renderCurrent ( ) ;
601+ } ) ;
586602
587603localeSel . addEventListener ( 'change' , ( ) => {
588604 lastRenderedSource = '' ;
589605 lastRawSource = '' ;
606+ syncQueryParams ( ) ;
590607 renderCurrent ( ) ;
591608} ) ;
592609
@@ -646,7 +663,7 @@ async function loadExample(name, ext) {
646663 lastRenderedMode = '' ;
647664 lastRawSource = '' ;
648665 renderCurrent ( ) ;
649- history . replaceState ( null , '' , `/x/${ name } ` ) ;
666+ history . replaceState ( null , '' , `/x/${ name } ${ location . search } ` ) ;
650667 cmBtn . style . display = 'none' ;
651668 cliHint . textContent = '' ;
652669 } catch {
@@ -668,6 +685,17 @@ examplesSel.addEventListener('change', async () => {
668685// ------------------------------------------------------------
669686
670687( async ( ) => {
688+ // Apply URL query parameters (?format=...&locale=...)
689+ const params = new URLSearchParams ( location . search ) ;
690+ const paramFormat = params . get ( 'format' ) ;
691+ const paramLocale = params . get ( 'locale' ) ;
692+ if ( paramFormat && outputMode . querySelector ( `option[value="${ paramFormat } "]` ) ) {
693+ outputMode . value = paramFormat ;
694+ }
695+ if ( paramLocale && localeSel . querySelector ( `option[value="${ paramLocale } "]` ) ) {
696+ localeSel . value = paramLocale ;
697+ }
698+
671699 const xMatch = location . pathname . match ( / ^ \/ x \/ ( .+ ) $ / ) ;
672700 if ( xMatch ) {
673701 await loadExample ( xMatch [ 1 ] ) ;
0 commit comments