-
Notifications
You must be signed in to change notification settings - Fork 195
/
VimeoVideo.ts
49 lines (44 loc) · 1.29 KB
/
VimeoVideo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import getOriginData from "../originData";
import { findLightningAddressInText, setLightningData } from "./helpers";
const urlMatcher = /^https:\/\/vimeo.com\/.*\d{4,}\/?$/;
const battery = (): void => {
const videoDescription = document.querySelector("[data-description-content]");
const channelLink = document.querySelector(
".clip_info-subline--watch .js-user_link"
);
if (!videoDescription || !channelLink) {
return;
}
const text = videoDescription.textContent || "";
let match;
let recipient;
// check for an lnurl
if ((match = text.match(/(lnurlp:)(\S+)/i))) {
recipient = match[2];
}
// if there is no lnurl we check for a zap emoji with a lightning address
// we check for the @-sign to try to limit the possibility to match some invalid text (e.g. random emoji usage)
else if ((match = findLightningAddressInText(text))) {
recipient = match;
} else {
return;
}
const name = channelLink.textContent || "";
const imageUrl =
document.querySelector<HTMLImageElement>(".clip_info-subline--watch img")
?.src || "";
setLightningData([
{
method: "lnurl",
address: recipient,
...getOriginData(),
name,
icon: imageUrl,
},
]);
};
const VimeoVideo = {
urlMatcher,
battery,
};
export default VimeoVideo;