File tree Expand file tree Collapse file tree
apps/site/src/components/portable-text Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -199,7 +199,7 @@ const components = {
199199 // until a visitor actually asks for it.
200200 const play = target.closest("button");
201201 const embed = play?.closest<HTMLElement>(".yt-embed");
202- if (!play || !embed) {
202+ if (!play || !embed || embed.querySelector("iframe") ) {
203203 return;
204204 }
205205 const id = embed.dataset.yt;
Original file line number Diff line number Diff line change @@ -136,3 +136,32 @@ const alt = rawAlt && rawAlt.trim().length > 0 ? rawAlt : "";
136136 </div >
137137 )
138138}
139+
140+ <script >
141+ if (!(window as unknown as { __ccYtEmbedInit?: boolean }).__ccYtEmbedInit) {
142+ (window as unknown as { __ccYtEmbedInit?: boolean }).__ccYtEmbedInit = true;
143+ document.addEventListener("click", (event) => {
144+ const target = event.target;
145+ if (!(target instanceof Element)) {
146+ return;
147+ }
148+ const play = target.closest("button");
149+ const embed = play?.closest<HTMLElement>(".yt-embed");
150+ if (!play || !embed || embed.querySelector("iframe")) {
151+ return;
152+ }
153+ const id = embed.dataset.yt;
154+ if (!id) {
155+ return;
156+ }
157+ const iframe = document.createElement("iframe");
158+ iframe.src = `https://www.youtube-nocookie.com/embed/${id}?autoplay=1&rel=0&modestbranding=1&fs=0`;
159+ iframe.allow =
160+ "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share";
161+ iframe.allowFullscreen = true;
162+ iframe.title = "YouTube video player";
163+ iframe.className = "absolute inset-0 size-full border-0";
164+ embed.replaceChildren(iframe);
165+ });
166+ }
167+ </script >
You can’t perform that action at this time.
0 commit comments