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.
Dernier runAucun
0Étoiles
0Forks
2Issues
| 1 | /** |
| 2 | * The page half of the lite-youtube smoke (see lite-youtube.html). Imports |
| 3 | * the shipped dist bundle, checks the 16:9 box and the 44px play badge and |
| 4 | * that no request went to YouTube, then activates the link and checks the |
| 5 | * player that took its place. The iframe's own load is not awaited: the |
| 6 | * smoke needs no network. |
| 7 | */ |
| 8 | export {}; // a module: the page awaits at its top level |
| 9 | |
| 10 | await import("../dist/lite-youtube.js"); |
| 11 | await new Promise(resolve => setTimeout(resolve, 50)); |
| 12 | |
| 13 | const host = document.querySelector("pebble-lite-youtube") as HTMLElement; |
| 14 | const ratio = (el: Element) => el.getBoundingClientRect().width / el.getBoundingClientRect().height; |
| 15 | // by host: the page's own bundle is named after the package |
| 16 | const fromYouTube = () => |
| 17 | performance.getEntriesByType("resource").filter(e => /(youtube|ytimg|googlevideo|ggpht)\./.test(new URL(e.name).hostname)).length; |
| 18 | const posterRatio = ratio(host); |
| 19 | const badge = host.querySelector(".play")!.getBoundingClientRect(); |
| 20 | const requestsBefore = fromYouTube(); |
| 21 | |
| 22 | host.querySelector("a")!.click(); |
| 23 | const iframe = host.querySelector("iframe"); |
| 24 | const verdict = { |
| 25 | checks: { |
| 26 | registered: customElements.get("pebble-lite-youtube") !== undefined, |
| 27 | "the poster box is 16:9": Math.abs(posterRatio - 16 / 9) < 0.02, |
| 28 | "the play badge is at least 44px": badge.width >= 44 && badge.height >= 44, |
| 29 | "nothing came from YouTube before the click": requestsBefore === 0, |
| 30 | "the click put the nocookie player in": iframe?.src === "https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?autoplay=1&playsinline=1", |
| 31 | "the player is named": iframe?.title === "Bande-annonce : Maman, j’ai raté l’avion", |
| 32 | "the player may autoplay and go fullscreen": iframe?.allow === "autoplay; encrypted-media; picture-in-picture" && iframe.allowFullscreen, |
| 33 | "the player fills the 16:9 box": iframe !== null && Math.abs(ratio(iframe) - 16 / 9) < 0.02 && Math.abs(ratio(host) - 16 / 9) < 0.02, |
| 34 | "focus moved into the player": document.activeElement === iframe, |
| 35 | }, |
| 36 | observed: { posterRatio, badge: [badge.width, badge.height], requestsBefore, src: iframe?.src }, |
| 37 | }; |
| 38 | document.getElementById("smoke")!.textContent = `SMOKE:${JSON.stringify(verdict)}`; |