var buyLink = {
  pre: "https://www.diskpart.com", // 中转平台地址
  preJp: "https://partition.aomei.jp",
  current: {
    // 当前弹窗地址，用以前得购买地址
    demo: "upgrade-pro.html",
    pro: "upgrade-pro.html",
    ser: "upgrade-server.html",
    srv: "upgrade-server.html",
    tech: "upgrade-tech.html",
    unl: "upgrade-unlimited.html",
    unlimited: "upgrade-unlimited.html",
    creat: "upgrade-advanced-features.html"
  },
  ruCurrent: "https://www.aomeitech.com/ru/partners/pa-upgrade-for-syssoft.html"
};

var groupKeys = {
  toolbar: ["all", "data-safe"],
  register: ["all", "data-safe"],
  "1st-run": ["all", "data-safe"],
  "duplicate-files-finder": ["flexible", "efficient"],
  "pc-cleaner": ["free-up-space", "better-performance"],
  "app-mover": ["fast-safe", "complete"],
  "disk-speed-test": ["rapid", "comprehensive"],
  "create-portable-version": ["flexible2", "convenient"],
  "active-partition": ["fast", "no-data-loss"],
  "create-partition": ["fast", "no-data-loss6"],
  "shred-files": ["completely", "fast"],
  "delete-partition": ["fast", "repartition"],
  "fat32-to-ntfs": ["fast", "no-data-loss2"],
  "ntfs-fat32-converter": ["fast", "no-data-loss2"],
  "clone-partition": ["fast", "no-data-loss3"],
  "change-serial-number": ["no-format", "advanced"],
  "change-partition-type-id": ["fast", "safe2"],
  "change-drive-letter": ["fast", "safe3"],
  "change-partition-label": ["flexible3", "fast"],
  "initialize-disk": ["fast", "completely2"],
  "surface-test": ["fast", "deep-scan"],
  "check-partition": ["fast", "safe4"],
  "hide-partition": ["fast", "safe5"],
  "format-partition": ["flexible4", "fast"],
  "merge-partition": ["fast", "safe6"],
  "resize/move-partition": ["fast", "safe7"],
  "dynamic-volume-management": ["fast", "safe8"],
  "delete-wipe-data": ["permanently", "completely3"],
  "partition-alignment": ["fast", "safe15"],
  "convert-to-primary": ["fast", "safe9"],
  "convert-to-logical": ["fast", "safe9"],
  "wipe-partition": ["permanently3", "completely4"],
  "quick-partition": ["fast", "no-more-changing"],
  wintogo: ["flexible5", "boot-any-computer"],
  "allocate-free-space": ["fast", "safe10"],
  "convert-gpt-mbr": ["no-data-loss4", "safe"],
  "convert-mbr-gpt": ["no-data-loss4", "safe"],
  "migrate-os": ["fully-bootable", "no-reinstall"],
  "convert-dynamic-basic": ["fast", "no-data-loss2"],
  "extend-partition-wizard": ["fast2", "safe11"],
  "make-bootable-media": ["fast", "troubleshoot-easily"],
  "partition-recovery": ["successfully", "fast"],
  "rebuild-mbr": ["fast", "safe12"],
  "ssd-erase": ["reborn", "securely"],
  "disk-copy": ["fully-bootable2", "no-data-loss5"],
  "split-partition": ["fast", "safe13"],
  "wipe-disk": ["permanently2", "completely3"],
  "disk-defrag": ["intelligent", "powerful"],
  "delete-large-files": ["easily", "quickly"],
  "reset-windows-password": ["fast3", "safe14"],
  "recover-windows-data": ["unlimited", "high-recovery-rate"],
  "uefi-management": ["easy", "convenient2"],
  "bitlocker-encryption": ["trustworthy", "secure"],
  "boot-repair": ["easy2", "efficient2"],
  "1-click-adjust-space": ["easy3", "efficient3"], //新增
  "users-and-groups": ["fast4", "completely5"], //新增
  "virtual-disk": ["flexible6", "secure2"], //新增
  "change-cluster-size": [
    "reliable-change-cluster-size",
    "fast-change-cluster-size"
  ]
};

