121121
122122
123123 # output , # output2
124- {white-space : pre; font-family : monospace;font-size : 16px }
124+ {font-family : monospace;font-size : 16px }
125125 # item , # item2
126126 {margin : 20px 0 ;border : 1px solid lightgray;padding : 10px ;overflow : auto}
127127 # src
128128 {}
129129 # values
130- {}
130+ {white-space : pre }
131131 # values .error
132132 {color : red}
133133
224224 var item2 ;
225225
226226
227+ var process = { } ;
228+
227229 //:
228230
229231
@@ -234,14 +236,15 @@ <h3>
234236 $ ( '#script .paste' ) . onclick = async e => { var txt = await navigator . clipboard . readText ( ) ; src . value = txt } ;
235237 $ ( '#script .copy' ) . onclick = e => navigator . clipboard . writeText ( src . value ) ;
236238
239+ src . onkeydown = e => e . key == 'Enter' && process . script ( src . value ) ;
240+ //src.value='https://cdn.jsdelivr.net/npm/markdown-it-container@4.0.0/+esm';
241+
237242 item = $ ( '#item' ) ;
238243 item . remove ( ) ;
239244
240- go . onclick = function ( ) {
245+ go . onclick = e => process . script ( src . value ) ;
246+ src . focus ( ) ;
241247
242- process ( src . value ) ;
243-
244- } //onclick
245248
246249
247250
253256
254257 go2 . onclick = function ( ) {
255258
256- process2 ( src2 . value ) ;
259+ process . import ( src2 . value ) ;
257260
258261 } //onclick
259262
@@ -265,12 +268,17 @@ <h3>
265268 //:
266269
267270
268- function process ( src ) {
271+ process . script = function ( src ) {
269272 console . log ( 'process.script' , src ) ;
270273
271- var nitem = item . cloneNode ( true ) ;
272- var $ = nitem . querySelector . bind ( nitem ) ;
274+ var nitem = item . cloneNode ( true ) ;
275+ var $ = nitem . querySelector . bind ( nitem ) ;
273276 $ ( '#url' ) . textContent = src ;
277+ var values = $ ( '#values' ) ;
278+ values . remove ( ) ;
279+ var nvalues ;
280+ var clone = ( ) => ( nvalues = values . cloneNode ( true ) , nitem . append ( nvalues ) ) ;
281+ output . append ( nitem ) ;
274282
275283 var iframe = document . createElement ( 'iframe' ) ;
276284 iframe . onload = onload ;
@@ -287,73 +295,81 @@ <h3>
287295
288296 var script = document . createElement ( 'script' ) ;
289297 script . src = src ;
298+ doc . head . appendChild ( script ) ;
290299
291300
292- win . onerror = err => {
301+ win . onerror = function ( err ) {
293302 console . log ( 'window.onerror' ) ;
303+ console . log ( arguments ) ;
294304 console . error ( err ) ;
295- $ ( '#values' ) . textContent = err . toString ( ) ;
296- $ ( '#values' ) . classList . add ( 'error' ) ;
305+ clone ( ) ;
306+ nvalues . textContent = err ;
307+ nvalues . classList . add ( 'error' ) ;
297308
298309 } //onerror
299310
300311
301- win . onunhandledrejection = e => {
312+ win . onunhandledrejection = function ( e ) {
302313 console . warn ( `UNHANDLED PROMISE REJECTION: ${ e . reason } ` ) ;
303- $ ( '#values' ) . textContent = e . reason ;
304- $ ( '#values' ) . classList . add ( 'error' ) ;
314+ console . log ( arguments ) ;
315+ clone ( ) ;
316+ nvalues . textContent = e . reason ;
317+ nvalues . classList . add ( 'error' ) ;
305318
306319 } //onunhandledrejection
307320
308321
309- script . onerror = err => {
322+ script . onerror = function ( err ) {
310323 console . log ( 'script.onerror' ) ;
324+ console . log ( arguments ) ;
311325 console . error ( err ) ;
312- $ ( '#values' ) . textContent = err . toString ( ) ;
313- $ ( '#values' ) . classList . add ( 'error' ) ;
326+ clone ( ) ;
327+ nvalues . textContent = err . toString ( ) ;
328+ nvalues . classList . add ( 'error' ) ;
314329
315330 } //onerror
316331
317332
318- script . onload = ( ) => {
333+ script . onload = function ( ) {
319334 console . log ( 'script.onload' ) ;
335+ console . log ( arguments ) ;
320336 var afterKeys = new Set ( Object . keys ( win ) ) ;
321337 var added = [ ...afterKeys ] . filter ( k => ! beforeKeys . has ( k ) ) ;
322338
323339 var str = '' ;
324340 added . forEach ( key => {
325341
342+ clone ( ) ;
343+
326344 var s = win [ key ] . toString ( ) ;
327345 var s1 = s . slice ( 0 , 80 ) ;
328346 if ( s . length > s1 . length ) {
329347 s1 += ` ... ( ${ s . length } )` ;
330348 }
331- str += `window.${ key } [ ${ typeof win [ key ] } ] : ${ s1 } ` + '\n' ;
332349
350+ var str = `window.${ key } [ ${ typeof win [ key ] } ] : ${ s1 } ` + '\n' ;
351+ nvalues . textContent = str ;
333352 console . log ( `window.${ key } =` , win [ key ] ) ;
334353
335354 } ) ;
336355
337- $ ( '#values' ) . textContent = str ;
356+ // $('#values').textContent = str;
338357
339- output . append ( nitem ) ;
340358
341359
342- console . log ( '🔍 New globals added by script :' , added ) ;
360+ console . log ( 'New globals :' , added ) ;
343361
344362
345363 } //onload
346364
347- doc . head . appendChild ( script ) ;
348-
349365 } //onload
350366
351367 } //process
352368
353369
354370
355371
356- async function process2 ( src ) {
372+ process . import = async function ( src ) {
357373
358374 var mod = await import ( src ) ;
359375 //console.log(inspect(mod));
0 commit comments