const importScript = function (path, success, error) {
  let isLoaded = false
  let scriptElements = document.getElementsByTagName('script')
  for(let i in scriptElements){
    if(scriptElements[i].src === path){
      isLoaded = true
    }
  }
  if(isLoaded === false){
    let oS = document.createElement('script')
    oS.src = path
    document.getElementsByTagName('head')[0].appendChild(oS)
    oS.onload = function () {
      success && success()
    }

    oS.onerror = function () {
      error && error()
    }
  }
}

export default importScript