Skip to content

Commit

Permalink
fix(fbox): finds data correctly now (#8273)
Browse files Browse the repository at this point in the history
  • Loading branch information
Its-Haze authored Apr 16, 2024
1 parent 42f81b5 commit 2b8dc9f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
6 changes: 5 additions & 1 deletion websites/F/fbox.to/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
{
"name": "Kyrie",
"id": "368399721494216706"
},
{
"name": "Haze.dev",
"id": "165102125746094080"
}
],
"service": "fbox.to",
Expand All @@ -16,7 +20,7 @@
},
"url": "fbox.to",
"regExp": "(www([0-9]*)?[.])?fbox[.]to",
"version": "1.2.14",
"version": "1.3.0",
"logo": "https://cdn.rcd.gg/PreMiD/websites/F/fbox.to/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/F/fbox.to/assets/thumbnail.png",
"color": "#565c67",
Expand Down
38 changes: 24 additions & 14 deletions websites/F/fbox.to/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,19 @@ presence.on("UpdateData", async () => {
[buttons, image] = await Promise.all([
presence.getSetting<boolean>("buttons"),
presence.getSetting<boolean>("image"),
]),
search = document.querySelector<HTMLInputElement>('[type="text"]');
]);

if (search?.value) {
presenceData.details = "Searching for:";
presenceData.state = search.value;
presenceData.smallImageKey = Assets.Search;
} else if (pathname === "/home" || pathname === "/")
if (pathname === "/home" || pathname === "/")
presenceData.details = "Browsing";
else if (pathname.startsWith("/series/")) {
else if (pathname.startsWith("/tv/")) {
const title = document.querySelector<HTMLHeadingElement>(
"#watch > div.container > div.watch-extra > div.bl-1 > section.info > div.info > h1"
"section#w-info > div.info > h1.name"
),
season = document.querySelector<HTMLSpanElement>(".value"),
episode = document.querySelector<HTMLAnchorElement>("a.active");
{ season, episode } = extractSeasonEpisode(pathname);
if (title) presenceData.details = title.textContent;
if (season) {
presenceData.state = season.textContent.split("-")[0].trim();
if (episode) presenceData.state += ` - ${episode.textContent.trim()}`;
presenceData.state = `Season ${season}`;
if (episode) presenceData.state += ` Episode ${episode}`;
}
if (image) {
presenceData.largeImageKey =
Expand Down Expand Up @@ -75,7 +69,7 @@ presence.on("UpdateData", async () => {
}
} else if (pathname.startsWith("/movie/")) {
const title = document.querySelector<HTMLHeadingElement>(
"#watch > div.container > div.watch-extra > div.bl-1 > section.info > div.info > h1"
"section#w-info > div.info > h1.name"
);
if (title) presenceData.details = title.textContent;
if (image) {
Expand Down Expand Up @@ -117,3 +111,19 @@ presence.on("UpdateData", async () => {

presence.setActivity(presenceData);
});

function extractSeasonEpisode(url: string): {
season: number;
episode: number;
} {
// This regular expression matches URLs that follow the pattern /tv/show-name/season-number-episode-number
// It captures the season number and episode number from the URL
const match = url.match(/\/tv\/[^/]+\/(\d+)-(\d+)/);
if (match) {
return {
season: parseInt(match[1], 10),
episode: parseInt(match[2], 10),
};
}
return { season: 0, episode: 0 };
}

0 comments on commit 2b8dc9f

Please sign in to comment.