let translate_icon_1 = chrome["runtime"]["getURL"]("logo/translation_1.png"),
  translate_icon_2 = chrome["runtime"]["getURL"]("logo/translation_2.png"),
  is_translate_enabled = ![],
  is_translate_message_used = ![];
const ps_translate_0a = {};
ps_translate_0a["type"] = "language";
let languageNames = new Intl["DisplayNames"](["en"], ps_translate_0a),
  currentLanguage = "en",
  last_day_since_translate_used = "",
  count_of_days_translate_used = 0x0;
(function initVars() {
  const F = {};
  (F["nXDjW"] = "default"),
    (F["RcCdX"] = "currentLanguage"),
    (F["RxTku"] = "isTranslateMessageUsed"),
    (F["dCemF"] = "lastDaySinceTranslateMessageUsed"),
    (F["rKvfp"] = "countOfDaysTranslateMessageUsed");
  const m = F;
  chrome["storage"]["local"]["get"](
    [m["RcCdX"], m["RxTku"], m["dCemF"], m["rKvfp"]],
    (j) => {
      (currentLanguage = j["currentLanguage"] || m["nXDjW"]),
        (is_translate_message_used = j["isTranslateMessageUsed"] || ![]),
        (last_day_since_translate_used =
          j["lastDaySinceTranslateMessageUsed"] || ""),
        (count_of_days_translate_used =
          j["countOfDaysTranslateMessageUsed"] || 0x0);
    }
  );
})(),
  chrome["runtime"]["onMessage"]["addListener"]((F, m, j) => {
    const P = {};
    P["TvlNi"] = "translate_language";
    const x = P;
    if (F["type"] === x["TvlNi"]) currentLanguage = F["language"];
  });
