Skip to content

Commit

Permalink
feat(FRAnime): new presence (#7404)
Browse files Browse the repository at this point in the history
* feat(FRAnime): new presence

* Using yarn format

* Update presence.ts

Forgot to change pathname to href

Signed-off-by: Noah Schmidt <[email protected]>

* Update metadata.json

Changing domain

Signed-off-by: Noah Schmidt <[email protected]>

* Update presence.ts

Additional changes suggested by dependabot

Signed-off-by: Noah Schmidt <[email protected]>

* Update websites/F/FRAnime/presence.ts

Co-authored-by: Daniel Lau <[email protected]>
Signed-off-by: Noah Schmidt <[email protected]>

* Update websites/F/FRAnime/presence.ts

Co-authored-by: Daniel Lau <[email protected]>
Signed-off-by: Noah Schmidt <[email protected]>

* Update websites/F/FRAnime/presence.ts

Co-authored-by: Daniel Lau <[email protected]>
Signed-off-by: Noah Schmidt <[email protected]>

* Update presence.ts

Removing Emojis

Signed-off-by: Noah Schmidt <[email protected]>

* Update metadata.json

Updating Schema

Signed-off-by: Noah Schmidt <[email protected]>

* Update websites/F/FRAnime/presence.ts

Co-authored-by: Daniel Lau <[email protected]>
Signed-off-by: Noah Schmidt <[email protected]>

* Update presence.ts

removing repetitive comments

Signed-off-by: Noah Schmidt <[email protected]>

* Update presence.ts

Signed-off-by: Noah Schmidt <[email protected]>

* Update presence.ts

Signed-off-by: Noah Schmidt <[email protected]>

* Update presence.ts

Signed-off-by: Noah Schmidt <[email protected]>

* Update presence.ts

Removing useless comment, as suggested

Signed-off-by: Noah Schmidt <[email protected]>

* Update presence.ts

Putting images in an enum, such as recommanded

Signed-off-by: Noah Schmidt <[email protected]>

* Update presence.ts

Signed-off-by: Noah Schmidt <[email protected]>

---------

Signed-off-by: Noah Schmidt <[email protected]>
Co-authored-by: Daniel Lau <[email protected]>
  • Loading branch information
Wys2 and theusaf authored Jul 31, 2023
1 parent fcc689d commit 7e7d4a5
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
24 changes: 24 additions & 0 deletions websites/F/FRAnime/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://schemas.premid.app/metadata/1.9",
"author": {
"id": "187235399524024320",
"name": "0xWys"
},
"service": "FRAnime",
"description": {
"en": "Watch anime in VF or VOSTFR for free and ad-free on FRAnime",
"fr": "Regarder un animé en VF ou en VOSTFR est gratuit et sans pub sur FRAnime"
},
"url": "franime.fr",
"version": "1.0.0",
"logo": "https://i.imgur.com/YKxUCs3.png",
"thumbnail": "https://i.imgur.com/yUK6zjO.png",
"color": "#eb132c",
"category": "anime",
"tags": [
"anime",
"streaming",
"vf",
"vostfr"
]
}
100 changes: 100 additions & 0 deletions websites/F/FRAnime/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
const presence = new Presence({
clientId: "1102272266278027296",
});
const enum Assets {
FRAnimeLogo = "https://i.imgur.com/YKxUCs3.png",
FRAnimeLogoBg = "https://i.imgur.com/byFtXWd.png",
}
const presenceStrings = {
browsing: "Parcours le catalogue",
branding: "Animes gratuit & sans pub",
websiteName: "FRAnime.fr",
onPage: "Sur la page",
watchOn: "Regarder sur FRAnime.fr",
},
animeBrowsingTimestamp = Math.floor(Date.now() / 1000);

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {},
{ href, pathname } = document.location,
params = new URLSearchParams(new URL(href).search.slice(1)),
scriptElement = document.querySelector<HTMLScriptElement>(
'script[type="application/ld+json"]'
),
jsonLD = scriptElement ? JSON.parse(scriptElement.textContent || "") : null;

// Home page
if (pathname === "/") {
presenceData.details = presenceStrings.browsing;
presenceData.state = presenceStrings.branding;
presenceData.smallImageText = presenceStrings.websiteName;
presenceData.largeImageKey = Assets.FRAnimeLogoBg;
presenceData.smallImageKey = Assets.Search;
presenceData.startTimestamp = animeBrowsingTimestamp;

// Anime page
} else if (params.get("ep") === "") {
presenceData.details = `${presenceStrings.onPage} ${jsonLD.name}`;
presenceData.state = presenceStrings.branding;
presenceData.smallImageText = presenceStrings.websiteName;
presenceData.largeImageKey = jsonLD.thumbnailUrl;
presenceData.smallImageKey = Assets.Search;
presenceData.startTimestamp = animeBrowsingTimestamp;
presenceData.buttons = [
{
label: presenceStrings.watchOn,
url: href,
},
];

// Watching page
} else if (document.querySelector("#play_button")) {
presenceData.details = `${jsonLD.name} - S${params.getAll(
"s"
)}, EP${params.getAll("ep")}`;

presenceData.state = presenceStrings.branding;
presenceData.smallImageText = presenceStrings.websiteName;
presenceData.smallImageKey = Assets.Pause;
presenceData.largeImageKey = jsonLD.thumbnailUrl;
presenceData.buttons = [
{
label: presenceStrings.watchOn,
url: href,
},
];

// The anime is loading, so we delete the timestamp
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;

// player is loaded
} else if (document.querySelectorAll("video")) {
const video = document.querySelector("video"),
[startTimestamp, endTimestamp] = presence.getTimestampsfromMedia(video);

presenceData.details = `${jsonLD.name} - S${params.getAll(
"s"
)}, EP${params.getAll("ep")}`;

presenceData.state = presenceStrings.branding;
presenceData.smallImageText = presenceStrings.websiteName;
presenceData.startTimestamp = startTimestamp;
presenceData.endTimestamp = endTimestamp;
presenceData.largeImageKey = jsonLD.thumbnailUrl;
presenceData.buttons = [
{
label: presenceStrings.watchOn,
url: href,
},
];

if (!video.paused) presenceData.smallImageKey = Assets.Play;
else {
presenceData.smallImageKey = Assets.Pause;
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
}
presence.setActivity(presenceData);
});

0 comments on commit 7e7d4a5

Please sign in to comment.