(function (w, d, s) {
  function go() {
    var js,
      fjs = d.getElementsByTagName(s)[0],
      load = function (url, id, cb) {
        if (d.getElementById(id)) {
          return;
        }
        js = d.createElement(s);
        js.src = url;
        js.id = id;
        fjs.parentNode.insertBefore(js, fjs);

        // if callback, execute the callback.
        if (typeof cb === "function") {
          js.onload = cb.call(this, id);
          // For IE
          js.onreadystatechange = function (id) {
            if (
              this.readyState === "complete" ||
              this.readyState === "loaded"
            ) {
              cb.call(this, id);
            }
          };
        }
      };
    load(window.userbugreport.ubr_script, "ubrsdk", id => {
      var checkExist = setInterval(function () {
        if (window.showBugButton) {
          clearInterval(checkExist);
          window.showBugButton(window.userbugreport);
        }
      }, 100); // check every 100msv
    });
  }
  if (w.addEventListener) {
    w.addEventListener("load", go);
  } else if (w.attachEvent) {
    w.attachEvent("onload", go);
  }
})(window, document, "script");
