library
Prebuilt pebble components: drop-in custom elements, no compiler needed
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Lite YouTube (<pebble-lite-youtube>)
A YouTube video as a poster link that becomes the player when activated. Nothing is requested from YouTube before that: no script, no thumbnail, no preconnect. The poster is the page's own image. Self-registering, light DOM.
<link rel="stylesheet" href="/static/pebble/lite-youtube.css">
<script type="module" src="/static/pebble/lite-youtube.js"></script>
<pebble-lite-youtube video="dQw4w9WgXcQ" title="Bande-annonce : Maman, j’ai raté l’avion">
<a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ">
<img src="/affiches/yt-dQw4w9WgXcQ.jpg" alt="Bande-annonce : Maman, j’ai raté l’avion">
<span class="play" aria-hidden="true">▶</span>
</a>
</pebble-lite-youtube>
The markup
| where | what | notes |
|---|---|---|
host video | the YouTube video id | 11 characters of A–Z a–z 0–9 _ -; anything else leaves the link alone (dev warning) |
host title | the player's accessible name | falls back to the poster's alt |
<a href> | the video on YouTube | the no-JS path, and a modified click's |
<img> | the poster, served by the page | covers the 16:9 box (object-fit: cover) |
.play | the play badge | optional; centred, at least 44 px; mark it aria-hidden="true" (the link's name is the poster's alt) |
Behavior
- Activating the link (click, tap, Enter on the focused link) replaces the element's content with an iframe of
https://www.youtube-nocookie.com/embed/<video>?autoplay=1&playsinline=1, withallow="autoplay; encrypted-media; picture-in-picture",allowfullscreen, the title above, andreferrerpolicy="strict-origin-when-cross-origin"(YouTube's embed refuses to play without the embedding origin as referrer; a page whoseReferrer-Policyisno-referrerwould otherwise break it). Focus moves into the player. - A modified click (new tab or window) is the browser's.
- The host is a 16:9 box (
aspect-ratio) before and after;[data-playing]marks it once the player is in. - A page with a Content-Security-Policy needs
frame-src https://www.youtube-nocookie.com.
CSS hooks
The sheet ships as lite-youtube.css (raw: dist/lite-youtube.css, published as @pebble/lite-youtube/lite-youtube.css); link it for the poster's look without JS. Dark defaults from prefers-color-scheme.
--pebble-lite-youtube-backdrop (behind the poster, #000) · --pebble-lite-youtube-radius (0.5rem) · --pebble-lite-youtube-play-surface · --pebble-lite-youtube-play-active (the badge on hover and focus, YouTube red) · --pebble-lite-youtube-play-ink · --pebble-lite-youtube-play-width (4.25rem) · --pebble-lite-youtube-play-height (3rem) · --pebble-lite-youtube-play-radius · --pebble-lite-youtube-focus (falls back to --accent)
The iframe carries part="player".
Exports
VIDEO_ID (the id pattern), embedUrl(id).