/* eslint-disable */
(function () {
  // pc和h5域名映射关系
  const domainMap = {
    "develop.cguardian.com": "mdevelop.cguardian.com",
    "alldevelop.cguardian.com": "malldevelop.cguardian.com",
    "test.cguardian.com": "mtest.cguardian.com",
    "www.cguardian.com": "m.cguardian.com",
  };
  // 判断是否移动端浏览器
  function judgeDeviceIsMobile() {
    const u = navigator.userAgent;
    const ios = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
    const android = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1;
    return ios || android;
  }
  const domain = location.hostname;
  // 仅处理
  if (domainMap[domain]) {
    // http 替换成https
    let href = location.href.replace(/^http:/, "https:");
    // 是移动环境
    if (judgeDeviceIsMobile()) {
      href = href.replace(domain, domainMap[domain]);
    }
    // url 被 调整过
    if (href !== location.href) {
      // 使用replace, 不增加history路由记录
      location.replace(href);
    }
  }
})();
