This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"id": "primevideo",
|
||||||
|
"name": "Prime Video",
|
||||||
|
"description": "Shows the title you're watching on Amazon Prime Video.",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"author": "hibna",
|
||||||
|
"match": [
|
||||||
|
"https://www.primevideo.com/*",
|
||||||
|
"https://www.amazon.com/gp/video/*",
|
||||||
|
"https://www.amazon.com/-/*/gp/video/*",
|
||||||
|
"https://www.amazon.co.uk/gp/video/*",
|
||||||
|
"https://www.amazon.de/gp/video/*"
|
||||||
|
],
|
||||||
|
"tickInterval": 1500,
|
||||||
|
"sdkVersion": "^0.1.0"
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import { ActivityType, definePresence } from "@source/presence-sdk";
|
||||||
|
|
||||||
|
function findVideo(): HTMLVideoElement | null {
|
||||||
|
return document.querySelector<HTMLVideoElement>(
|
||||||
|
"video.webPlayerElement, video.rendererContainer__video, video[src], video",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPlayerOpen(): boolean {
|
||||||
|
if (document.querySelector(".webPlayerSDKContainer")) return true;
|
||||||
|
if (document.querySelector("[data-automation-id='webPlayer']")) return true;
|
||||||
|
return /\/(detail|gp\/video\/detail)\//.test(location.pathname) === false &&
|
||||||
|
document.querySelector("video") !== null &&
|
||||||
|
location.pathname.includes("/video/");
|
||||||
|
}
|
||||||
|
|
||||||
|
function readPlayerTitle(): string | null {
|
||||||
|
const candidates = [
|
||||||
|
"h1.atvwebplayersdk-title-text",
|
||||||
|
".atvwebplayersdk-title-text",
|
||||||
|
"[data-automation-id='title']",
|
||||||
|
".webPlayerSDKContainer h1",
|
||||||
|
];
|
||||||
|
for (const sel of candidates) {
|
||||||
|
const node = document.querySelector<HTMLElement>(sel);
|
||||||
|
const text = node?.textContent?.trim();
|
||||||
|
if (text) return text;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readPlayerSubtitle(): string | null {
|
||||||
|
const candidates = [
|
||||||
|
".atvwebplayersdk-subtitle-text",
|
||||||
|
"[data-automation-id='subtitle']",
|
||||||
|
];
|
||||||
|
for (const sel of candidates) {
|
||||||
|
const node = document.querySelector<HTMLElement>(sel);
|
||||||
|
const text = node?.textContent?.trim();
|
||||||
|
if (text) return text;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readDetailTitle(): string | null {
|
||||||
|
const node =
|
||||||
|
document.querySelector<HTMLElement>("[data-automation-id='title']") ??
|
||||||
|
document.querySelector<HTMLElement>("h1");
|
||||||
|
return node?.textContent?.trim() ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function browsingLabel(): string {
|
||||||
|
const path = location.pathname;
|
||||||
|
if (/\/(detail|gp\/video\/detail)\//.test(path)) return "Viewing title";
|
||||||
|
if (path.includes("/search/") || location.search.includes("phrase=")) return "Searching";
|
||||||
|
if (path.includes("/storefront/")) return "Browsing store";
|
||||||
|
if (path.includes("/library/") || path.includes("/watchlist")) return "Browsing watchlist";
|
||||||
|
return "Browsing";
|
||||||
|
}
|
||||||
|
|
||||||
|
export default definePresence({
|
||||||
|
match: [
|
||||||
|
"https://www.primevideo.com/*",
|
||||||
|
"https://www.amazon.com/gp/video/*",
|
||||||
|
"https://www.amazon.com/-/*/gp/video/*",
|
||||||
|
"https://www.amazon.co.uk/gp/video/*",
|
||||||
|
"https://www.amazon.de/gp/video/*",
|
||||||
|
],
|
||||||
|
tickInterval: 1500,
|
||||||
|
tick(ctx) {
|
||||||
|
const video = findVideo();
|
||||||
|
if (video && isPlayerOpen()) {
|
||||||
|
const title = readPlayerTitle();
|
||||||
|
if (!title) {
|
||||||
|
ctx.setActivity({
|
||||||
|
type: ActivityType.WATCHING,
|
||||||
|
name: "Prime Video",
|
||||||
|
details: "Loading…",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const subtitle = readPlayerSubtitle();
|
||||||
|
const paused = video.paused;
|
||||||
|
const remainingMs =
|
||||||
|
Number.isFinite(video.duration) && video.duration > 0
|
||||||
|
? Math.floor((video.duration - video.currentTime) * 1000)
|
||||||
|
: null;
|
||||||
|
ctx.setActivity({
|
||||||
|
type: ActivityType.WATCHING,
|
||||||
|
name: "Prime Video",
|
||||||
|
details: title,
|
||||||
|
state: subtitle
|
||||||
|
? `${paused ? "Paused" : "Watching"} · ${subtitle}`
|
||||||
|
: paused
|
||||||
|
? "Paused"
|
||||||
|
: "Watching",
|
||||||
|
url: location.href,
|
||||||
|
startedAt: paused ? null : Date.now() - Math.floor(video.currentTime * 1000),
|
||||||
|
endsAt: paused || remainingMs === null ? null : Date.now() + remainingMs,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/\/(detail|gp\/video\/detail)\//.test(location.pathname)) {
|
||||||
|
const title = readDetailTitle();
|
||||||
|
ctx.setActivity({
|
||||||
|
type: ActivityType.WATCHING,
|
||||||
|
name: "Prime Video",
|
||||||
|
details: title ? `Viewing ${title}` : "Viewing title",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.setActivity({
|
||||||
|
type: ActivityType.WATCHING,
|
||||||
|
name: "Prime Video",
|
||||||
|
details: browsingLabel(),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user