forked from PreMiD/Presences
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AniMi Club): add presence (PreMiD#7983)
- Loading branch information
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const iframe = new iFrame(); | ||
|
||
iframe.on("UpdateData", async () => { | ||
if (document.querySelector("video")) { | ||
const video: HTMLVideoElement = | ||
document.querySelector<HTMLVideoElement>("video"); | ||
|
||
if (video && !isNaN(video.duration)) { | ||
iframe.send({ | ||
duration: video.duration, | ||
currentTime: video.currentTime, | ||
paused: video.paused, | ||
}); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.9", | ||
"author": { | ||
"id": "546262814424170498", | ||
"name": "official_riktik" | ||
}, | ||
"service": "AniMi Club", | ||
"description": { | ||
"en": "Watch anime online for free. Large database of the best anime with russian voiceover in good quality.", | ||
"ru": "Смотреть аниме онлайн бесплатно. Большая база лучших аниме с русской озвучкой в хорошем качестве.", | ||
"uk_UA": "Дивитися аніме онлайн безкоштовно. Велика база найкращих аніме з російською озвучкою в хорошій якості." | ||
}, | ||
"url": [ | ||
"animi.club", | ||
"www.animi.club", | ||
"dev.animi.club" | ||
], | ||
"version": "1.0.0", | ||
"logo": "https://i.imgur.com/BZtDh0g.png", | ||
"thumbnail": "https://i.imgur.com/Anc197L.png", | ||
"color": "#e11d48", | ||
"category": "anime", | ||
"tags": [ | ||
"anime", | ||
"аниме", | ||
"animi", | ||
"аними", | ||
"animiclub", | ||
"анимиклаб" | ||
], | ||
"iframe": true, | ||
"iFrameRegExp": ".*", | ||
"settings": [ | ||
{ | ||
"id": "privacy", | ||
"title": "Приватный режим", | ||
"icon": "fad fa-user-secret", | ||
"value": false | ||
}, | ||
{ | ||
"id": "time", | ||
"title": "Показывать оставшееся время просмотра", | ||
"icon": "fad fa-stopwatch", | ||
"value": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
const presence = new Presence({ | ||
clientId: "1127599137374871563", | ||
}); | ||
|
||
const enum Assets { | ||
Logo = "https://i.imgur.com/BZtDh0g.png", | ||
} | ||
|
||
interface VideoData { | ||
duration: number; | ||
currentTime: number; | ||
paused: boolean; | ||
} | ||
|
||
async function getStrings() { | ||
return presence.getStrings({ | ||
play: "general.playing", | ||
pause: "general.paused", | ||
browse: "general.browsing", | ||
viewPage: "general.viewPage", | ||
page: "general.page", | ||
}); | ||
} | ||
|
||
let strings: Awaited<ReturnType<typeof getStrings>>, | ||
video: VideoData = { | ||
duration: 0, | ||
currentTime: 0, | ||
paused: true, | ||
}; | ||
|
||
presence.on("iFrameData", (data: VideoData) => { | ||
video = data; | ||
}); | ||
|
||
presence.on("UpdateData", async () => { | ||
const [privacy, time] = await Promise.all([ | ||
presence.getSetting<boolean>("privacy"), | ||
presence.getSetting<boolean>("time"), | ||
]), | ||
presenceData: PresenceData = { | ||
details: "Где-то на сайте", | ||
largeImageKey: Assets.Logo, | ||
smallImageText: "AniMi Club", | ||
}; | ||
|
||
if (!strings) strings = await getStrings(); | ||
|
||
const typeCurrent = | ||
document | ||
.querySelector("meta[property='og:url']") | ||
.getAttribute("content") | ||
.split("/")[3] === "anime" | ||
? "аниме" | ||
: "манга"; | ||
|
||
if (document.location.pathname === "/") | ||
presenceData.details = "На главной странице"; | ||
else if (document.location.pathname.match(/\/(anime|manga)\//)) { | ||
const title = | ||
document | ||
.querySelector("meta[property='og:title']") | ||
?.getAttribute("content") ?? "Неизвестное название"; | ||
|
||
presenceData.details = `Смотрит страницу ${typeCurrent}`; | ||
|
||
if (!privacy) { | ||
presenceData.state = `«${title}»`; | ||
|
||
presenceData.buttons = [ | ||
{ | ||
label: "Смотреть страницу", | ||
url: | ||
document | ||
.querySelector("meta[property='og:url']") | ||
?.getAttribute("content") || "", | ||
}, | ||
]; | ||
} | ||
|
||
if (video.duration) { | ||
presenceData.smallImageKey = video.paused ? Assets.Play : Assets.Pause; | ||
presenceData.smallImageText = video.paused ? strings.play : strings.pause; | ||
|
||
if (time) { | ||
if (video.paused) { | ||
delete presenceData.startTimestamp; | ||
delete presenceData.endTimestamp; | ||
} else { | ||
[presenceData.startTimestamp, presenceData.endTimestamp] = | ||
presence.getTimestamps(video.currentTime, video.duration); | ||
} | ||
} | ||
} | ||
} | ||
|
||
presence.setActivity(presenceData); | ||
}); |