@@ -11,15 +11,15 @@ const resultBlock = document.querySelector('.result');
1111codeOutput . textContent = codeInput . value ;
1212hljs . highlightElement ( codeOutput ) ;
1313
14- codeInput . addEventListener ( 'input' , ( event ) => {
14+ codeInput . addEventListener ( 'input' , ( ) => {
1515 codeOutput . removeAttribute ( 'data-highlighted' ) ;
1616 let val = codeInput . value ;
1717 if ( val [ val . length - 1 ] === "\n" ) val += ' ' ;
1818 codeOutput . textContent = val ;
1919 hljs . highlightElement ( codeOutput ) ;
2020} ) ;
2121
22- codeInput . addEventListener ( 'scroll' , ( event ) => {
22+ codeInput . addEventListener ( 'scroll' , ( ) => {
2323 codeOutput . scrollTop = codeInput . scrollTop ;
2424 codeOutput . scrollLeft = codeInput . scrollLeft ;
2525} ) ;
@@ -49,14 +49,27 @@ console.warn = function (...args) {
4949 resultBlock . innerHTML += `<div class="console warn">${ arg } </div>` ;
5050 } ) ;
5151}
52- runButton . addEventListener ( 'click' , ( event ) => {
52+ runButton . addEventListener ( 'click' , ( ) => {
5353 resultBlock . innerHTML = '' ;
5454 const code = codeInput . value ;
5555 try {
5656 Function ( code ) ( ) ;
5757 } catch ( e ) {
5858 console . error ( e ) ;
5959 }
60- } )
60+ } ) ;
6161
6262resizeObserver . observe ( codeInput ) ;
63+
64+ addEventListener ( "DOMContentLoaded" , ( event ) => {
65+ let hash = location . hash . slice ( 1 ) ;
66+ if ( hash ) {
67+ try {
68+ hash = decodeURIComponent ( hash ) ;
69+ } catch ( error ) {
70+ hash = hash . replace ( / % [ 0 - F ] { 2 } / ig, decodeURIComponent ) ;
71+ }
72+ codeInput . value = hash ;
73+ codeInput . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
74+ }
75+ } ) ;
0 commit comments