presence.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const presence = new Presence({
  2. clientId: "799583813582848041",
  3. }),
  4. browsingTimestamp: number = Math.floor(Date.now() / 1000);
  5. let from: string, to: string, typet: string;
  6. presence.on("UpdateData", async () => {
  7. const presenceData: PresenceData = {
  8. largeImageKey:
  9. "https://cdn.rcd.gg/PreMiD/websites/Y/Yandex.Translate/assets/logo.png",
  10. };
  11. switch (document.location.pathname) {
  12. case "/": {
  13. typet = "Text";
  14. from = document.querySelector("#srcLangButton").textContent;
  15. to = document.querySelector("#dstLangButton").textContent;
  16. break;
  17. }
  18. case "/translate":
  19. case "/doc": {
  20. typet =
  21. document.location.pathname === "/translate" ? "Website" : "Document";
  22. from = document.querySelector(
  23. "#srcLangButton > #sourceLangText"
  24. ).textContent;
  25. to = document.querySelector(
  26. "#dstLangButton > #targetLangText"
  27. ).textContent;
  28. break;
  29. }
  30. case "/ocr": {
  31. typet = "Image";
  32. from = document.querySelector("#sourceLangButton").textContent;
  33. to = document.querySelector("#targetLangButton").textContent;
  34. break;
  35. }
  36. default: {
  37. typet = "Text";
  38. from = "Choosing...";
  39. to = "Choosing...";
  40. }
  41. }
  42. const showTime = await presence.getSetting<boolean>("stamp"),
  43. showType = await presence.getSetting<boolean>("type");
  44. presenceData.startTimestamp = showTime ? browsingTimestamp : null;
  45. if (presenceData.startTimestamp === null) delete presenceData.startTimestamp;
  46. if (showType) {
  47. presenceData.details = `Translating: ${typet}`;
  48. presenceData.state = `From: ${from} - To: ${to}`;
  49. } else {
  50. presenceData.details = `Translating from: ${from}`;
  51. presenceData.state = `To: ${to}`;
  52. }
  53. presence.setActivity(presenceData);
  54. });