function replace_HTML_tags(F) {
  const m = {};
  m["pOEQG"] = "div";
  const j = m;
  let P = F;
  Object["keys"](REPLACEMENT_HTML_TAGS)["forEach"]((V) => {
    let i = REPLACEMENT_HTML_TAGS[V];
    P = P["replaceAll"](i["replacement_regex"], i["replacement_pattern"]);
  });
  let x = document["createElement"](j["pOEQG"]);
  return (x["innerHTML"] = P), (P = x["innerText"]), P;
}
function replace_back_HTML_tags(a, F) {
  let m = a;
  return (
    Object["keys"](REPLACEMENT_HTML_TAGS)["forEach"]((j) => {
      let P = REPLACEMENT_HTML_TAGS[j];
      if (P["replaceback_regex"])
        m = m["replaceAll"](P["replaceback_regex"], P["replaceback_pattern"]);
      else {
        let x = F["match"](P["replacement_regex"]);
        x &&
          x["forEach"]((V) => (m = m["replace"](P["replacement_pattern"], V))),
          (m = m["replaceAll"](P["replacement_pattern"], ""));
      }
    }),
    m
  );
}
function is_valid_translation(F, m, j, P) {
  const x = {};
  (x["mCvTC"] = function (M, O) {
    return M || O;
  }),
    (x["lSiwX"] = function (M, O) {
      return M == O;
    }),
    (x["KrkQm"] = function (M, O) {
      return M === O;
    });
  const V = x;
  if (V["mCvTC"](!F, !P)) return ![];
  if (F === m || V["lSiwX"](j, P)) return ![];
  let i = j["replace"](/[^a-zA-Z]/g, "")["toLowerCase"](),
    X = P["replace"](/[^a-zA-Z]/g, "")["toLowerCase"]();
  if (V["KrkQm"](i, X)) return ![];
  return !![];
}
async function translate_message_HTML(a, F) {
  const m = {
    jtTam: function (x, V, i) {
      return x(V, i);
    },
    CqWWD: function (x, V) {
      return x(V);
    },
    rPixS: function (V, i) {
      return V === i;
    },
    TXZen: function (x, V) {
      return x(V);
    },
  };
  if (
    m["rPixS"](a, undefined) ||
    m["rPixS"](a, null) ||
    m["rPixS"](a["trim"]()["length"], 0x0)
  )
    return "";
  let j = m["CqWWD"](replace_HTML_tags, a);
  const P =
    "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=" +
    F +
    "&dt=t&q=" +
    m["TXZen"](encodeURI, j);
  return await new Promise((x) => {
    const V = {
      bPwbx: function (i, X, M) {
        return m["jtTam"](i, X, M);
      },
      yfFzf: function (i, X) {
        return m["CqWWD"](i, X);
      },
    };
    try {
      $["getJSON"](P, function (i) {
        let X = i[0x2],
          M = i[0x0]["map"]((O) => O[0x0])["join"]("\x20");
        if (is_valid_translation(X, F, j, M)) {
          let O = V["bPwbx"](replace_back_HTML_tags, M, a);
          V["yfFzf"](x, [X, O]);
        } else V["yfFzf"](x, [null, null]);
      });
    } catch (i) {
      m["CqWWD"](x, [null, null]);
    }
  });
}
function is_in_viewport(F, m) {
  const j = {};
  (j["YtknS"] = function (i, X) {
    return i || X;
  }),
    (j["AjMLb"] = function (i, X) {
      return i <= X;
    });
  const P = j;
  if (P["YtknS"](!F, !m)) return ![];
  const x = F["getBoundingClientRect"](),
    V = m["getBoundingClientRect"]();
  return x["bottom"] >= V["top"] && P["AjMLb"](x["top"], V["bottom"]);
}
function get_detected_language_names(F) {
  const m = {};
  (m["cICcA"] = function (V, i) {
    return V === i;
  }),
    (m["ICcWo"] = "Multiple\x20Languages");
  const j = m;
  let P = F["size"];
  if (j["cICcA"](P, 0x1)) return [...F][0x0];
  if (P === 0x2) return [...F]["sort"]()["join"](",\x20");
  return j["ICcWo"];
}
function add_traslate_button() {
  const a = {
    SqepT: "div",
    TyGfx: "translate_div",
    tetOV: "none",
    Wrxos: "flex",
    chyVS: function (j, P) {
      return j(P);
    },
    PYdoK: "conversation_panel_wrapper",
    OulaZ: "click",
  };
  let F = document["createElement"](a["SqepT"]);
  (F["id"] = a["TyGfx"]),
    (F["className"] = "hide"),
    (F["innerHTML"] =
      "\x0a\x20\x20\x20\x20\x20\x20\x20\x20<div\x20id=\x22translate_message_btn\x22\x20class=\x22btn\x22\x20style=\x22display:\x20" +
      (is_translate_enabled ? a["tetOV"] : a["Wrxos"]) +
      ";\x20text-transform:none;\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<img\x20src=\x22" +
      translate_icon_1 +
      "\x22\x20class=\x22translate_icon\x22\x20width=\x2217px\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div><span\x20id=\x22detected_language_names\x22></span>\x20>\x20<span\x20id=\x22targeted_language_name\x22></span></div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span\x20class=\x22highlight\x22\x20style=\x22text-transform:none;\x22>Translate\x20using\x20Prime\x20Sender</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20<div\x20id=\x22original_message_btn\x22\x20class=\x22btn\x22\x20style=\x22display:\x20" +
      (is_translate_enabled ? a["Wrxos"] : a["tetOV"]) +
      "\x22>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<img\x20src=\x22" +
      translate_icon_2 +
      "\x22\x20class=\x22translate_icon\x22\x20width=\x2217px\x22/>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<span\x20class=\x22highlight\x22>View\x20Original</span>\x0a\x20\x20\x20\x20\x20\x20\x20\x20</div>");
  let m = a["chyVS"](getDocumentElement, a["PYdoK"]);
  m["prepend"](F), F["addEventListener"](a["OulaZ"], translate_all_messages);
}
function update_translate_button() {
  const a = {
    NaSOu: ".detected_language_name",
    bASNz: function (M, O) {
      return M === O;
    },
    uzFNl: "default",
    iOXXC: function (M) {
      return M();
    },
    lGuKl: "conversation_panel",
    HVWdm: "show",
    HaioE: function (M, O) {
      return M(O);
    },
    pcAtI: "hide",
    efUHE: "#detected_language_names",
    fDlxE: "#targeted_language_name",
    heUoE: "shimmer",
  };
  let F = a["bASNz"](currentLanguage, a["uzFNl"]) ? "en" : currentLanguage;
  !document["getElementById"]("translate_div") &&
    a["iOXXC"](add_traslate_button);
  let m = document["getElementById"]("translate_div"),
    j = getDocumentElement(a["lGuKl"]),
    P = document["querySelectorAll"](".message-in"),
    x = Array["from"](P)["filter"]((M) => is_in_viewport(M, j)),
    V = new Set();
  x["forEach"]((M) => {
    if (M["querySelector"](".detected_language_name")) {
      let O = M["querySelector"](a["NaSOu"])["innerText"];
      V["add"](O);
    }
  });
  if (V["size"] === 0x0) {
    m["classList"]["add"]("hide"), m["classList"]["remove"](a["HVWdm"]);
    return;
  }
  let i = a["HaioE"](get_detected_language_names, V),
    X = languageNames["of"](F);
  m["classList"]["add"](a["HVWdm"]),
    m["classList"]["remove"](a["pcAtI"]),
    (m["querySelector"](a["efUHE"])["innerText"] = i),
    (m["querySelector"](a["fDlxE"])["innerText"] = X),
    !is_translate_message_used &&
      !m["classList"]["contains"]("shimmer") &&
      (m["classList"]["add"](a["heUoE"]),
      setTimeout(() => m["classList"]["remove"]("shimmer"), 0x1b58));
}
function get_message_div(F) {
  const m = {};
  (m["SCtrZ"] = "span"), (m["qgdxn"] = ":scope\x20>\x20span");
  const j = m;
  let P = F["querySelector"](".selectable-text"),
    x = P["querySelectorAll"](":scope\x20>\x20span");
  if (x["length"] > 0x1) {
    let i = "";
    x["forEach"]((M) => (i += "\x0a" + M["innerHTML"]));
    let X = document["createElement"](j["SCtrZ"]);
    (X["className"] = x[0x0]?.["className"]),
      (X["innerHTML"] = i),
      (P["innerHTML"] = ""),
      P["appendChild"](X);
  }
  let V = P["querySelector"](j["qgdxn"]);
  return V;
}
function replace_message(a) {
  const F = {
    XbrqC: ".selectable-text",
    TQdeN: function (i, X) {
      return i(X);
    },
    RKyGB: ".translated_message",
    LzPmo: ".original_message",
    UhwOt: ".targeted_language_code",
    cVMcJ: "ltr",
    gIknC: "rtl",
  };
  if (
    !a["querySelector"](F["XbrqC"]) ||
    !a["querySelector"](".translated_message")
  )
    return;
  let m = F["TQdeN"](get_message_div, a),
    j = a["querySelector"](F["RKyGB"])["innerHTML"],
    P = a["querySelector"](F["LzPmo"])["innerHTML"],
    x = a["querySelector"](F["UhwOt"])["innerText"],
    V = a["querySelector"](".detected_language_code")["innerText"];
  is_translate_enabled
    ? ((m["innerHTML"] = j),
      m["setAttribute"](
        "dir",
        RTL_LANGUAGE_CODES["includes"](x) ? "rtl" : F["cVMcJ"]
      ))
    : ((m["innerHTML"] = P),
      m["setAttribute"](
        "dir",
        RTL_LANGUAGE_CODES["includes"](V) ? F["gIknC"] : F["cVMcJ"]
      ));
}
function translate_all_messages() {
  const m = {
    BPBzd: function (V, i) {
      return V(i);
    },
    Sfody: ".message-in",
    gCyEo: "original_message_btn",
    GrEOB: "flex",
    ampaj: "translate_message_btn",
    aVcvR: "translate_div",
    zSRjj: function (V, i) {
      return V == i;
    },
    wJrwo: "shimmer",
    twxbf: function (V, i, X) {
      return V(i, X);
    },
    IEcjr: "translate_message",
  };
  is_translate_enabled = !is_translate_enabled;
  let j = document["querySelectorAll"](m["Sfody"]);
  j["forEach"]((V) => {
    m["BPBzd"](replace_message, V);
  }),
    (document["getElementById"](m["gCyEo"])["style"]["display"] =
      is_translate_enabled ? m["GrEOB"] : "none"),
    (document["getElementById"](m["ampaj"])["style"]["display"] =
      is_translate_enabled ? "none" : m["GrEOB"]);
  let P = document["getElementById"](m["aVcvR"]);
  if (is_translate_enabled) {
    let V = new Date()["toDateString"]();
    if (
      m["zSRjj"](V, last_day_since_translate_used) ||
      count_of_days_translate_used >= 0x5
    )
      P["classList"]["remove"](m["wJrwo"]);
    else {
      P["classList"]["add"]("shimmer"),
        m["twxbf"](
          setTimeout,
          () => P["classList"]["remove"]("shimmer"),
          0xbb8
        ),
        (last_day_since_translate_used = V),
        count_of_days_translate_used++;
      const i = {};
      (i["lastDaySinceTranslateMessageUsed"] = last_day_since_translate_used),
        (i["countOfDaysTranslateMessageUsed"] = count_of_days_translate_used),
        chrome["storage"]["local"]["set"](i);
    }
  } else P["classList"]["remove"](m["wJrwo"]);
  is_translate_message_used = !![];
  const x = {};
  (x["isTranslateMessageUsed"] = !![]),
    chrome["storage"]["local"]["set"](x),
    m["twxbf"](trackEvent, m["IEcjr"], currentLanguage);
}
function translate_visible_messages() {
  const a = {
    pLthi: "@c.us",
    MYTUr: function (j, P, x) {
      return j(P, x);
    },
    dVrPu: ".translated_message_div",
    TuvMS: ".selectable-text",
    EvEWV: "translated_message_div",
    ROBri: function (j, P) {
      return j(P);
    },
    MDgIm: function (j, P) {
      return j > P;
    },
    ttYwF: function (j, P, x) {
      return j(P, x);
    },
    eTBld: function (j, P) {
      return j && P;
    },
    HIgum: function (j, P) {
      return j == P;
    },
    XOVWq: function (j) {
      return j();
    },
    lGxKJ: function (j, P) {
      return j === P;
    },
    kQVBH: ".message-in",
  };
  let F = a["lGxKJ"](currentLanguage, "default") ? "en" : currentLanguage,
    m = document["querySelectorAll"](a["kQVBH"]);
  m["forEach"](async (j, P) => {
    if (!j["querySelector"](a["dVrPu"]) && j["querySelector"](a["TuvMS"])) {
      let x = document["createElement"]("div");
      (x["className"] = a["EvEWV"]), (x["hidden"] = !![]), j["appendChild"](x);
      let V = a["ROBri"](get_message_div, j);
      if (V && a["MDgIm"](V["innerText"]["length"], 0x0)) {
        let i = V["innerHTML"],
          [X, M] = await a["ttYwF"](translate_message_HTML, i, F);
        a["eTBld"](X, M) &&
          ((x["innerHTML"] =
            "\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22targeted_language_code\x22>" +
            F +
            "</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22detected_language_code\x22>" +
            X +
            "</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22targeted_language_name\x22>" +
            languageNames["of"](F) +
            "</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22detected_language_name\x22>" +
            languageNames["of"](X) +
            "</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22translated_message\x22>" +
            M +
            "</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20<div\x20class=\x22original_message\x22>" +
            i +
            "</div>\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"),
          a["ROBri"](replace_message, j),
          j["addEventListener"]("click", (O) => {
            let D =
              O["target"]["dataset"]["jid"] ||
              O["target"]["parentNode"]["dataset"]["jid"] ||
              "";
            D &&
              D["includes"](a["pLthi"]) &&
              a["MYTUr"](openNumber, D["split"](a["pLthi"])[0x0], "");
          }));
      }
    }
    a["HIgum"](P, m["length"] - 0x1) && a["XOVWq"](update_translate_button);
  });
}
function translate_messages() {
  const a = {
    lvdpc: function (V, i) {
      return V - i;
    },
    mmikR: function (x) {
      return x();
    },
    kjtTC: function (x, V) {
      return x(V);
    },
    WOFgt: "today_yesterday_div",
    RyRLh: "translate_div",
    blonh: function (x, V, i) {
      return x(V, i);
    },
    vHWqi: "0px",
    CjDqA: function (x) {
      return x();
    },
    kzLNu: "scroll",
  };
  let F = getDocumentElement("conversation_panel");
  if (!F) return;
  a["CjDqA"](add_traslate_button);
  let m = null,
    j = F["scrollTop"];
  function P(x = ![]) {
    let V = Math["abs"](a["lvdpc"](F["scrollTop"], j));
    (x || V > 0x21) &&
      ((j = F["scrollTop"]), a["mmikR"](translate_visible_messages));
    window["clearTimeout"](m);
    let i = a["kjtTC"](getDocumentElement, a["WOFgt"]),
      X = document["getElementById"](a["RyRLh"]);
    X &&
      (i
        ? ((X["style"]["top"] = "35px"),
          (m = a["blonh"](
            setTimeout,
            () => (X["style"]["top"] = "0px"),
            0xc80
          )))
        : (X["style"]["top"] = a["vHWqi"]));
  }
  F["addEventListener"](a["kzLNu"], P), a["kjtTC"](P, !![]);
}
async function translate(a, F = "en", m = currentLanguage) {
  const j = {
    nQrGT: function (P, x, V, i) {
      return P(x, V, i);
    },
    bzlPJ: "translatedCache",
    vWyac: function (P, V) {
      return P === V;
    },
    BhMxm: function (P, V) {
      return P === V;
    },
  };
  if (
    j["vWyac"](a, undefined) ||
    j["BhMxm"](a, null) ||
    j["BhMxm"](a["trim"]()["length"], 0x0)
  )
    return "";
  return new Promise((P) => {
    chrome["storage"]["local"]["get"]([j["bzlPJ"]], async function (x) {
      const V = x["translatedCache"] || {};
      if (V[a] && V[a][m]) P(V[a][m]);
      else {
        const i = await j["nQrGT"](translateAPI, a, F, m);
        if (!V[a]) V[a] = {};
        V[a][m] = i;
        const X = {};
        (X["translatedCache"] = V),
          chrome["storage"]["local"]["set"](X, function () {
            P(i);
          });
      }
    });
  });
}
async function translateAPI(a, F = "en", m = currentLanguage) {
  const j = {
    RqeSw: function (V, i) {
      return V(i);
    },
    jCVPH: function (V, i) {
      return V(i);
    },
    zJpbY: function (V, i) {
      return V(i);
    },
    bkXsN: function (V, i) {
      return V(i);
    },
    LCTti: function (V, i) {
      return V === i;
    },
    nTJLp: function (V, i) {
      return V === i;
    },
    rZpmE: function (V, i) {
      return V === i;
    },
    CyWXc: function (V, i) {
      return V(i);
    },
  };
  let P = (V) =>
    V["replaceAll"](
      /<<(.*?)>>/gi,
      "<span\x20class=\x22styled_text\x22>$1</span>"
    );
  if (a === undefined || j["LCTti"](a, null) || a["trim"]()["length"] === 0x0)
    return "";
  if (j["nTJLp"](m, "default") || j["rZpmE"](m, F)) return j["CyWXc"](P, a);
  const x =
    "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" +
    F +
    "&tl=" +
    m +
    "&dt=t&q=" +
    encodeURI(a);
  return await new Promise((V) => {
    try {
      $["getJSON"](x, function (i) {
        let X = i[0x0]["map"]((M) => M[0x0])["join"]("\x20");
        j["RqeSw"](V, j["jCVPH"](P, X));
      });
    } catch (i) {
      j["zJpbY"](V, j["bkXsN"](P, a));
    }
  });
}
