Skip to content

Commit

Permalink
fix(WCOStream): fix presence & remove broken code (#8277)
Browse files Browse the repository at this point in the history
* fix(WCOStream): fix presence & remove broken code

* fix(WCOStream): fix presence
  • Loading branch information
Dark_Ville authored Apr 16, 2024
1 parent 2b8dc9f commit 73e2f86
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 63 deletions.
21 changes: 12 additions & 9 deletions websites/W/Wcostream/iframe.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const iframe = new iFrame();

iframe.on("UpdateData", async () => {
if (document.querySelector<HTMLVideoElement>("#video-js_html5_api")) {
const video = document.querySelector<HTMLVideoElement>("video");
if (video) {
iframe.send({
paused: document
.querySelector<HTMLButtonElement>(
"#video-js > div.vjs-control-bar > button"
)
.title.includes("Play"),
timeLeft: document.querySelector<HTMLSpanElement>(
"span.vjs-remaining-time-display"
).textContent,
paused: video?.paused,
timeLeft:
document.querySelectorAll('[role="timer"]')?.[1]?.textContent ??
document.querySelector(".vjs-remaining-time-display")?.textContent,
});
} else {
iframe.send({
titleV:
document.querySelector(".video-title")?.textContent ??
document.querySelector('[property="og:title"]')?.textContent,
});
}
});
9 changes: 3 additions & 6 deletions websites/W/Wcostream/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
"description": {
"en": "Watch anime online, You can watch anime movies online and english dubbed. Our site to watch animes. Best online animes series here."
},
"url": [
"www.wcostream.com",
"www.wcostream.net",
"www.wcostream.org"
],
"version": "1.1.9",
"url": "www.wcostream.com",
"regExp": "(www[.])?wcostream[.].{2,5}",
"version": "1.1.10",
"logo": "https://cdn.rcd.gg/PreMiD/websites/W/Wcostream/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/W/Wcostream/assets/thumbnail.png",
"color": "#FFCE39",
Expand Down
84 changes: 36 additions & 48 deletions websites/W/Wcostream/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@ const presence = new Presence({
browsingTimestamp = Math.floor(Date.now() / 1000);

let video = {
timeLeft: "",
paused: true,
};
paused: true,
timeLeft: "",
},
title = "";

presence.on("iFrameData", (data: { timeLeft: string; paused: boolean }) => {
video = data;
});
const enum Assets {
Logo = "https://cdn.rcd.gg/PreMiD/websites/W/Wcostream/assets/logo.png",
}
presence.on(
"iFrameData",
(data: { paused: boolean; timeLeft: string; titleV: string }) => {
if (data.paused || data.timeLeft) video = data;
else title = data.titleV;
}
);

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey:
"https://cdn.rcd.gg/PreMiD/websites/W/Wcostream/assets/logo.png",
largeImageKey: Assets.Logo,
details: "Browsing...",
startTimestamp: browsingTimestamp,
},
Expand All @@ -26,21 +33,20 @@ presence.on("UpdateData", async () => {
presence.getSetting<boolean>("buttons"),
]);
if (video.timeLeft !== "") {
if (!title) {
title =
document.querySelector('[itemprop="partOfSeries"]')?.textContent ??
document.querySelector(".video-title")?.textContent ??
document.querySelector(".entry-title")?.textContent;
}
presenceData.details = "Watching:";
presenceData.state = document.querySelector<HTMLSpanElement>(
"#content div.iltext > strong > span"
).textContent;
if (
document.querySelector<HTMLAnchorElement>(
"#star-watch-on > div.wcobtn > a"
)
) {
presenceData.state = title?.split("Episode")?.[0];

if (document.querySelector<HTMLImageElement>('[class*="s-post-image"]')) {
// This is where they store their thumbnails/posters
presenceData.largeImageKey = `https://cdn.animationexplore.com/catimg/${
document
.querySelector<HTMLAnchorElement>("#star-watch-on > div.wcobtn > a")
.href.split("/", 5)[4]
}.jpg`;
presenceData.largeImageKey =
document.querySelector<HTMLImageElement>('[class*="s-post-image"]')
?.src ?? Assets.Logo;
}
delete presenceData.startTimestamp;
const timeLeft = presence.timestampFromFormat(video.timeLeft);
Expand All @@ -56,34 +62,16 @@ presence.on("UpdateData", async () => {
else if (pathname.startsWith("/search")) {
presenceData.details = "Searching...";
presenceData.smallImageKey = Assets.Search;
} else if (pathname.startsWith("/anime")) {
presenceData.details = "Viewing a Series:";
presenceData.state = document.querySelector<HTMLHeadingElement>(
"tbody > tr > td > h2"
).textContent;
presenceData.largeImageKey = document.querySelector<HTMLImageElement>(
"#cat-img-desc > div:nth-child(1) > img"
).src;
presenceData.smallImageKey = Assets.Reading;
presenceData.buttons = [{ label: "View Series", url: document.URL }];
} else if (
document.querySelector<HTMLAnchorElement>(
"table > tbody > tr > td > h2 > a"
)
) {
presenceData.details = "Browsing a Category:";
presenceData.state = document.querySelector<HTMLAnchorElement>(
"table > tbody > tr > td > h2 > a"
).textContent;
presenceData.smallImageKey = Assets.Search;
presenceData.smallImageText = "Searching";
}
if (!cover) {
presenceData.largeImageKey =
"https://cdn.rcd.gg/PreMiD/websites/W/Wcostream/assets/0.png";
}
if (!buttons) delete presenceData.buttons;
if (!timestamps) {

if (!cover && presenceData.largeImageKey !== Assets.Logo)
presenceData.largeImageKey = Assets.Logo;

if (!buttons && presenceData.buttons) delete presenceData.buttons;
if (
!timestamps &&
(presenceData.endTimestamp || presenceData.startTimestamp)
) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
Expand Down

0 comments on commit 73e2f86

Please sign in to comment.