-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (29 loc) · 845 Bytes
/
index.js
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
import cp from 'node:child_process';
import alfy from 'alfy';
// Get either the Script Filter input or from the clipboard
const input = alfy.input || cp.spawnSync('pbpaste', {
encoding: 'utf8',
}).stdout;
try {
const regex = /(?:youtube.[a-z]+\/[a-z?&]*v[/|=]|youtu.be\/)([\w-]+)/g;
const youtubeLinkParts = regex.exec(input.trim());
const youtubeLink = `youtu.be/${youtubeLinkParts[1]}`.trim();
const youtubeLinkHttps = `https://${youtubeLink}`;
alfy.output([
{
title: `YT Share Link: ${youtubeLinkHttps}`,
subtitle: 'Copy to Clipboard',
arg: youtubeLinkHttps,
},
{
title: `YT Share Link: ${youtubeLink}`,
subtitle: 'Copy to Clipboard',
arg: youtubeLink,
},
]);
} catch {
alfy.output([{
title: 'YT Share Link: Last clipboard entry is not a valid youtube link.',
subtitle: 'Please try again…',
}]);
}