Skip to content

Commit

Permalink
refactor(Sflix): prettier refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
iuriineves committed Dec 28, 2024
1 parent 774084f commit 81580ba
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions websites/S/Sflix/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,38 @@ let video = {
paused: true,
};

presence.on("iFrameData", (data: { duration: number, currentTime: number, paused: boolean }) => {
video = data;
});
presence.on(
"iFrameData",
(data: { duration: number; currentTime: number; paused: boolean }) => {
video = data;
}
);

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: Assets.Logo,
type: ActivityType.Watching,
startTimestamp: browsingTimestamp,
},

[ thumbnail, privacy ] = await Promise.all([
presence.getSetting<boolean>("thumbnail"),
presence.getSetting<boolean>("privacy"),
]),

variables = await presence.getPageVariable("currPage");
largeImageKey: Assets.Logo,
type: ActivityType.Watching,
startTimestamp: browsingTimestamp,
},
[thumbnail, privacy] = await Promise.all([
presence.getSetting<boolean>("thumbnail"),
presence.getSetting<boolean>("privacy"),
]),
variables = await presence.getPageVariable("currPage");

switch (variables.currPage) {
case "": {
presenceData.details = "Searching";
presenceData.smallImageKey = Assets.Search;
presenceData.smallImageText = "Searching";
presenceData.state = privacy ? "" : `${document.querySelector("h2[class*='cat-heading']").textContent.split('"')[1] || document.querySelector("h2[class*='cat-heading']").textContent}`;
presenceData.state = privacy
? ""
: `${
document
.querySelector("h2[class*='cat-heading']")
.textContent.split('"')[1] ||
document.querySelector("h2[class*='cat-heading']").textContent
}`;
break;
}
case "home_search":
Expand All @@ -49,23 +57,31 @@ presence.on("UpdateData", async () => {
}
case "detail": {
presenceData.details = "Browsing";
presenceData.state = privacy ? "" : document.querySelector(".heading-name")?.textContent;
presenceData.state = privacy
? ""
: document.querySelector(".heading-name")?.textContent;
presenceData.smallImageKey = Assets.Reading;
presenceData.smallImageText = "Browsing";
break;
}
case "watch": {

const showTitle = document.querySelector(".heading-name").textContent,
thumbnailURL = document.querySelector(`img[title*="${showTitle}"]`)?.getAttribute("src");

thumbnailURL = document
.querySelector(`img[title*="${showTitle}"]`)
?.getAttribute("src");

presenceData.details = privacy ? "Watching" : `${showTitle}`;
presenceData.state = privacy ? "" : `${document.querySelector(".on-air div h3")?.textContent || ""}`;
presenceData.largeImageKey = (thumbnail && thumbnailURL && !privacy) ? thumbnailURL : Assets.Logo;

presenceData.state = privacy
? ""
: `${document.querySelector(".on-air div h3")?.textContent || ""}`;
presenceData.largeImageKey =
thumbnail && thumbnailURL && !privacy ? thumbnailURL : Assets.Logo;

if (!video.paused) {
const timestamps = presence.getTimestamps(video.currentTime, video.duration);
const timestamps = presence.getTimestamps(
video.currentTime,
video.duration
);
presenceData.smallImageKey = Assets.Play;
presenceData.smallImageText = "Playing";
if (!privacy) {
Expand Down

0 comments on commit 81580ba

Please sign in to comment.