var fn = {
  fnIsOurCustomBrowser: function () {
    if (window.external.CB_IsOurCustomBrowser != null) {
      return true;
    } else {
      return false;
    }
  },
  //
  theParam: function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURIComponent(r[2]);
    return null;
  },

  // 获取点击标签中传递过来的参数
  getTag: function () {
    var currentTag = "";
    var _this = this;
    var currSource = _this.theParam("source");
    $.each(groupKeys, function (key) {
      if (key == currSource) {
        currentTag = key;
      } else if (
        currSource &&
        currSource.match &&
        currSource.match(/^delete-wipe-data/)
      ) {
        currentTag = "delete-wipe-data";
      } else if (
        currSource &&
        currSource.match &&
        currSource.match(/^wipe-partition/)
      ) {
        currentTag = "wipe-partition";
      } else if (
        currSource &&
        currSource.match &&
        currSource.match(/^(convert-system-gpt-mbr|convert-system-mbr-gpt)/)
      ) {
        currentTag = "convert-gpt-mbr";
      } else if (
        currSource &&
        currSource.match &&
        currSource.match(/^migrate-os/)
      ) {
        currentTag = "migrate-os";
      } else if (
        currSource &&
        currSource.match &&
        currSource.match(/^disk-copy/)
      ) {
        currentTag = "disk-copy";
      } else if (
        currSource &&
        currSource.match &&
        currSource.match(/^wipe-disk/)
      ) {
        currentTag = "wipe-disk";
      }
    });
    return currentTag || "toolbar";
  },

  // 获取语言参数
  getLang: function () {
    var langArry = ["en", "de", "fr", "it", "es", "tw", "jp", "ja", "ru"];

    var lang = this.theParam("lang");
    var found = false;

    for (var i = 0; i < langArry.length; i++) {
      if (langArry[i] === lang) {
        found = true;
        break;
      }
    }

    if (found) {
      lang === "ja" && (lang = "jp");
    } else {
      lang = "en";
    }

    return lang;
  },

  // 转化语言键值
  getKey: function (o, lang) {
    return o.hasOwnProperty(lang) ? lang : "en";
  },
  // 获取文件名字
  getFilename: function () {
    var pathname = window.location.pathname;
    var filename = pathname.substring(
      pathname.lastIndexOf("/") + 1,
      pathname.lastIndexOf(".html")
    );
    return filename;
  },
  getEdition: function () {
    var allProductName = ["pro", "srv", "tech", "unl", "demo"];
    var originalCurrent = this.theParam("edition")
      ? this.theParam("edition").split("_")[0]
      : "pro";
    var currentProductName = "pro"; // 默认值
    for (var i = 0; i < allProductName.length; i++) {
      if (allProductName[i] === originalCurrent) {
        currentProductName = originalCurrent;
        break;
      }
    }
    return currentProductName;
  },
  // 设置popurl
  setPopurl: function () {
    var popurlLang = fn.getLang().match(/jp|en/)
      ? "/"
      : "/" + fn.getLang() + "/";
    var tag = this.getTag();
    var buyLinkO = "";
    var edition = this.getEdition();
    if (tag === "create-portable-version") {
      buyLinkO = buyLink.current.creat;
    } else {
      buyLinkO = buyLink.current[edition];
    }
    var pre = fn.getLang() === "jp" ? buyLink.preJp : buyLink.pre;
    var popurl = pre + popurlLang + buyLinkO + window.location.search;

    // 俄语的popurl构造
    if (fn.getLang() === "ru") {
      popurl = buyLink.ruCurrent + window.location.search;
    }
    return "&popurl=" + encodeURIComponent(popurl);
  },
  // 给main-wrap添加类名
  dealClassName: function () {
    // 登录状态
    var status = this.theParam("LoginStatus") || "uloged"; // 登录状态
    var hasCloud = this.theParam("cloudSt") || "0"; // 是否已经是傲梅云用户
    status === "loging" || hasCloud === "1"
      ? $(".main-wrap").addClass("logging")
      : $(".main-wrap").removeClass("logging");

    // 文件名字
    var filename = "file-" + this.getFilename().replace("trial", "");
    $(".main-wrap").addClass(filename);
  },
  accordion: function () {
    $(".accordion li h6").click(function () {
      $(this).next().show().parents("li").addClass("active");
      $(this)
        .parent()
        .siblings()
        .find("p")
        .hide()
        .parents("li")
        .removeClass("active");
    });
  },
  // 勾选傲梅云产品
  selectCloudPrt: function (renderData) {
    var fileName = renderData.productName;
    var productList = renderData.productList;

    var isTimeout = $(".main-wrap").hasClass("timeout");
    // 倒计时过期要改变得产品信息
    if (isTimeout) {
      var changeInfo = renderData.timeout[fileName];
      $.each(productList, function (i, item) {
        changeInfo[i].discount &&
          (productList[i].discount = changeInfo[i].discount);
        productList[i].salePrice = changeInfo[i].salePrice;
        productList[i].btnLink = changeInfo[i].btnLink;
        productList[i].cloud = changeInfo[i].cloud;
      });
    }
    $(".prd-cloud").click(function (e) {
      e.stopPropagation();
      $(this).toggleClass("active");
      var $parent = $(this).parents(".prd-it");
      var Prdindex = $parent.index();
      var $discount = $parent.find(".ribbon");
      var $salePrice = $parent.find(".sale-price");
      var $totalPrice = $parent.find("del");
      var $btn = $parent.find(".btn");

      if ($(this).hasClass("active")) {
        // 有傲梅云产品时
        productList[Prdindex].cloud.discount &&
          $discount.html(productList[Prdindex].cloud.discount);
        $salePrice.html(productList[Prdindex].cloud.salePrice);
        productList[Prdindex].cloud.totalPrice &&
          $totalPrice.text(productList[Prdindex].cloud.totalPrice);
        var hashCloud = fn.theParam("LoginStatus") === "uloged" ? "#cloud" : "";
        $btn.attr(
          "data-href",
          fn.buildupBuyLink(productList[Prdindex].cloud.btnLink) + hashCloud
        );
      } else {
        productList[Prdindex].discount &&
          $discount.html(productList[Prdindex].discount);
        $salePrice.html(productList[Prdindex].salePrice);
        productList[Prdindex].totalPrice &&
          $totalPrice.text(productList[Prdindex].totalPrice);
        $btn.attr(
          "data-href",
          fn.buildupBuyLink(productList[Prdindex].btnLink)
        );
      }
      //   switch()
    });
  },
  // 辅助函数：将数字转换为两位数的字符串，添加前导零
  formatTwoDigits: function (num) {
    return num < 10 ? "0" + num : num;
  },
  endTime: function (inputDate) {
    if (!inputDate) {
      return 24;
    }
    var timestamp = new Date(parseInt(inputDate)).getTime();
    // var newTimestamp = timestamp + 24 * 60 * 60 * 1000;
    var newTimestamp = timestamp;
    var newDate = new Date(newTimestamp);

    // 格式化日期和时间部分为两位数
    var formattedDate =
      newDate.getFullYear() +
      "/" +
      this.formatTwoDigits(newDate.getMonth() + 1) +
      "/" +
      this.formatTwoDigits(newDate.getDate()) +
      " " +
      this.formatTwoDigits(newDate.getHours()) +
      ":" +
      this.formatTwoDigits(newDate.getMinutes()) +
      ":" +
      this.formatTwoDigits(newDate.getSeconds());

    return formattedDate;
  },
  getTimeLeft: function (time, unit) {
    var res = 0;
    switch (unit) {
      case "h":
        res = this.formatTwoDigits(Math.floor(time / 3600000));
        break;
      case "m":
        res = this.formatTwoDigits(Math.floor((time % 3600000) / 60000));
        break;
      case "s":
        res = this.formatTwoDigits(Math.floor((time % 60000) / 1000));
        break;
    }
    res = res.toString();
    return [res.slice(0, 1), res.slice(1, 2)];
  },
  countdown: function (renderData) {
    if (
      this.getEdition() === "demo" &&
      this.getTag() !== "create-portable-version"
    ) {
      return;
    }
    var cdt = this.theParam("cdt");
    var nowTime = new Date().getTime();
    var isMoreThan24h = cdt - nowTime > 24 * 60 * 60 * 1000;

    // 传入的倒计时小于当前时间，不开启倒计时
    if (!cdt || parseInt(cdt) <= nowTime || isMoreThan24h) {
      return true;
    }

    function timeout() {
      $(".main-wrap").addClass("timeout");

      // 倒计时结束改变产品价格
      var $productLists = $(".prd-it");
      var currentPrdList = renderData.timeout[renderData.productName];
      $productLists.each(function (i, item) {
        currentPrdList[i].discount
          ? $(item).find(".ribbon").html(currentPrdList[i].discount).show()
          : $(item).find(".ribbon").hide();
        currentPrdList[i].totalPrice
          ? $(item).find("del").text(currentPrdList[i].totalPrice).show()
          : $(item).find("del").hide();
        $(item).find(".sale-price").html(currentPrdList[i].salePrice);

        // 税
        $(item).find(".tax").length > 0 &&
          $(item).find(".tax").text(fn.toTaxPrice(currentPrdList[i].salePrice));
        fn.handleClick2();
      });
    }
    var timeLeft = cdt - nowTime;
    var timeLeftH = this.getTimeLeft(timeLeft, "h");
    var timeLeftM = this.getTimeLeft(timeLeft, "m");
    var timeLeftS = this.getTimeLeft(timeLeft, "s");
    var endStampName = renderData.productName + "-pa-sw";
    CookieUtil.unset(endStampName);
    var cd = new yCountdown({
      el: $("#ab-popup-countDown"),
      end: this.endTime(this.theParam("cdt")),
      loop: false,
      flag: true,
      hasDay: false,
      hasHour: true,
      hasMs: false,
      endStampName: endStampName,
      flagTxt: {
        d: "",
        h: "",
        min: "",
        s: "",
        ms: ""
      },
      template:
        '\n\t\t\t<div class="countdown" data-ycountdown="yCountdown">\n\t\t\t\t<div class="d">\n\t\t\t\t<div>\n\t\t\t\t\t\t<span data-ycountdown="daysTenth">0</span><span data-ycountdown="days">0</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t<p class="txt"></p>\n\t\t\t\t\t</div>\n\t\t\t\t' +
        '<i class="d">:</i>\n\t\t\t\t' +
        '<div class="h">\n\t\t\t\t<div>\n\t\t\t\t\t\t<span data-ycountdown="hrsTenth">' +
        timeLeftH[0] +
        '</span><span data-ycountdown="hrs">' +
        timeLeftH[1] +
        '</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t<p class="txt"></p>\n\t\t\t\t\t</div>\n\t\t\t\t' +
        '<i class="h-i">:</i>\n\t\t\t\t' +
        '<div class="min">\n\t\t\t\t<div>\n\t\t\t\t\t\t<span data-ycountdown="minsTenth">' +
        timeLeftM[0] +
        '</span><span data-ycountdown="mins">' +
        timeLeftM[1] +
        '</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t<p class="txt"></p>\n\t\t\t\t</div>\n\t\t\t\t' +
        "<i>:</i>\n\t\t\t\t" +
        '<div class="s">\n\t\t\t\t<div>\t\n\t\t\t\t\t\t<span data-ycountdown="secsTenth">' +
        timeLeftS[0] +
        '</span><span data-ycountdown="secs">' +
        timeLeftS[1] +
        '</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t<p class="txt"></p>\n\t\t\t\t\t</div>\n\t\t\t' +
        '<i class="ms"> : </i>' +
        '<div class="ms"><div><span data-ycountdown="msTenth">0</span><span data-ycountdown="ms">0</span><span data-ycountdown="ms">0</span></div>\n\t\t\t\t\t<p class="txt"></p>\n\t\t\t\t\t</div>\n\t\t\t' +
        "</div></div>\n\t\t\t",
      callback: timeout
    });
    cd.init();
  },
  tableEvent: function () {
    // 展开收起
    $(".target").click(function () {
      $(this)
        .parents("tr")
        .siblings()
        .find(".target")
        .removeClass("active")
        .find("p")
        .hide();
      $(this).addClass("active").find("p").stop().show();
    });
    // hover高亮
    $("tbody tr").hover(
      function () {
        $(this).addClass("hover");
      },
      function () {
        $(this).removeClass("hover");
      }
    );
  },
  // 操作
  elActions: function () {
    $("[el-action]").click(function () {
      var actionInitial = $(this).attr("el-action").split("-");
      var actionType = actionInitial[0];
      var action = actionInitial[1];
      var $target = $('[el-name="' + action + '"]');
      switch (actionType) {
        case "show":
          //   $target.slideDown();
          action !== "bsns"
            ? $target.show()
            : $target.animate({ right: 0 }, 300);
          break;
        case "hide":
          //   $target.slideUp();
          action !== "bsns"
            ? $target.hide()
            : $target.animate({ right: "-1000px" }, 300);
          break;
      }
    });
  },
  // 构造购买链接
  buildupBuyLink: function (original) {
    var searchPopurl = fn.setPopurl();
    var pre = this.getLang() === "jp" ? buyLink.preJp : buyLink.pre;
    var link =
      this.getLang() === "ru"
        ? buyLink.ruCurrent + "?" + searchPopurl.slice(1)
        : pre + "/cart?" + original + searchPopurl;
    return link;
    //   return pre + "/cart?" + original + searchPopurl;
  },
  // 渲染模版
  renderHtml: function () {
    var theTag = this.getTag();
    var theLang = this.getLang();
    if (theLang === "ja") {
      theLang = "jp";
    }
    // var theKey = this.getKey(obj, theLang);
    //   var renderData = obj;
    //   var renderData = JSON.parse(JSON.stringify(this.proYearIncrease(obj)));
    var renderData = this.deepClone(this.proYearIncrease(obj));
    renderData.lang = theLang;
    $(document.body).addClass(theLang + " " + theTag.replace("/", "-"));
    var edition = this.getEdition();
    // 产品名字
    if (
      this.getTag() === "create-portable-version" &&
      /^pro|srv|demo/.test(edition)
    ) {
      renderData.productName = "unlimited";
    } else {
      renderData.productName = edition;
    }
    // renderData.productName =
    //   this.getTag() === "create-portable-version" ? "unlimited" : edition;
    switch (renderData.productName) {
      case "srv":
        renderData.productList = renderData.srv;
        break;
      case "tech":
        renderData.productList = renderData.tech;
        $(".prd-ls").addClass("prd-ls2");
        break;
      case "unl":
        renderData.productList = renderData.unl;
        $(".prd-ls").addClass("prd-ls2");
        break;
      case "unlimited":
        renderData.productList = renderData.unlimited;
        break;
      case "demo":
        renderData.productList = renderData.demo;
        break;
    }
    /**
     * topTxt的文案处理
     * source参数为克隆或者磁盘擦除部分试用过期
     */
    switch (theTag) {
      case "create-portable-version":
        renderData.topTxt = /^pro|srv|demo/.test(edition)
          ? renderData.topTxtAll["create-portable-version1"]
          : renderData.topTxtAll["create-portable-version2"];
        $.each(groupKeys[theTag], function (i, it) {
          renderData.topTxt.list.push(source.cnt[it]);
        });
        $("body").addClass("create-portable");
        break;
      case "toolbar":
      case "register":
      case "1st-run":
        renderData.topTxt = renderData.topTxtAll.common;
        $.each(groupKeys[theTag], function (i, it) {
          renderData.topTxt.list.push(source.cnt[it]);
        });
        break;
      default:
        renderData.topTxt = renderData.topTxtAll.feature;
        if (theTag === "boot-repair" || theTag === "1-click-adjust-space") {
          renderData.topTxt.des = renderData.topTxtAll.feature.des2;
        }

        $.each(groupKeys, function (key, item) {
          if (key === theTag) {
            $.each(item, function (i, it) {
              renderData.topTxt.list.push(source.cnt[it]);
            });
          }
          renderData.topTxt.title = renderData.topTxtAll.feature.title.replace(
            "${feature}",
            source.featureTitle[theTag]
          );
        });
        break;
    }

    renderData.lang = theLang; // 语言
    renderData.buyLinkPre =
      fn.getLang() === "jp" ? buyLink.preJp + "/cart?" : buyLink.pre + "/cart?";
    renderData.popurl = fn.setPopurl();

    // 过期时间产品价格 为了避免已经过期，进入页面有从倒计时前价格变到倒计时后得一个价格
    var cdt = this.theParam("cdt"); // 传入的倒计时
    var nowTime = new Date().getTime();
    var isMoreThan24h = cdt - nowTime > 24 * 60 * 60 * 1000;
    if (!cdt || parseInt(cdt) <= nowTime || isMoreThan24h) {
      $(".main-wrap").addClass("timeout"); // 倒计时插件bug
      var changeInfo = renderData.timeout[renderData.productName];
      $.each(renderData.productList, function (i, item) {
        renderData.productList[i].discount = changeInfo[i].discount
          ? changeInfo[i].discount
          : "";
        renderData.productList[i].totalPrice = changeInfo[i].totalPrice
          ? changeInfo[i].totalPrice
          : "";
        renderData.productList[i].salePrice = changeInfo[i].salePrice;
        renderData.productList[i].btnLink = changeInfo[i].btnLink;
        renderData.productList[i].cloud = changeInfo[i].cloud;
      });
    }
    $("#myTmpl").tmpl(renderData).appendTo(".main-wrap");
    this.countdown(renderData);
  },
  clickProduct: function () {
    $(".prd-it").click(function () {
      var $this = $(this);
      $(".prd-it").removeClass("active");
      $this.addClass("active");
      var btnLink = $this.find(".price").attr("btn-link");
      $this
        .parents('[class*="prd-ty"]')
        .find(".btn-org")
        .attr("data-href", btnLink);
    });
  },
  handleClick2: function () {
    $(".prd-ls").each(function (i, item) {
      $(item).find(".prd-it").eq(1).trigger("click");
    });
  },
  goLicenceCode: function () {
    $('[data-go="licenceCode"]').click(function () {
      if (fn.fnIsOurCustomBrowser()) {
        window.external.CB_OpenURL("enter licence code");
      } else {
        chrome.webview.postMessage("enter licence code");
      }
    });
  },
  toTaxPrice: function (price) {
    function formatNumberWithCommas(number) {
      return parseInt(number)
        .toString()
        .replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }

    // 先去除字符串中的逗号，并替换小数点为点号
    var cleanedPrice = price
      .replace(/,/g, "")
      .replace("円", "")
      .replace("．", ".")
      .match(/\d+/)[0];
    // 将字符串转换为数字
    var formattedPrice = parseFloat(cleanedPrice) * 1.1;

    formattedPrice = "（税込" + formatNumberWithCommas(formattedPrice) + "円）";

    return formattedPrice;
  },
  // 获取链接里的产品参数
  extractPkNumbers: function (url) {
    var urlObj = document.createElement("a");
    urlObj.href = url;
    var searchParams = urlObj.search.substring(1);
    var pkNumbers = "";
    // 将参数字符串分解为键值对数组
    var paramsArray = searchParams.split("&");

    for (var i = 0; i < paramsArray.length; i++) {
      var param = paramsArray[i].split("=");
      var key = decodeURIComponent(param[0]);
      var value = param.length > 1 ? decodeURIComponent(param[1]) : "";

      var match = key.match(/pk\[(\d+)\]/);
      if (match) {
        pkNumbers = match[1];
      }
    }

    return pkNumbers;
  },
  // 是否参加更换购买平台测试
  isReplacePlatform: function (url) {
    var productId = this.extractPkNumbers(url);
    var isProductId = /230|397|398|232|233|596/.test(productId);
    var isLang = fn.getLang() === "de";
    // var isSource = /register|install-complete|install/.test(this.theParam("source")); // install这个参数不知道有没有，需求给的就添加上了
    if (isProductId || isLang) {
      // 不参加更换购买平台因素
      return false;
    } else {
      return true;
    }
  },
  // 更换购买平台
  replaceBuyPlatform: function (url) {
    //   return url; // 暂时不上线下面需求
    //   var productId = this.extractPkNumbers(url);
    //   var buyPlatform = window.localStorage[productId];
    //   if (!buyPlatform) {
    //     buyPlatform = Math.random() < 0.5 ? "n" : "o";
    //     window.localStorage.setItem(productId, buyPlatform);
    //   }
    //   buyPlatform === "n" && (url = url.replace("ep=cb", "ep=vf").replace("ep=si&an=1", "ep=vf"));
    //   return url;

    // var xid = fn.theParam("xid");
    // var qid = xid ? xid.split("!")[1] : "";
    if (this.isReplacePlatform(url)) {
      url = url.replace("ep=cb", "ep=vf").replace("ep=si&an=1", "ep=vf");
    }
    return url;
  },
  proYearIncrease: function (data) {
    // object.assign兼容低版本浏览器
    if (typeof Object.assign !== "function") {
      Object.assign = function (target) {
        if (target == null) {
          throw new TypeError("Cannot convert undefined or null to object");
        }

        target = Object(target);
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];
          if (source != null) {
            for (var key in source) {
              if (Object.prototype.hasOwnProperty.call(source, key)) {
                target[key] = source[key];
              }
            }
          }
        }
        return target;
      };
    }
    // object.assign兼容低版本浏览器
    var xid = fn.theParam("xid");
    // var qid = xid ? xid.split("!")[1] : "";
    if (/de|fr|it/.test(this.getLang())) {
      Object.assign(data.demo[0], data.demo[0].other);
      Object.assign(data.timeout.demo[0], data.timeout.demo[0].other);
      Object.assign(data.timeout.pro[0], data.timeout.pro[0].other);
      Object.assign(data.timeout.pro[0], data.timeout.pro[0].other);
    }

    return data;
  },
  // 深拷贝
  deepClone: function (obj) {
    // 如果是 null 或非对象类型，直接返回
    if (obj === null || typeof obj !== "object") {
      return obj;
    }

    var clone;

    // 检查对象的类型
    if (obj instanceof Array) {
      // 如果是数组，初始化一个新数组
      clone = [];
      for (var i = 0; i < obj.length; i++) {
        clone[i] = this.deepClone(obj[i]); // 递归深拷贝每个元素
      }
    } else {
      // 如果是对象，初始化一个新对象
      clone = {};
      for (var key in obj) {
        if (obj.hasOwnProperty(key)) {
          clone[key] = this.deepClone(obj[key]); // 递归深拷贝每个属性
        }
      }
    }

    return clone;
  }
};
$(function () {
  function init() {
    fn.dealClassName();
    fn.renderHtml();
    fn.accordion();
    fn.clickProduct();
    //   fn.selectCloudPrt();
    //   fn.countdown();
    fn.tableEvent();
    fn.elActions();
    fn.handleClick2();
    fn.goLicenceCode();
    $(".btn-org").click(function () {
      // var btnLink =
      // !fn.isReplacePlatform($(this).attr("data-href"))
      //     ? $(this).attr("data-href")
      //     : fn.replaceBuyPlatform($(this).attr("data-href"));
      var btnLink = fn.replaceBuyPlatform($(this).attr("data-href"));
      var hash = "#" + $(this).attr("data-num");
      if (fn.fnIsOurCustomBrowser()) {
        window.external.CB_OpenURL(btnLink + hash);
      } else {
        chrome.webview.postMessage("openurl:" + btnLink + hash);
      }
    });
    $(".close").click(function () {
      if (fn.fnIsOurCustomBrowser()) {
        window.external.CB_OpenURL("close");
      } else {
        chrome.webview.postMessage("close");
      }
    });
  }

  // 引入对应js
  var scriptElement = document.createElement("script");
  scriptElement.type = "text/javascript";
  scriptElement.src = "scripts/demo" + "/" + fn.getLang() + ".js";

  // 兼容低版本浏览器
  if (scriptElement.readyState) {
    // 仅适用于IE
    scriptElement.onreadystatechange = function () {
      if (
        scriptElement.readyState === "loaded" ||
        scriptElement.readyState === "complete"
      ) {
        scriptElement.onreadystatechange = null;
        // 脚本加载完成后的操作
        init();
      }
    };
  } else {
    // 其他浏览器
    scriptElement.onload = function () {
      // 脚本加载完成后的操作
      init();
    };
  }
  //   window.localStorage.clear();
  document.getElementsByTagName("head")[0].appendChild(scriptElement);
});
