@@ -4,8 +4,6 @@ import {editor} from 'monaco-editor/esm/vs/editor/editor.api';
44
55import TSTLWorker = require( 'worker-loader!./tstlWorker' ) ;
66
7- import * as URL from "url-parse" ;
8-
97document . addEventListener ( 'DOMContentLoaded' , ( ) => {
108 const container = document . getElementById ( 'example-ts' ) ;
119 const exampleLua = document . getElementById ( 'example-lua' ) ;
@@ -31,9 +29,10 @@ document.addEventListener('DOMContentLoaded', () => {
3129 document.body.appendChild(button);
3230 ` ;
3331
34- let windowUrl = new URL ( window . location . href , window . location , true ) ;
35- if ( windowUrl . query . src ) {
36- example = decodeURIComponent ( windowUrl . query . src ) ;
32+ var queryStringSrcStart = window . location . hash . indexOf ( "#src=" ) ;
33+ if ( queryStringSrcStart == 0 ) {
34+ var encoded = window . location . hash . substring ( "#src=" . length ) ;
35+ example = decodeURIComponent ( encoded ) ;
3736 }
3837
3938 if ( container && exampleLua ) {
@@ -61,16 +60,25 @@ document.addEventListener('DOMContentLoaded', () => {
6160 tstlWorker . postMessage ( { tsStr : tsEditor . getValue ( ) } ) ;
6261
6362 let timerVar : any ;
63+ let ignoreHashChange = false ;
6464
6565 tsEditor . onDidChangeModelContent ( ( e => {
6666 clearInterval ( timerVar ) ;
6767 // wait one second before submitting work
6868 timerVar = setTimeout ( ( ) => {
6969 tstlWorker . postMessage ( { tsStr : tsEditor . getValue ( ) } ) ;
70- window . location . replace ( "?src=" + encodeURIComponent ( tsEditor . getValue ( ) ) ) ;
70+ window . location . hash = "#src=" + encodeURIComponent ( tsEditor . getValue ( ) ) ;
71+ ignoreHashChange = true ;
7172 } , 500 ) ;
7273 } ) )
7374
75+ window . onhashchange = ( ) => {
76+ if ( ignoreHashChange ) {
77+ ignoreHashChange = false ;
78+ return ;
79+ }
80+ }
81+
7482 tstlWorker . onmessage = ( event : MessageEvent ) => {
7583 luaEditor . setValue ( event . data . luaStr ) ;
7684 }
0 commit comments