let JSONP_INDEX = 1 ; declare const window ; param url param callbackName export async function jsonp ( url , callbackName = 'callback' ) { return new Promise ( ( resolve , reject ) => { JSONP_INDEX += 1 ; const funcName = 'jsonp_' + Date . now ( ) . toString ( 36 ) + '_' + JSONP_INDEX ; if ( /^\/\// . test ( url ) ) { url = window . location . protocol + url ; } const urlObject = new URL ( url ) ; urlObject . searchParams . set ( callbackName , funcName ) ; const script = document . createElement ( 'script' ) ; script . src = urlObject . href ; document . body . appendChild ( script ) ; script . onerror = ( error ) => { reject ( error ) ; } ; window [ funcName ] = ( result ) => { resolve ( result ) ; delete window [ funcName ] ; script . remove ( ) ; } ; } ) ; }