-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(meow.camera): added presense (#8187)
feat(meow.camrea): added presense
- Loading branch information
1 parent
6d4daf4
commit e9f6800
Showing
2 changed files
with
77 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,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" | ||
] | ||
} |
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,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; | ||
} |