Skip to content

Commit

Permalink
feat(meow.camera): added presense (#8187)
Browse files Browse the repository at this point in the history
feat(meow.camrea): added presense
  • Loading branch information
AzureToast authored Mar 19, 2024
1 parent 6d4daf4 commit e9f6800
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
25 changes: 25 additions & 0 deletions websites/M/meow.camera/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://schemas.premid.app/metadata/1.10",
"author": {
"id": "189682724334862336",
"name": "azuretst"
},
"service": "meow.camera",
"description": {
"en": "meow.camera is an alternative viewer for feeders from the Hello Street Cat / JieMao (街猫) app."
},
"url": "meow.camera",
"matches": [
"*://meow.camera/*"
],
"version": "1.0.0",
"logo": "https://i.postimg.cc/GhMJx6PB/logo.png",
"thumbnail": "https://i.postimg.cc/GhshXyGk/Screenshot-1.jpg",
"color": "#000000",
"category": "videos",
"tags": [
"cats",
"livestream",
"video"
]
}
52 changes: 52 additions & 0 deletions websites/M/meow.camera/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const presence = new Presence({
clientId: "1219194850767929374",
});
let browsingTimestamp = Math.floor(Date.now() / 1000);

const enum Assets {
Logo = "https://i.postimg.cc/GhMJx6PB/logo.png",
}

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: Assets.Logo,
startTimestamp: browsingTimestamp,
};

presenceData.details = document.querySelector(".feeder-title").textContent;
presenceData.state = getStats();
setTimestamps(document.querySelector("video"), presenceData);
presenceData.buttons = [
{
label: "View Feeder",
url: document.location.href,
},
];
presence.setActivity(presenceData);
});

function getStats(): string {
let stats = "";
const snack = document.querySelector("[title='Snack stock']"),
kibble = document.querySelector("[title='Kibble stock']"),
temp = document.querySelector("[title='Feeder temperature']");

if (!snack || !kibble || !temp) return stats;

stats = `🍪: ${snack.textContent === "" ? "🚫" : snack.textContent} | 🍿: ${
kibble.textContent === "" ? "🚫" : kibble.textContent
} | 🌡️: ${temp.textContent === "" ? "🚫" : temp.textContent} `;

return stats;
}

function setTimestamps(
element: HTMLVideoElement,
presenceData: PresenceData
): void {
if (element.paused) {
delete presenceData.startTimestamp;
browsingTimestamp = Math.floor(Date.now() / 1000);
presenceData.smallImageKey = Assets.Pause;
} else presenceData.smallImageKey = Assets.Live;
}

0 comments on commit e9f6800

Please sign in to comment.