export default function remoteLoad ( url , isCallback ) { const win = window ; const file = { createScript : null , removeScript : null } ; file . createScript = ( url2 ) => { const scriptElement = win . document . createElement ( 'script' ) ; win . document . body . appendChild ( scriptElement ) ; const promise = new Promise ( ( resolve , reject ) => { scriptElement . addEventListener ( 'load' , ( e ) => { file . removeScript ( scriptElement ) ; if ( ! isCallback ) { resolve ( e ) ; } } , false ) ; scriptElement . addEventListener ( 'error' , ( e ) => { file . removeScript ( scriptElement ) ; reject ( e ) ; } , false ) ; if ( isCallback ) { win . callback = ( result ) => { resolve ( result ) ; win . callback = null ; } ; } } ) ; if ( isCallback ) { url2 += ! url2 . includes ( '?' ) ? '?' : '&' ; url2 += 'callback=callback' ; } scriptElement . src = url2 ; return promise ; } ; file . removeScript = ( scriptElement ) => { win . document . body . removeChild ( scriptElement ) ; } ; return file . createScript ( url ) ; }