Skip to content

Commit

Permalink
fix(Anghami): run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
illvesion committed Jan 21, 2025
1 parent 4e8c835 commit 47cb9af
Showing 1 changed file with 82 additions and 68 deletions.
150 changes: 82 additions & 68 deletions websites/A/Anghami/presence.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,100 @@
const presence = new Presence({
clientId: "721740741570986016",
}),

strings = presence.getStrings({
play: "general.play",
pause: "general.paused",
browse: "general.browsing",
});
clientId: "721740741570986016",
}),
strings = presence.getStrings({
play: "general.play",
pause: "general.paused",
browse: "general.browsing",
});

function updateLogo() {
const trackCoverartDiv = document.querySelector(".track-coverart");
if (trackCoverartDiv) {
const style = trackCoverartDiv.getAttribute("style");
if (style) {
const match = decodeURIComponent(style).match(/url\("([^"]+?)"\)/);
if (match && match[1]) {
let url = match[1];
url = url.replace(/&size=\d+/, "");
return url;
const trackCoverartDiv = document.querySelector(".track-coverart");
if (trackCoverartDiv) {
const style = trackCoverartDiv.getAttribute("style");
if (style) {
const match = decodeURIComponent(style).match(/url\("([^"]+?)"\)/);
if (match && match[1]) {
let url = match[1];
url = url.replace(/&size=\d+/, "");
return url;
}
}
}
}
}

function calculateEndTimestamp(startTime: string, remainingTime: string): string {
const [startMinutes, startSeconds] = startTime.trim().split(":").map(Number),
[remainingMinutes, remainingSeconds] = remainingTime.trim().split(":").map(Number),

endTotalSeconds = startMinutes * 60 + startSeconds + remainingMinutes * 60 + remainingSeconds;
function calculateEndTimestamp(
startTime: string,
remainingTime: string
): string {
const [startMinutes, startSeconds] = startTime.trim().split(":").map(Number),
[remainingMinutes, remainingSeconds] = remainingTime
.trim()
.split(":")
.map(Number),
endTotalSeconds =
startMinutes * 60 +
startSeconds +
remainingMinutes * 60 +
remainingSeconds;

let endMinutes = Math.floor(endTotalSeconds / 60),
endSeconds = endTotalSeconds % 60;
let endMinutes = Math.floor(endTotalSeconds / 60),
endSeconds = endTotalSeconds % 60;

if (endSeconds === 60) {
endSeconds = 0;
endMinutes++;
}
return `${endMinutes}:${endSeconds.toString().padStart(2, "0")}`;
if (endSeconds === 60) {
endSeconds = 0;
endMinutes++;
}
return `${endMinutes}:${endSeconds.toString().padStart(2, "0")}`;
}

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: updateLogo(),
type: ActivityType.Listening,
},
playback = !!document.querySelector("anghami-player");

const presenceData: PresenceData = {
largeImageKey: updateLogo(),
type: ActivityType.Listening
},
playback = !!document.querySelector("anghami-player");
if (playback) {
const selectors: NodeListOf<Node> =
document.querySelectorAll(".duration-text"),
playing: boolean =
document.querySelector("anghami-player svg[title='pause-shape']") !==
null;
let selector: Node = document.querySelector(
"anghami-player .action-title .trim"
);
presenceData.details = (selector && selector.textContent) || null;
selector = document.querySelector("anghami-player .action-artist .trim");
presenceData.state = (selector && selector.textContent) || null;

if (playback) {
const selectors: NodeListOf<Node> =
document.querySelectorAll(".duration-text"),
playing: boolean =
document.querySelector("anghami-player svg[title='pause-shape']") !==
null;
let selector: Node = document.querySelector(
"anghami-player .action-title .trim"
);
presenceData.details = (selector && selector.textContent) || null;
selector = document.querySelector("anghami-player .action-artist .trim");
presenceData.state = (selector && selector.textContent) || null;
if (!playing) {
presenceData.smallImageKey = Assets.Pause;
presenceData.smallImageText = "Paused";
}
const duration = presence.timestampFromFormat(
calculateEndTimestamp(
selectors[0].textContent,
selectors[1].textContent
)
),
timestamps = presence.getTimestamps(
presence.timestampFromFormat(selectors[0].textContent),
duration
);

if (!playing) {
presenceData.smallImageKey = Assets.Pause;
presenceData.smallImageText = "Paused";
}
const
duration = presence.timestampFromFormat(calculateEndTimestamp(selectors[0].textContent, selectors[1].textContent)),
timestamps = presence.getTimestamps(presence.timestampFromFormat(selectors[0].textContent), duration);

presenceData.startTimestamp = timestamps[0];
presenceData.endTimestamp = timestamps[1];
presenceData.startTimestamp = timestamps[0];
presenceData.endTimestamp = timestamps[1];

if (!playing) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
if (!playing) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}

presence.setActivity(presenceData, playback);
} else {
presenceData.details = (await strings).browse;
presenceData.smallImageKey = Assets.Search;
presenceData.smallImageText = (await strings).browse;
presence.setActivity(presenceData);
}
presence.setActivity(presenceData, playback);
} else {
presenceData.details = (await strings).browse;
presenceData.smallImageKey = Assets.Search;
presenceData.smallImageText = (await strings).browse;
presence.setActivity(presenceData);
}
});

0 comments on commit 47cb9af

Please sign in to comment.