var buyLink = {
  preJp: "https://partition.aomei.jp",
  pre: "https://www.diskpart.com", // 中转平台地址
  current: "upgrade-now.html", // 当前弹窗地址，用以前得购买地址
  current2: "upgrade-advanced-features.html",
  ruCurrent: "https://www.aomeitech.com/ru/partners/pa-upgrade-for-syssoft.html"
};
var groupkeys = {
  toolbar: ["toolbar", "convert-to-mrb-gpt-disk", "app-mover"],
  register: ["register", "convert-to-mrb-gpt-disk", "app-mover"],
  "1st-run": ["1st-run", "convert-to-mrb-gpt-disk", "app-mover"],
  "duplicate-files-finder": [
    "duplicate-files-finder",
    "app-mover",
    "delete-large-files"
  ],
  "uefi-management": ["uefi-management", "make-bootable-media", "wintogo"],
  "recover-windows-data": [
    "recover-windows-data",
    "partition-recovery",
    "wipe-disk"
  ],
  "reset-windows-password": [
    "reset-windows-password",
    "disk-copy",
    "make-bootable-media"
  ],
  "delete-large-files": [
    "delete-large-files",
    "app-mover",
    "duplicate-files-finder"
  ],
  "delete-wipe-data": ["delete-wipe-data", "wipe-disk", "shred-files"],
  "wipe-partition": ["wipe-partition", "wipe-disk", "shred-files"],
  "convert-to-primary": [
    "convert-to-primary",
    "convert-to-logical",
    "convert-mbr-gpt"
  ],
  "convert-to-logical": [
    "convert-to-logical",
    "convert-to-primary",
    "convert-mbr-gpt"
  ],
  "quick-partition": ["quick-partition", "convert-mbr-gpt", "split-partition"],
  "partition-alignment": [
    "partition-alignment",
    "migrate-os",
    "allocate-free-space"
  ],
  "dynamic-volume-management": [
    "dynamic-volume-management",
    "convert-dynamic-basic",
    "convert-mbr-gpt"
  ],
  "allocate-free-space": [
    "allocate-free-space",
    "extend-partition-wizard",
    "app-mover"
  ],
  "wipe-disk": ["wipe-disk", "wipe-partition", "shred-files"],
  wintogo: ["wintogo", "migrate-os", "make-bootable-media"],
  "ssd-erase": ["ssd-erase", "partition-alignment", "disk-speed-test"],
  "split-partition": [
    "split-partition",
    "convert-mbr-gpt",
    "allocate-free-space"
  ],
  "rebuild-mbr": ["rebuild-mbr", "partition-recovery", "make-bootable-media"],
  "partition-recovery": [
    "partition-recovery",
    "recover-windows-data",
    "wipe-partition"
  ],
  "make-bootable-media": ["make-bootable-media", "wintogo", "uefi-management"],
  "extend-partition-wizard": [
    "extend-partition-wizard",
    "allocate-free-space",
    "split-partition"
  ],
  "disk-copy": ["disk-copy", "migrate-os", "convert-mbr-gpt"],
  "convert-dynamic-basic": [
    "convert-dynamic-basic",
    "dynamic-volume-management",
    "convert-mbr-gpt"
  ],
  "migrate-os": ["migrate-os", "disk-copy", "convert-mbr-gpt"],
  "convert-mbr-gpt": [
    "convert-mbr-gpt",
    "convert-gpt-mbr",
    "convert-dynamic-basic"
  ],
  "convert-gpt-mbr": [
    "convert-gpt-mbr",
    "convert-mbr-gpt",
    "convert-to-primary"
  ],
  "app-mover": ["app-mover", "extend-partition-wizard", "allocate-free-space"],
  "schedule-defrag": [
    "schedule-defrag",
    "partition-alignment",
    "disk-speed-test"
  ],
  "disk-speed-test": ["disk-speed-test", "migrate-os", "schedule-defrag"],
  "create-portable-version": [
    "create-portable-version",
    "unlimited-usage",
    "provide-service"
  ],
  "shred-files": ["shred-files", "wipe-disk", "recover-windows-data"],
  "bitlocker-encryption": [
    "bitlocker-encryption",
    "wipe-partition",
    "shred-files"
  ],
  "boot-repair": ["boot-repair", "recover-windows-data", "make-bootable-media"],
  "1-click-adjust-space": ["1-click-adjust-space", "app-mover", "migrate-os"],
  "users-and-groups": [
    "users-and-groups",
    "toolbar",
    "convert-to-mrb-gpt-disk"
  ],
  "change-cluster-size": [
    "change-cluster-size",
    "partition-alignment",
    "allocate-free-space"
  ]
};

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;
    $.each(groupkeys, function (key) {
      if (key == _this.theParam("source")) {
        currentTag = key;
      } else if (/^disk-copy/.test(_this.theParam("source"))) {
        currentTag = "disk-copy";
      } else if (/^migrate-os/.test(_this.theParam("source"))) {
        currentTag = "migrate-os";
      } else if (/^delete-wipe-data/.test(_this.theParam("source"))) {
        currentTag = "delete-wipe-data";
      } else if (/^wipe-partition/.test(_this.theParam("source"))) {
        currentTag = "wipe-partition";
      } else if (/^wipe-disk/.test(_this.theParam("source"))) {
        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";
  },
  accordion: function () {
    // 普通
    $(".accordion li h6").click(function () {
      $(this).next().show().parents("li").addClass("active");
      $(this)
        .parent()
        .siblings()
        .find("p")
        .hide()
        .parents("li")
        .removeClass("active");
    });

    // 表格
  },
  // 获取文件名字
  getFilename: function () {
    var pathname = window.location.pathname;
    var filename = pathname.substring(
      pathname.lastIndexOf("/") + 1,
      pathname.lastIndexOf(".html")
    );
    return filename;
  },
  getEdition: function () {
    var allProductName = ["std"];
    var originalCurrent = this.theParam("edition")
      ? this.theParam("edition").split("_")[1]
      : "";
    var currentProductName = ""; // 默认值
    for (var i = 0; i < allProductName.length; i++) {
      if (allProductName[i] === originalCurrent) {
        currentProductName = originalCurrent;
        break;
      }
    }
    return currentProductName;
  },
  setPopurl: function () {
    var popurlLang = fn.getLang().match(/jp|en/)
      ? "/"
      : "/" + fn.getLang() + "/";
    var trackPage =
      this.getTag() === "create-portable-version"
        ? buyLink.current2
        : buyLink.current;
    var pre = fn.getLang() === "jp" ? buyLink.preJp : buyLink.pre;
    var popurl = pre + popurlLang + trackPage + window.location.search;
    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");
  },
  // 辅助函数：将数字转换为两位数的字符串，添加前导零
  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;
    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)];
  },
  changeDomInfo: function ($items, info) {
    $items.each(function (i, item) {
      info[i].discount
        ? $(item).find(".ribbon").html(info[i].discount).show()
        : $(item).find(".ribbon").hide();
      info[i].totalPrice
        ? $(item).find("del").text(info[i].totalPrice).show()
        : $(item).find("del").hide();
      $(item).find(".sale-price").html(info[i].salePrice);
      $(item)
        .find(".btn")
        .attr("data-href", fn.buildupBuyLink(info[i].btnLink));
    });
  },
  countdown: function (renderData) {
    var _this = this;
    var cdt = this.theParam("cdt");
    var nowTime = new Date().getTime();
    var isMoreThan24h = cdt - nowTime > 24 * 60 * 60 * 1000;
    // 传入的倒计时小于当前时间，不开启倒计时
    if (!cdt || parseInt(cdt) <= nowTime || isMoreThan24h) {
      timeout();
      return true;
    }

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

      // 倒计时结束改变产品价格
      var $proProductLists = $('[el-name="pro"] .prd-it');
      var $bsnsProductLists = $('[el-name="bsns"] .prd-it');
      _this.getEdition() === "std" &&
      !/create-portable-version/.test(_this.getTag())
        ? _this.changeDomInfo($proProductLists, renderData.timeout["proNoDis"])
        : _this.changeDomInfo($proProductLists, renderData.timeout["pro"]);
      _this.changeDomInfo($bsnsProductLists, renderData.timeout["bsns"]);
      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 = "std-pa-sw";
    CookieUtil.unset(endStampName);
    var cd = new yCountdown({
      el: $("#ab-popup-countDown"),
      end: _this.endTime(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
    });
    var cd2 = new yCountdown({
      el: $("#ab-popup-countDown1"),
      end: this.endTime(this.theParam("cdt")),
      //   end: 24,
      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
    });
    cd2.init();
    cd.init();
  },
  tableEvent: function () {
    // 展开收起
    $(".target").click(function () {
      $(this)
        .parents("tr")
        .siblings()
        .find(".target")
        .removeClass("active")
        .find("p")
        .hide();
      // .stop()
      // .slideUp(100);
      $(this).addClass("active").find("p").show();
      //   .stop().slideDown();
    });
    // 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 + '"]');
      if (actionType === "show") {
        switch (action) {
          case "bsns":
            // $target.animate({ right: 0 }, 300);
            $target.animate(
              {
                top: 0
              },
              300
            );
            break;
          case "fetrs":
            $target.animate(
              {
                top: 0
              },
              300
            );
            break;
        }
      } else {
        switch (action) {
          case "bsns":
            // $target.animate({ right: "-1000px" }, 300);
            $target.animate(
              {
                top: "-800px"
              },
              300
            );
            break;
          case "fetrs":
            $target.animate(
              {
                top: "-800px"
              },
              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;
  },
  // 渲染模版
  renderHtml: function () {
    var theTag = this.getTag();
    var theLang = this.getLang();
    if (theLang === "ja") {
      theLang = "jp";
    }

    // 根据source参数修改pro edition上方文案
    // var theKey = this.getKey(obj, theLang);

    // var renderData = obj;
    // var renderData = this.proYearIncrease(obj);
    var renderData = this.deepClone(this.proYearIncrease(obj));
    renderData.lang = theLang;
    $("body").addClass(theLang);
    $("body").addClass(theTag);
    renderData.pro.list = [];
    $.each(groupkeys, function (key, item) {
      if (key === theTag) {
        $.each(item, function (i, it) {
          renderData.pro.list.push(source.cnt[it]);
        });
      }
    });

    if (/toolbar|register|1st-run|create-portable-version/.test(theTag)) {
      renderData.pro.title = renderData.pro.list[0].title;
      if (theTag === "create-portable-version") {
        renderData.pro.productList = renderData.unlimited;
        renderData.timeout.pro = renderData.timeout.unlimited;
        $("body").addClass("create-portable");
      }
    } else {
      renderData.pro.title = renderData.pro.title.replace(
        "${tt}",
        renderData.pro.list[0].title
      );
    }

    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 ||
      this.getEdition() === "std"
    ) {
      $(".main-wrap").addClass("timeout"); // 倒计时插件bug
      //   renderData.timeout.proNoDis用于没有折扣得pro
      var proTimeout =
        this.getEdition() === "std"
          ? renderData.timeout.proNoDis
          : renderData.timeout.pro;
      var bsnsTimeout = renderData.timeout.bsns;
      //  pro修改产品信息
      $.each(renderData.pro.productList, function (i, item) {
        renderData.pro.productList[i].discount = proTimeout[i].discount
          ? proTimeout[i].discount
          : "";
        renderData.pro.productList[i].totalPrice = proTimeout[i].totalPrice
          ? proTimeout[i].totalPrice
          : "";
        renderData.pro.productList[i].salePrice = proTimeout[i].salePrice;
        renderData.pro.productList[i].btnLink = proTimeout[i].btnLink;
      });

      //  bsns修改产品信息
      $.each(renderData.bsns.productList, function (i, item) {
        renderData.bsns.productList[i].discount = bsnsTimeout[i].discount
          ? bsnsTimeout[i].discount
          : "";
        renderData.bsns.productList[i].totalPrice = bsnsTimeout[i].totalPrice
          ? bsnsTimeout[i].totalPrice
          : "";
        renderData.bsns.productList[i].salePrice = bsnsTimeout[i].salePrice;
        renderData.bsns.productList[i].btnLink = bsnsTimeout[i].btnLink;
      });
    }

    // source=install-complete:首次弹出
    // this.theParam("source") === "install-complete";
    if (
      /toolbar|register|1st-run|install-complete/.test(this.theParam("source"))
    ) {
      renderData.fetrs.title = source.cnt.toolbar.title;
    }
    $("#myTmpl").tmpl(renderData).appendTo(".main-wrap");
    this.countdown(renderData);
  },
  clickProduct: function () {
    $(".prd-it").click(function () {
      var $this = $(this);
      $this.parents(".prd-ls").find(".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 pkNumbers = "";
    var queryString = url.split("?")[1]; // 获取查询字符串部分

    if (queryString) {
      var params = queryString.split("&"); // 分割查询字符串成键值对数组

      for (var i = 0; i < params.length; i++) {
        var param = params[i].split("="); // 分割每个键值对
        var key = param[0];
        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/.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) {
    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.pro.productList[0], data.pro.productList[0].other);
      Object.assign(data.timeout.pro[0], data.timeout.pro[0].other);
      Object.assign(data.timeout.proNoDis[0], data.timeout.proNoDis[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 () {
  // 引入对应js
  var scriptElement = document.createElement("script");
  scriptElement.type = "text/javascript";
  scriptElement.src = "scripts/std" + "/" + fn.getLang() + ".js";

  function init() {
    fn.dealClassName();
    fn.renderHtml();
    // 登录状态
    fn.accordion();
    fn.clickProduct();
    fn.tableEvent();
    fn.elActions();
    fn.handleClick2();
    fn.goLicenceCode();

    $(".btn-org").click(function () {
      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");
      }
    });
  }
  // 兼容低版本浏览器
  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);
});
