Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Anime Sama): add privacy mode and update timestamps #8839

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion websites/A/Anime Sama/iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const iframe = new iFrame();

iframe.on("UpdateData", async () => {
const video = document.querySelector<HTMLVideoElement>("video");
if (!isNaN(video?.duration)) {
if (video && !isNaN(video.duration)) {
iframe.send({
currentTime: video.currentTime,
duration: video.duration,
Expand Down
24 changes: 18 additions & 6 deletions websites/A/Anime Sama/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"$schema": "https://schemas.premid.app/metadata/1.11",
"apiVersion": 1,
"author": {
"name": "RisingSunLight",
"id": "240521747852558347"
"name": "Atom Skully",
"id": "671037171611729920"
},
"contributors": [
{
"name": "Atom Skully",
"id": "671037171611729920"
"name": "RisingSunLight",
"id": "240521747852558347"
}
],
Comment on lines +5 to 13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you are swapping the contributor and author field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best, as this is the second time I've modified/added features to this Presence.
What's more, the original author of the Presence doesn't seem to maintain it anymore, nor the others he created (the last commit he made on one of these Presences seems to date back to March 2023).
And if I come up with any other ideas for adding functionality to this Presence, I'll be happy to add them :)
Let me know what you think and if you find this change legitimate. If not, I'll change it according to your guidelines.

"service": "Anime Sama",
Expand All @@ -17,7 +17,7 @@
"fr": "Votre site de streaming préféré pour vos animes et scans sans pubs."
},
"url": "anime-sama.fr",
"version": "1.1.9",
"version": "1.2.0",
"logo": "https://cdn.rcd.gg/PreMiD/websites/A/Anime%20Sama/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/A/Anime%20Sama/assets/thumbnail.png",
"color": "#0063c0",
Expand All @@ -30,14 +30,26 @@
"vostfr"
],
"iframe": true,
"iFrameRegExp": ".*((sendvid)|(sibnet)|(myvi)).*",
"iFrameRegExp": ".*",

Check warning on line 33 in websites/A/Anime Sama/metadata.json

View workflow job for this annotation

GitHub Actions / Presence Validator

Presence (Anime Sama) has metadata.iFrameRegExp set to '.*', please change this if possible
"settings": [
{
"id": "buttons",
"title": "Show Buttons",
"icon": "fas fa-compress-arrows-alt",
"value": true
},
{
"id": "privacy",
"title": "Privacy Mode",
"icon": "fad fa-user-secret",
"value": false
},
{
"id": "timestamps",
"title": "Show Timestamps",
"icon": "fad fa-stopwatch",
"value": true
},
{
"id": "cover",
"title": "Show Cover",
Expand Down
81 changes: 57 additions & 24 deletions websites/A/Anime Sama/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@ const presence = new Presence({ clientId: "1016797607370162256" }),
"": "Visionne la page d'accueil",
planning: "Regarde le planning des sorties",
aide: "Lit la page d'aide",
profil: "visionne son profil",
profil: "Visionne son profil",
catalogue: "Parcourir le catalogue",
};

const enum Assets {
Logo = "https://cdn.rcd.gg/PreMiD/websites/A/Anime%20Sama/assets/logo.png",
}

interface IFrameData {
duration: number;
currentTime: number;
paused: boolean;
}

let duration: number,
currentTime: number,
paused = true;
let video = {
duration: 0,
currentTime: 0,
paused: true,
};

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

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
Expand All @@ -34,16 +33,22 @@ presence.on("UpdateData", async () => {
},
{ pathname, href } = document.location,
pathArr = pathname.split("/"),
[showButtons, showCover] = await Promise.all([
[showButtons, privacyMode, showTimestamps, showCover] = await Promise.all([
presence.getSetting<boolean>("buttons"),
presence.getSetting<boolean>("privacy"),
presence.getSetting<boolean>("timestamps"),
presence.getSetting<boolean>("cover"),
]);

if (Object.keys(staticPages).includes(pathArr[1]) && pathArr.length <= 3)
if (Object.keys(staticPages).includes(pathArr[1]) && pathArr.length <= 3) {
presenceData.details = staticPages[pathArr[1]];
else if (pathArr.length === 4) {
if (privacyMode) presenceData.details = "Navigue...";
} else if (pathArr.length === 4) {
const pageTitle = document.querySelector(
"h2.border-slate-500"
)?.textContent;
presenceData.details =
document.querySelector("h2.border-slate-500")?.textContent === "Anime"
pageTitle === "Anime"
? "Regarde la page de l'anime"
: "Regarde la page du manga";
presenceData.state = document
Expand All @@ -53,6 +58,13 @@ presence.on("UpdateData", async () => {
presenceData.largeImageKey =
document.querySelector<HTMLMetaElement>("[property='og:image']")
?.content ?? Assets.Logo;
if (privacyMode) {
delete presenceData.state;
presenceData.details =
pageTitle === "Anime"
? "Regarde la page d'un anime"
: "Regarde la page d'un manga";
}
} else if (document.querySelector<HTMLSelectElement>("#selectEpisodes")) {
const season = document.querySelector("#avOeuvre").textContent,
selectEps = document.querySelector<HTMLSelectElement>("#selectEpisodes"),
Expand All @@ -61,21 +73,33 @@ presence.on("UpdateData", async () => {
presenceData.details = `Regarde ${
document.querySelector("#titreOeuvre").textContent
}`;
const [startTimestamp, endTimestamp] = presence.getTimestamps(
video.currentTime,
video.duration
);
presenceData.state = `${season ? `${season} - ` : ""}${
selectEps.options[selectEps.selectedIndex].value
}`;

presenceData.buttons = [{ label: "Voir l'Anime", url: href }];
presenceData.smallImageKey = Assets.Pause;
presenceData.smallImageKey = video.paused ? Assets.Pause : Assets.Play;
presenceData.smallImageText =
selectLecteur.options[selectLecteur.selectedIndex].value;
presenceData.largeImageKey =
document.querySelector<HTMLMetaElement>("[property='og:image']")
?.content ?? Assets.Logo;
if (!paused) {
[presenceData.startTimestamp, presenceData.endTimestamp] =
presence.getTimestamps(currentTime, duration);
presenceData.smallImageKey = Assets.Play;
[presenceData.startTimestamp, presenceData.endTimestamp] = [
startTimestamp,
endTimestamp,
];
if (video.paused) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
if (privacyMode) {
delete presenceData.state;
delete presenceData.smallImageKey;
presenceData.details = "Regarde un anime";
}
} else {
const selectChapitres =
Expand All @@ -94,10 +118,19 @@ presence.on("UpdateData", async () => {
presenceData.largeImageKey =
document.querySelector<HTMLMetaElement>("[property='og:image']")
?.content ?? Assets.Logo;
if (privacyMode) {
delete presenceData.state;
delete presenceData.smallImageKey;
presenceData.details = "Lit un manga";
}
}

if (!showButtons) delete presenceData.buttons;
if (!showCover) presenceData.largeImageKey = Assets.Logo;
if (!showButtons || privacyMode) delete presenceData.buttons;
if (!showTimestamps) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
if (!showCover || privacyMode) presenceData.largeImageKey = Assets.Logo;
if (presenceData.details) presence.setActivity(presenceData);
else presence.setActivity();
});
Loading