mirror of
https://github.com/misskey-dev/summerflare.git
synced 2025-08-02 22:56:26 +09:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { assign } from "../common";
|
|
import type { PrioritizedReference } from "../common";
|
|
|
|
export default function getPlayerUrlHeight(url: URL, html: HTMLRewriter) {
|
|
const result: PrioritizedReference<string | null> = {
|
|
bits: 2, // 0-3
|
|
priority: 0,
|
|
content: null,
|
|
};
|
|
html.on('meta[property="twitter:player:height"]', {
|
|
element(element) {
|
|
const content = element.getAttribute("content");
|
|
if (content) {
|
|
assign(result, 3, content);
|
|
}
|
|
},
|
|
});
|
|
html.on('meta[name="twitter:player:height"]', {
|
|
element(element) {
|
|
const content = element.getAttribute("content");
|
|
if (content) {
|
|
assign(result, 2, content);
|
|
}
|
|
},
|
|
});
|
|
html.on('meta[property="og:video:height"]', {
|
|
element(element) {
|
|
const content = element.getAttribute("content");
|
|
if (content) {
|
|
assign(result, 1, content);
|
|
}
|
|
},
|
|
});
|
|
return new Promise<number | null>((resolve) => {
|
|
html.onDocument({
|
|
end() {
|
|
const content = parseInt(result.content!, 10);
|
|
resolve(Number.isNaN(content) ? null : content);
|
|
},
|
|
});
|
|
});
|
|
}
|