(function () {
  var userInfo = new Promise(function (resolve, reject) {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "https://user.pds.gov.cn/api/User/T?parms=user/myInfo/")
    xhr.withCredentials = true
    xhr.send();
    xhr.onload = function () {
      if (XMLHttpRequest.DONE == xhr.readyState && (200 == xhr.status || 304 == xhr.status)) {
        if (xhr.response !== "未登录") {
          resolve(JSON.parse(xhr.response));
        }
      }
      reject(xhr.response)
    }
  });
  return userInfo;
})().then(function (data) {
    // var safeUrl=window.location.href.replace(/\%/g,"%25");
  var place = document.querySelector(".loginbox");
  var frag = document.createDocumentFragment();
  var link = document.createElement("a");
  link.textContent = data.DisplayName + "";
    link.target = "_blank";
  link.href = "https://user.pds.gov.cn/api/SUser/getLogin?siteId="+getSiteId();
//   link.href = "https://user.pds.gov.cn/userCenter/center.html";
  var quit = document.createElement("a");
  quit.textContent = "退出"
  quit.href = "https://user.pds.gov.cn/api/SUser/quit?backUrl="+window.location.href;
  var style = document.createElement("style");
  style.textContent = ".loginbox{display:inline-block;}";
  frag.appendChild(style);
  frag.appendChild(link);
  frag.appendChild(document.createTextNode(" | "));
  frag.appendChild(quit);
  place.innerHTML = "";
  place.appendChild(frag);
}).catch(function () {

  var frag = document.createDocumentFragment();
  var linkl = document.createElement("a");
  linkl.href = "https://user.pds.gov.cn/api/SUser/getLogin?siteId="+getSiteId()+"&backUrl="+window.location.href;;
  linkl.target = "_blank";
  linkl.textContent = "登录";
  linkr = document.createElement("a");
  linkr.textContent = "注册"
//   linkr.target = "_blank";
  linkr.href = "https://login.hnzwfw.gov.cn/tacs-uc/naturalMan/register?backUrl=http://user.pds.gov.cn/api/SUser/getLogin"+"&siteId="+getSiteId();
  linkr.className = "mr30";
  var style = document.createElement("style");
  style.textContent = ".loginbox{display:inline-block;}";
  frag.appendChild(style);
  frag.appendChild(linkl);
  frag.appendChild(document.createTextNode(" | "));
  frag.appendChild(linkr);
  var place = document.querySelector(".loginbox");
  place.innerHTML = "";
  place.appendChild(frag);
});