Skip to content

Commit

Permalink
auto play for youtube as default
Browse files Browse the repository at this point in the history
  • Loading branch information
softmarshmallow committed Mar 29, 2022
1 parent b381d8e commit 9eec1cc
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,31 @@ export class HtmlIframeYoutube extends HtmlIframe {
loading,
sandbox,
referrerpolicy,
src: yturl(video),
src: yturl(video, { autoplay: true }),
});
}
}

function yturl(video: string): string {
function yturl(
video: string,
opt?: {
autoplay?: boolean;
}
): string {
const q = {};

if (opt?.autoplay) {
q["autoplay"] = "1";
}

if (Object.keys(q).length > 0) {
return `https://www.youtube.com/embed/${video}?${buildq(q)}`;
}

return `https://www.youtube.com/embed/${video}`;
}

const buildq = (q: object): string =>
Object.keys(q)
.map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(q[k])}`)
.join("&");

0 comments on commit 9eec1cc

Please sign in to comment.