-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtube.js
36 lines (29 loc) · 1.22 KB
/
youtube.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
32
33
34
35
36
/**
* @copyright 2023 Chris Zuber <admin@kernvalley.us>
*/
import { createIframe } from './elements.js';
import { getYouTubePolicy } from './trust-policies.js';
export const allow = ['accelerometer', 'encrypted-media', 'gyroscope', 'picture-in-picture', 'fullscreen'];
export const sandbox = ['allow-scripts', 'allow-popups', 'allow-same-origin', 'allow-presentation'];
export const cookie = 'https://www.youtube.com/embed/';
export const noCookie = 'https://www.youtube-nocookie.com/embed/';
export const policy = getYouTubePolicy();
export function createYouTubeEmbed(video, {
height, width, fetchPriority = 'low', referrerPolicy = 'origin',
title = 'YouTube Embedded Video', loading = 'lazy', credentialless = true,
controls = true, start,
} = {}) {
const src = credentialless
? new URL(`./${encodeURIComponent(video)}`, noCookie) : new URL(`./${encodeURIComponent(video)}`, cookie);
if (! controls) {
src.searchParams.set('controls', '0');
}
if (Number.isSafeInteger(start) && start > 0) {
src.searchParams.set('start', start);
}
return createIframe(src.href, {
width, height, loading, title, fetchPriority, referrerPolicy, allow,
sandbox, policy, credentialless,
});
}
export const trustPolicies = [policy.name];