EmbedKing · embed library

Configuration reference

How to load embed.js and configure the carousel with window.EmbedKingYtWidgetConfig and optional EmbedKingYoutube.init().

Loading the embed

Set configuration on window before the script runs, then load embed.js from the same base URL you pass as apiBaseUrl (or a copy you host):

<!-- Set config before the script loads -->
<script>
  window.EmbedKingYtWidgetConfig = {
    apiBaseUrl: "https://embedking-youtube.ego-348.workers.dev",
    apiToken: "YOUR_TOKEN",
    // …see EmbedKingYtWidgetConfig below
  };
</script>
<script src="https://embedking-youtube.ego-348.workers.dev/embed.js" async></script>

After load, you can merge or override options programmatically:

window.EmbedKingYoutube?.init({
  carouselBreakpoints: [768, 1024],
});

init merges into the existing config, re-injects carousel CSS when relevant, and updates window.EmbedKingYtWidgetConfig.

EmbedKingYtWidgetConfig

All fields are optional unless a mode requires them. Set this object before loading the script, or pass a partial object to EmbedKingYoutube.init().

PropertyTypeDefaultDescription
apiBaseUrlstringorigin of script URLBase URL of the EmbedKing deployment (no trailing slash). The script loads data from this host.
apiTokenstring—Token included with data requests from the embed. Use the value issued for your deployment.
youtubeApiKeystring—YouTube Data API key for playlist blocks and legacy stats UI when not using the RSS-only carousel path.
channelIdstring—Channel id for the default single-channel carousel when you are not using carouselSources.
playlistIdsstring[]—Playlist ids for legacy #playlist-1 … #playlist-n rows when not using carouselSources.
carouselSourcesEmbedKingCarouselSource[]—When set, the carousel loads merged feeds from multiple channels/playlists. When omitted or empty, the carousel uses the default single-channel feed from the deployment.
carouselFeedModeEmbedKingCarouselFeedMode"mixed"How multiple sources are merged when layout is single. Ignored when carouselLayout is multiRow.
carouselLayoutEmbedKingCarouselLayout"single"single: one carousel with merged ordering. multiRow: one horizontal row per carouselSources entry (three videos per row, separate arrows).
statsChannelIdstring—Channel id used for subscriber / view / video counts when using carouselSources (if not set, the first channel source is used).
carouselBreakpointsnumber[][768]Viewport widths (px) where layout may change. On resize, the carousel re-renders only when crossing a boundary — not on every pixel. Single-column mobile carousel when innerWidth ≤ max(breakpoints).
carouselRootstring | HTMLElement—Container for the widget: CSS selector or element. If omitted, the first .ytw-container in the document.
carouselModeEmbedKingCarouselMode"manual"manual: you provide markup. html: set carouselHtml. default: generated from defaultWidget.
carouselHtmlstring—Full HTML when carouselMode is html.
defaultWidgetEmbedKingDefaultWidgetContent—Channel links, labels, logo when carouselMode is default.
carouselFocusOnPlaybooleantrueIf true, loads the IFrame API and on play dims the page and focuses the video. Not used when carouselLayout is multiRow.
injectCarouselStylesbooleantrueIf false, default .ytw-* CSS is not injected — you style the widget yourself.
carouselStylesEmbedKingCarouselStyles—Replaces the entire built-in theme. patchCarouselStyles is ignored when set.
patchCarouselStyles(theme) => EmbedKingCarouselStyles—Receives a deep clone of the default theme; return the object to inject. Not used when carouselStyles is set.

Read-only on window: EmbedKingCarouselDefaultStyles — reference the built-in theme (clone before mutating).

EmbedKingDefaultWidgetContent

URLs and copy for the generated header when using default mode.

PropertyTypeDefaultDescription
channelUrlrequiredstring—Main channel URL (logo + title area).
subscribeUrlstring—Subscribe button; defaults to channel URL with sub_confirmation if omitted.
channelVideosUrlstring—“Videos” / channel page link.
logoSrcstring—Logo image URL.
logoAltstring—Alt text for logo.
titleTextstring—Heading text.
subscribeLabelstring—Subscribe button label.
channelButtonLabelstring—Secondary channel button label.
statsLoadingTextstring—Shown in the stats line until numbers load.

Enumerations

EmbedKingCarouselMode

  • manual — You supply markup; container must match expected .ytw-* structure.
  • html — carouselHtml is set as innerHTML.
  • default — Markup built from defaultWidget.

EmbedKingCarouselFeedMode

  • mixed — Concatenate sources in order; global dedupe by video id.
  • interleaved — Round-robin one pick per source; global dedupe.
  • roundRobin — Each carousel “page” is filled by round-robin pulls from sources; no duplicate within a view.

EmbedKingCarouselLayout

  • single — One carousel; merged list from carouselFeedMode.
  • multiRow — One row per carouselSources entry; requires multiple sources in carouselSources and matching markup (e.g. playlist rows).