|
1 | 1 | function loadScript(src) { |
2 | | - return new Promise((resolve, reject) => { |
3 | | - try { |
4 | | - const tag = document.createElement("script"); |
5 | | - tag.async = true; |
6 | | - tag.src = src; |
7 | | - tag.addEventListener("load", () => resolve()); |
8 | | - tag.addEventListener("error", () => reject()); |
9 | | - document.head.appendChild(tag); |
10 | | - } catch (error) { |
11 | | - reject(error); |
12 | | - } |
13 | | - }); |
| 2 | + return new Promise((resolve, reject) => { |
| 3 | + try { |
| 4 | + const tag = document.createElement("script"); |
| 5 | + tag.async = true; |
| 6 | + tag.src = src; |
| 7 | + tag.addEventListener("load", () => resolve()); |
| 8 | + tag.addEventListener("error", () => reject()); |
| 9 | + document.head.appendChild(tag); |
| 10 | + } catch (error) { |
| 11 | + reject(error); |
| 12 | + } |
| 13 | + }); |
14 | 14 | } |
15 | 15 |
|
16 | 16 | function initClock() { |
17 | | - const svg = document.querySelector("svg"); |
18 | | - const text = document.querySelector("text"); |
19 | | - const formatter = new Intl.DateTimeFormat("en-US", { |
20 | | - timeStyle: "medium", |
21 | | - hourCycle: "h23", |
22 | | - }); |
| 17 | + const svg = document.querySelector("svg"); |
| 18 | + const text = document.querySelector("text"); |
| 19 | + const formatter = new Intl.DateTimeFormat("en-US", { |
| 20 | + timeStyle: "medium", |
| 21 | + hourCycle: "h23", |
| 22 | + }); |
23 | 23 |
|
24 | | - function updateTime() { |
25 | | - text.textContent = formatter.format(new Date()); |
26 | | - svg.setAttribute("viewBox", `0 -12 ${Math.ceil(text.getBBox().width)} 13`); |
27 | | - requestAnimationFrame(updateTime); |
28 | | - } |
29 | | - updateTime(); |
| 24 | + function updateTime() { |
| 25 | + text.textContent = formatter.format(new Date()); |
| 26 | + svg.setAttribute("viewBox", `0 -12 ${Math.ceil(text.getBBox().width)} 13`); |
| 27 | + requestAnimationFrame(updateTime); |
| 28 | + } |
| 29 | + updateTime(); |
30 | 30 | } |
31 | 31 |
|
32 | 32 | async function initReceiver() { |
33 | | - await loadScript("//www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js"); |
34 | | - const options = new cast.framework.CastReceiverOptions(); |
35 | | - options.disableIdleTimeout = true; |
36 | | - cast.framework.CastReceiverContext.getInstance().start(options); |
| 33 | + await loadScript("//www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js"); |
| 34 | + const options = new cast.framework.CastReceiverOptions(); |
| 35 | + options.disableIdleTimeout = true; |
| 36 | + cast.framework.CastReceiverContext.getInstance().start(options); |
37 | 37 | } |
38 | 38 |
|
39 | 39 | async function initSender() { |
40 | | - window["__onGCastApiAvailable"] = (isAvailable) => { |
41 | | - if (isAvailable) { |
42 | | - cast.framework.CastContext.getInstance().setOptions({ |
43 | | - receiverApplicationId: "F65B2EC2", |
44 | | - autoJoinPolicy: chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED, |
45 | | - }); |
46 | | - document.body.appendChild(document.createElement("google-cast-launcher")); |
47 | | - } |
48 | | - }; |
49 | | - await loadScript("//www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"); |
| 40 | + window["__onGCastApiAvailable"] = (isAvailable) => { |
| 41 | + if (isAvailable) { |
| 42 | + cast.framework.CastContext.getInstance().setOptions({ |
| 43 | + receiverApplicationId: "F65B2EC2", |
| 44 | + autoJoinPolicy: chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED, |
| 45 | + }); |
| 46 | + document.body.appendChild(document.createElement("google-cast-launcher")); |
| 47 | + } |
| 48 | + }; |
| 49 | + await loadScript("//www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"); |
50 | 50 | } |
51 | 51 |
|
52 | 52 | initClock(); |
53 | 53 | if (navigator.userAgent.includes("CrKey")) { |
54 | | - initReceiver(); |
| 54 | + initReceiver(); |
55 | 55 | } else { |
56 | | - initSender(); |
| 56 | + initSender(); |
57 | 57 | } |
0 commit comments