Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/components/SearchVideos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ type Video = {
iframe_src: string;
};

const getPlayableIframeSrc = (iframeSrc: string) => {
try {
const url = new URL(iframeSrc);

if (url.hostname.endsWith('youtube-nocookie.com')) {
url.hostname = 'www.youtube.com';
}

url.searchParams.set('enablejsapi', '1');

return url.toString();
} catch {
return `${iframeSrc}${iframeSrc.includes('?') ? '&' : '?'}enablejsapi=1`;
}
};

declare module 'yet-another-react-lightbox' {
export interface VideoSlide extends GenericSlide {
type: 'video-slide';
Expand Down Expand Up @@ -199,7 +215,7 @@ const Searchvideos = ({
return slide.type === 'video-slide' ? (
<div className="h-full w-full flex flex-row items-center justify-center">
<iframe
src={`${slide.iframe_src}${slide.iframe_src.includes('?') ? '&' : '?'}enablejsapi=1`}
src={getPlayableIframeSrc(slide.iframe_src)}
ref={(el) => {
if (el) {
videoRefs.current[index] = el;
Expand Down