@kyun.si/codex-hongguo 0.0.25 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/README.en.md +2 -2
- package/README.md +2 -2
- package/dist/hooks/write.mjs +15 -7
- package/dist/server/index.mjs +40 -32
- package/dist/setup/check.mjs +16 -8
- package/dist/ui/player.html +1 -1
- package/package.json +1 -1
package/dist/ui/player.html
CHANGED
|
@@ -2060,7 +2060,7 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
2060
2060
|
- omitted: host decides border`)}),c3=E.object({method:E.literal("ui/request-display-mode"),params:E.object({mode:fl.describe("The display mode being requested.")})}),GF=E.object({mode:fl.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),KF=E.union([E.literal("model"),E.literal("app")]).describe("Tool visibility scope - who can access the tool."),u3=E.object({resourceUri:E.string().optional(),visibility:E.array(KF).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
2061
2061
|
- "model": Tool visible to and callable by the agent
|
|
2062
2062
|
- "app": Tool callable by the app from this server only`),csp:E.never().optional(),permissions:E.never().optional()}),d3=E.object({mimeTypes:E.array(E.string()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),f3=E.object({method:E.literal("ui/download-file"),params:E.object({contents:E.array(E.union([cS,uS])).describe("Resource contents to download \u2014 embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),h3=E.object({method:E.literal("ui/message"),params:E.object({role:E.literal("user").describe('Message role, currently only "user" is supported.'),content:E.array(Xs).describe("Message content blocks (text, image, etc.).")})}),m3=E.object({method:E.literal("ui/notifications/sandbox-resource-ready"),params:E.object({html:E.string().describe("HTML content to load into the inner iframe."),sandbox:E.string().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:bS.optional().describe("CSP configuration from resource metadata."),permissions:SS.optional().describe("Sandbox permissions from resource metadata.")})}),HF=E.object({method:E.literal("ui/notifications/tool-result"),params:Qs.describe("Standard MCP tool execution result.")}),AA=E.object({toolInfo:E.object({id:Ws.optional().describe("JSON-RPC id of the tools/call request."),tool:wf.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:PF.optional().describe("Current color theme preference."),styles:zF.optional().describe("Style configuration for theming the app."),displayMode:fl.optional().describe("How the UI is currently displayed."),availableDisplayModes:E.array(fl).optional().describe("Display modes the host supports."),containerDimensions:E.union([E.object({height:E.number().describe("Fixed container height in pixels.")}),E.object({maxHeight:E.union([E.number(),E.undefined()]).optional().describe("Maximum container height in pixels.")})]).and(E.union([E.object({width:E.number().describe("Fixed container width in pixels.")}),E.object({maxWidth:E.union([E.number(),E.undefined()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
2063
|
-
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:E.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:E.string().optional().describe("User's timezone in IANA format."),userAgent:E.string().optional().describe("Host application identifier."),platform:E.union([E.literal("web"),E.literal("desktop"),E.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:E.object({touch:E.boolean().optional().describe("Whether the device supports touch input."),hover:E.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:E.object({top:E.number().describe("Top safe area inset in pixels."),right:E.number().describe("Right safe area inset in pixels."),bottom:E.number().describe("Bottom safe area inset in pixels."),left:E.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),ZF=E.object({method:E.literal("ui/notifications/host-context-changed"),params:AA.describe("Partial context update containing only changed fields.")}),p3=E.object({method:E.literal("ui/update-model-context"),params:E.object({content:E.array(Xs).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:E.record(E.string(),E.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),g3=E.object({method:E.literal("ui/initialize"),params:E.object({appInfo:sl.describe("App identification (name and version)."),appCapabilities:VF.describe("Features and capabilities this app provides."),protocolVersion:E.string().describe("Protocol version this app supports.")})}),qF=E.object({protocolVersion:E.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:sl.describe("Host application identification and version."),hostCapabilities:jF.describe("Features and capabilities provided by the host."),hostContext:AA.describe("Rich context about the host environment.")}).passthrough(),WF={target:"draft-2020-12"};async function kA(n,e){let t=n["~standard"];if(t.jsonSchema)return t.jsonSchema[e](WF);if(t.vendor==="zod"){let{z:i}=await Promise.resolve().then(()=>(tl(),Yb));return i.toJSONSchema(n,{io:e})}throw Error(`Schema (vendor: ${t.vendor}) does not implement Standard JSON Schema (~standard.jsonSchema). Use a library that does (zod v4, ArkType, Valibot) or wrap your schema accordingly.`)}async function $A(n,e,t=""){let i=await n["~standard"].validate(e);if(i.issues){let r=i.issues.map(s=>{let o=s.path?.map(a=>typeof a=="object"?a.key:a).join(".");return o?`${o}: ${s.message}`:s.message}).join("; ");throw Error(t+r)}return i.value}function wA(n){let e=document.documentElement;e.setAttribute("data-theme",n),e.style.colorScheme=n}function PA(n,e=document.documentElement){for(let[t,i]of Object.entries(n))i!==void 0&&e.style.setProperty(t,i)}var Rf=class n extends vS{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(e){if(this._initializedSent)return;let t=`[ext-apps] App.${e}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(t);console.warn(`${t}. This will throw in a future release.`)}eventSchemas={toolinput:NF,toolinputpartial:MF,toolresult:HF,toolcancelled:UF,hostcontextchanged:ZF};static ONE_SHOT_EVENTS=new Set(["toolinput","toolinputpartial","toolresult","toolcancelled"]);_everHadListener=new Set;_assertHandlerTiming(e){if(!n.ONE_SHOT_EVENTS.has(e)||this._everHadListener.has(e)||(this._everHadListener.add(e),!this._initializedSent))return;let t=`[ext-apps] "${String(e)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(t);console.warn(t)}setEventHandler(e,t){t&&this._assertHandlerTiming(e),super.setEventHandler(e,t)}addEventListener(e,t){this._assertHandlerTiming(e),super.addEventListener(e,t)}onEventDispatch(e,t){e==="hostcontextchanged"&&(this._hostContext={...this._hostContext,...t})}constructor(e,t={},i={autoResize:!0}){super(i),this._appInfo=e,this._capabilities=t,this.options=i,i.allowUnsafeEval||E.config({jitless:!0}),this.setRequestHandler(Ys,r=>(console.log("Received ping:",r.params),{})),this.setEventHandler("hostcontextchanged",void 0)}registerCapabilities(e){if(this.transport)throw Error("Cannot register capabilities after transport is established");this._capabilities=IA(this._capabilities,e)}registerTool(e,t,i){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let r=this,s=()=>{r._initializedSent&&r._capabilities.tools?.listChanged&&r.sendToolListChanged()},o=t.inputSchema!==void 0,a={title:t.title,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema,annotations:t.annotations,_meta:t._meta,enabled:!0,enable(){this.enabled=!0,s()},disable(){this.enabled=!1,s()},update(l){Object.assign(this,l),s()},remove(){r._registeredTools[e]===a&&(delete r._registeredTools[e],s())},handler:async(l,c)=>{if(!a.enabled)throw Error(`Tool ${e} is disabled`);let u;if(o){let d=a.inputSchema,f=d?await $A(d,l??{},`Invalid input for tool ${e}: `):l??{};u=await i(f,c)}else u=await i(c);return a.outputSchema&&!u.isError&&(u.structuredContent=await $A(a.outputSchema,u.structuredContent,`Invalid output for tool ${e}: `)),u}};return this._registeredTools[e]=a,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),s(),a}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(e,t)=>{let i=this._registeredTools[e.name];if(!i)throw Error(`Tool ${e.name} not found`);return i.handler(e.arguments,t)},this.onlisttools=async(e,t)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([i,r])=>r.enabled).map(async([i,r])=>{let s={name:i,title:r.title,description:r.description,inputSchema:r.inputSchema?await kA(r.inputSchema,"input"):{type:"object",properties:{}}};return r.outputSchema&&(s.outputSchema=await kA(r.outputSchema,"output")),r.annotations&&(s.annotations=r.annotations),r._meta&&(s._meta=r._meta),s}))}))}async sendToolListChanged(e={}){this._assertInitialized("sendToolListChanged"),await this.notification({method:"notifications/tools/list_changed",params:e})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(e){this.setEventHandler("toolinput",e)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(e){this.setEventHandler("toolinputpartial",e)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(e){this.setEventHandler("toolresult",e)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(e){this.setEventHandler("toolcancelled",e)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(e){this.setEventHandler("hostcontextchanged",e)}_onteardown;get onteardown(){return this._onteardown}set onteardown(e){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,e),this._onteardown=e,this.replaceRequestHandler(BF,(t,i)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(t.params,i)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(fS,(t,i)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(t.params,i)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(e){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,e),this._onlisttools=e,this.replaceRequestHandler(dS,(t,i)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(t.params,i)})}assertCapabilityForMethod(e){switch(e){case"sampling/createMessage":if(!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${e})`);break}}assertRequestHandlerCapability(e){switch(e){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${e} registered`)}}assertNotificationCapability(e){}assertTaskCapability(e){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(e){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(e,t){if(this._assertInitialized("callServerTool"),typeof e=="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:e},Qs,{onprogress:()=>{},resetTimeoutOnProgress:!0,...t})}async readServerResource(e,t){return this._assertInitialized("readServerResource"),await this.request({method:"resources/read",params:e},sS,t)}async listServerResources(e,t){return this._assertInitialized("listServerResources"),await this.request({method:"resources/list",params:e},rS,t)}async createSamplingMessage(e,t){this._assertInitialized("createSamplingMessage");let i=e.tools?mS:hS;return await this.request({method:"sampling/createMessage",params:e},i,t)}sendMessage(e,t){return this._assertInitialized("sendMessage"),this.request({method:"ui/message",params:e},OF,t)}sendLog(e){return this.notification({method:"notifications/message",params:e})}updateModelContext(e,t){return this._assertInitialized("updateModelContext"),this.request({method:"ui/update-model-context",params:e},bf,t)}openLink(e,t){return this._assertInitialized("openLink"),this.request({method:"ui/open-link",params:e},DF,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this._assertInitialized("downloadFile"),this.request({method:"ui/download-file",params:e},CF,t)}requestTeardown(e={}){return this.notification({method:"ui/notifications/request-teardown",params:e})}requestDisplayMode(e,t){return this._assertInitialized("requestDisplayMode"),this.request({method:"ui/request-display-mode",params:e},GF,t)}sendSizeChanged(e){return this.notification({method:"ui/notifications/size-changed",params:e})}setupSizeChangedNotifications(){let e=!1,t=0,i=0,r=()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1;let o=document.documentElement,a=o.style.height;o.style.height="max-content";let l=Math.ceil(o.getBoundingClientRect().height);o.style.height=a;let c=Math.ceil(window.innerWidth);(c!==t||l!==i)&&(t=c,i=l,this.sendSizeChanged({width:c,height:l}))}))};r();let s=new ResizeObserver(r);return s.observe(document.documentElement),s.observe(document.body),()=>s.disconnect()}async connect(e=new yS(window.parent,window.parent),t){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");this._initializedSent=!1,await super.connect(e);try{let i=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:AF}},qF,t);if(i===void 0)throw Error(`Server sent invalid initialize result: ${i}`);this._hostCapabilities=i.hostCapabilities,this._hostInfo=i.hostInfo,this._hostContext=i.hostContext,await this.notification({method:"ui/notifications/initialized"}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(i){throw this.close(),i}}};function RA(n,e,t){let i,r=!1,s=()=>{r||i!==void 0||(i=requestAnimationFrame(()=>{i=void 0,!(r||!e())&&t(n.hidden?1:Math.max(1,Math.ceil(n.getBoundingClientRect().height)))}))},o=new ResizeObserver(s);return o.observe(n),s(),{refresh:s,dispose(){r=!0,o.disconnect(),i!==void 0&&cancelAnimationFrame(i)}}}var LA={name:"@kyun.si/codex-hongguo",version:"0.0.25",private:!0,license:"MIT",type:"module",engines:{node:">=22.16"},scripts:{"version:patch":"npm version patch --no-git-tag-version",preversion:"node scripts/version.mjs --next",version:"node scripts/version.mjs --sync",prebuild:"node scripts/version.mjs",build:"node scripts/build.mjs",test:"npm run build && node scripts/prepare-media.mjs && node --test test/*.test.mjs",package:"npm run build && node scripts/package.mjs","verify:install":"node scripts/verify-install.mjs","release:publish":"node scripts/publish.mjs"},dependencies:{"@modelcontextprotocol/ext-apps":"1.7.5","@modelcontextprotocol/sdk":"1.32.2","cross-spawn":"7.0.6",fflate:"0.8.3","hls.js":"1.7.4","m3u8-parser":"7.2.1","mpd-parser":"1.4.1",openhongguo:"0.2.0","xz-decompress":"0.2.3",zod:"4.6.7"},devDependencies:{"@types/node":"22.20.5",esbuild:"0.28.2",typescript:"5.9.3"}};var Bn=document.documentElement.dataset.host==="browser",CA=document.documentElement.dataset.surface==="waiting",_S="",Xn=Bn?null:new Rf({name:"\u7EA2\u679C\u77ED\u5267",version:LA.version},{},{autoResize:!CA}),xS,OA=()=>Xn?.getHostContext()?.locale||navigator.language,Lf=()=>Xn?.getHostContext()?.displayMode;async function NA(){if((await Xn?.requestDisplayMode({mode:"fullscreen"},{timeout:5e3}))?.mode!=="fullscreen")throw Error("\u5F53\u524D Codex \u65E0\u6CD5\u5728\u4F1A\u8BDD\u4E2D\u6253\u5F00\u64AD\u653E\u5668")}function DA(n){n&&(n.theme&&wA(n.theme),n.styles?.variables&&PA(n.styles.variables))}async function MA(n,e,t){if(Bn){let i=await fetch("context",{signal:AbortSignal.timeout(4e3)});if(!i.ok)throw Error("\u5206\u5C4F\u5DF2\u5931\u6548\uFF0C\u8BF7\u4ECE\u9762\u677F\u91CD\u65B0\u6253\u5F00");n(await i.json());return}Xn.ontoolresult=i=>{if(typeof i._meta?.panel!="string")return;_S=i._meta.panel;let r=typeof i._meta.waitingTurn=="string"?i._meta.waitingTurn:void 0;n({identified:!!i.structuredContent?.identified||!!r,waitingTurn:r})},Xn.onteardown=async()=>(xS?.dispose(),await e(),{}),Xn.onhostcontextchanged=i=>{DA(i),i.displayMode!==void 0&&(t(),xS?.refresh())},await Xn.connect(),DA(Xn.getHostContext()),CA&&(xS=RA(document.getElementById("waitingCard"),()=>(Lf()||"inline")==="inline",i=>{Xn.sendSizeChanged({height:i}).catch(()=>{})})),t()}async function Ie(n,e={},t=15e3){if(Bn){let r=await fetch("api/"+n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),keepalive:n==="save_progress",signal:AbortSignal.timeout(t)}),s=await r.json();if(!r.ok)throw Error(s.error||"\u5206\u5C4F\u8FDE\u63A5\u5DF2\u4E2D\u65AD");return s}if(!_S)throw Error("\u7B49\u5F85\u4F1A\u8BDD\u9762\u677F\u8FDE\u63A5");let i=await Xn.callServerTool({name:n,arguments:{...e,panel:_S}},{timeout:t});if(i.isError)throw Error(i.content?.[0]?.type==="text"?i.content[0].text:"\u672C\u673A\u670D\u52A1\u4E0D\u53EF\u8FBE");return i._meta?.data}var ES="https://hongguo.invalid/";function UA(n,e,t,i,r,s){if(!sr.isSupported())throw Error("\u5F53\u524D\u9762\u677F\u4E0D\u652F\u6301\u5206\u6BB5\u89E3\u7801\uFF0C\u53EF\u4F7F\u7528\u540C\u7A97\u5206\u5C4F");class o{context=null;stats=new li;abort(){this.stats.aborted=!0}destroy(){this.abort()}load(d,f,h){this.context=d,this.stats.loading.start=performance.now(),(async()=>{let p=d.url.slice(ES.length);if(!d.url.startsWith(ES))throw Error("\u65E0\u6548\u5A92\u4F53\u6765\u6E90");if(p==="index.m3u8")return i;let g=0,y;do{let b=await Ie("read_panel_chunk",{episodeId:e,stream:t,asset:p,offset:g},8e3);if(this.stats.aborted)return;if(!Number.isSafeInteger(b.size)||b.size<1||b.size>32*1024*1024)throw Error("\u5206\u6BB5\u957F\u5EA6\u65E0\u6548");y??=new Uint8Array(b.size);let S=atob(b.bytes);if(b.size!==y.length||!S.length||g+S.length>b.size)throw Error("\u5206\u6BB5\u4E0D\u5B8C\u6574");for(let x=0;x<S.length;x++)y[g+x]=S.charCodeAt(x);g+=S.length}while(g<y.length);return y.buffer})().then(p=>{this.stats.aborted||p===void 0||(this.stats.loading.first=this.stats.loading.end=performance.now(),this.stats.loaded=this.stats.total=typeof p=="string"?p.length:p.byteLength,h.onSuccess({url:d.url,data:p},this.stats,d,null))}).catch(()=>{this.stats.aborted||h.onError({code:0,text:"\u4FA7\u680F\u5206\u6BB5\u8BFB\u53D6\u5931\u8D25"},d,null,this.stats)})}}let a=new sr({loader:o,enableWorker:!1,maxBufferLength:16,maxMaxBufferLength:24,backBufferLength:12});a.on(sr.Events.MEDIA_ENDED,s),a.on(sr.Events.ERROR,(u,d)=>{d.fatal&&(d.type===sr.ErrorTypes.NETWORK_ERROR?r("\u4FA7\u680F\u5206\u6BB5\u8BFB\u53D6\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u70B9\u64AD"):r("\u4FA7\u680F\u65E0\u6CD5\u5904\u7406\u89C6\u9891\u5206\u6BB5\uFF0C\u53EF\u4F7F\u7528\u540C\u7A97\u5206\u5C4F"))});let l=u=>{u.disposition==="enforce"&&u.effectiveDirective==="media-src"&&(u.blockedURI==="blob"||u.blockedURI.startsWith("blob:"))&&r("\u684C\u9762\u5B89\u5168\u7B56\u7565\u963B\u6B62\u4E86\u4FA7\u680F\u8F7D\u5165\u672C\u5730\u89C6\u9891")},c=()=>{document.removeEventListener("securitypolicyviolation",l),a.destroy()};document.addEventListener("securitypolicyviolation",l);try{a.loadSource(ES+"index.m3u8"),a.attachMedia(n)}catch(u){throw c(),u}return c}function IS(n){switch(n){case 1:return"\u89C6\u9891\u52A0\u8F7D\u5DF2\u4E2D\u6B62\uFF0C\u53EF\u4EE5\u91CD\u65B0\u70B9\u64AD";case 2:return"\u8BFB\u53D6\u89C6\u9891\u6570\u636E\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u70B9\u64AD";case 3:return"\u64AD\u653E\u5668\u89E3\u7801\u89C6\u9891\u6570\u636E\u5931\u8D25\uFF0C\u53EF\u4F7F\u7528\u540C\u7A97\u5206\u5C4F";case 4:return"\u64AD\u653E\u5668\u65E0\u6CD5\u6253\u5F00\u89C6\u9891\u6765\u6E90\uFF0C\u53EF\u91CD\u65B0\u70B9\u64AD\u6216\u4F7F\u7528\u540C\u7A97\u5206\u5C4F";default:return"\u89C6\u9891\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u70B9\u64AD"}}function FA(n,e){return new Promise((t,i)=>{let r=()=>l(),s=()=>l(Error(IS(n.error?.code))),o=()=>l(e.reason),a=setTimeout(()=>l(Error("\u7B49\u5F85\u89C6\u9891\u5143\u6570\u636E\u8D85\u65F6\uFF0C\u8BF7\u91CD\u65B0\u70B9\u64AD")),3e4);function l(c){clearTimeout(a),n.removeEventListener("loadedmetadata",r),n.removeEventListener("error",s),e.removeEventListener("abort",o),c!==void 0?i(c):t()}n.addEventListener("loadedmetadata",r),n.addEventListener("error",s),e.addEventListener("abort",o),e.aborted&&o()})}function zA(n,e){return!!n&&!!e.turnId&&e.state==="submitted"&&n.turnId!==e.turnId}function BA(n,e){return!n||!e.turnId||e.state!=="stopped"&&e.state!=="interrupted"||n.turnId===e.turnId&&n.state!=="submitted"?null:e.state==="interrupted"?"\u672C\u8F6E\u5DF2\u4E2D\u65AD\uFF0C\u5DF2\u4E3A\u4F60\u6682\u505C":"\u672C\u8F6E\u5DF2\u505C\u6B62\uFF0C\u5DF2\u4E3A\u4F60\u6682\u505C"}var yt=n=>document.getElementById(n),hl=0,TS=!1;function JF(n){let e=n.hooks.status==="ready",t=n.hooks.events.some(s=>s.status==="needs_review");yt("setupTitle").textContent=Ce(t?"\u8BF7\u5BA1\u67E5\u7EA2\u679C\u7684\u56DE\u5408 Hooks":"\u5F00\u59CB\u4F7F\u7528\u7EA2\u679C");let i=[["Node",n.runtime,!0],["\u8FDB\u5EA6\u5E93",n.database?"\u53EF\u5199":"\u4E0D\u53EF\u7528",n.database],["\u64AD\u653E\u7EC4\u4EF6",n.ffmpeg?"\u5C31\u7EEA":"\u51C6\u5907\u4E2D",n.ffmpeg],["\u56DE\u5408\u8054\u52A8",e?"\u5DF2\u914D\u7F6E":n.hooks.status==="unknown"?"\u5F85\u786E\u8BA4":"\u5F85\u914D\u7F6E",e]];yt("setupRows").replaceChildren(...i.map(([s,o,a])=>{let l=document.createElement("div"),c=document.createElement("span"),u=document.createElement("span");return l.className="healthRow "+(a?"ok":"bad"),c.textContent=Ce(s),u.textContent=Ce(o),l.append(tr(a?"check":"alert"),c,u),l}));let r=n.database?n.ffmpeg?e?"\u56DE\u5408\u8054\u52A8\u5DF2\u5C31\u7EEA\u3002\u53EF\u5728\u8BBE\u7F6E\u4E2D\u914D\u7F6E\u4EFB\u52A1\u5F00\u59CB\u81EA\u52A8\u64AD\u653E\u548C\u4EFB\u52A1\u7ED3\u675F\u81EA\u52A8\u6682\u505C\u3002":n.hooks.status==="unknown"?"\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6 Hooks \u72B6\u6001\uFF0C\u8BF7\u5728\u5BBF\u4E3B\u8BBE\u7F6E\u4E2D\u6838\u5BF9\u3002\u73B0\u5728\u53EF\u4EE5\u5148\u624B\u52A8\u89C2\u770B\u3002":n.hooks.events.some(s=>s.status==="missing")?"\u5C1A\u672A\u53D1\u73B0\u5B8C\u6574\u7684\u56DE\u5408\u4E8B\u4EF6\u3002\u8BF7\u68C0\u67E5\u63D2\u4EF6\u5DF2\u542F\u7528\uFF0C\u5E76\u5728\u65B0\u7684\u672C\u5730\u5BF9\u8BDD\u4E2D\u91CD\u8BD5\u3002":"\u56DE\u5408\u8054\u52A8\u5C1A\u672A\u914D\u7F6E\u3002\u5B8C\u6210\u4E0B\u65B9\u64CD\u4F5C\u540E\u91CD\u65B0\u68C0\u67E5\uFF0C\u4E5F\u53EF\u4EE5\u5148\u624B\u52A8\u89C2\u770B\u3002":"\u64AD\u653E\u7EC4\u4EF6\u5C1A\u672A\u5C31\u7EEA\u3002\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u70B9\u51FB\u300C\u91CD\u65B0\u68C0\u67E5\u300D\uFF0C\u63D2\u4EF6\u4F1A\u81EA\u52A8\u51C6\u5907\u3002":"\u8FDB\u5EA6\u6682\u65F6\u65E0\u6CD5\u4FDD\u5B58\uFF0C\u8BF7\u68C0\u67E5\u7EA2\u679C\u7684\u6570\u636E\u76EE\u5F55\u6743\u9650\u3002";yt("setupHelp").textContent=Ce(r),yt("setupGuide").querySelector(".setupHooks").hidden=e}async function Df(n=!0){if(Bn)return;let e=++hl,t=yt("setupCheck");t.disabled=!0,n&&(yt("setupGuide").hidden=!1,yt("setupRows").replaceChildren(),yt("setupHelp").textContent=Ce("\u6B63\u5728\u68C0\u67E5\u2026"));try{let i=await Ie("get_setup_status");if(e!==hl)return;TS=i.dismissed,JF(i);let r=!i.database||!i.ffmpeg||i.hooks.status==="needs_attention";yt("setupGuide").hidden=!(n||!i.dismissed||r)}catch{if(e!==hl)return;yt("setupGuide").hidden=!(n||!TS),yt("setupRows").replaceChildren(),yt("setupHelp").textContent=Ce("\u68C0\u67E5\u672A\u5B8C\u6210\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u6216\u5728 Codex \u8BBE\u7F6E \u2192 Hooks \u6838\u5BF9\u56DE\u5408\u8054\u52A8\u3002"),yt("setupGuide").querySelector(".setupHooks").hidden=!1}finally{e===hl&&(t.disabled=!1)}}function jA(n){yt("setupOpen").hidden=Bn,yt("setupCheck").onclick=()=>{Df()},yt("setupDone").onclick=async()=>{++hl,TS=!0;let e=yt("setupDone");e.disabled=!0;try{await Ie("set_setup_dismissed",{dismissed:!0})}catch{n("\u672C\u6B21\u5DF2\u6536\u8D77\u6307\u5357\uFF0C\u6682\u65F6\u65E0\u6CD5\u4FDD\u5B58\u6B64\u8BBE\u7F6E\u3002")}finally{yt("setupGuide").hidden=!0,e.disabled=!1,yt("setupCheck").disabled=!1}},Df(!1)}function $S(n){return n.episodeId?Ce(n.kind==="next"?"\u770B\u4E0B\u4E00\u96C6":"\u7EE7\u7EED\u89C2\u770B")+" \xB7 "+n.title:n.title}function kS(n,e){return e.aborted?Promise.resolve(!1):new Promise(t=>{let i=new IntersectionObserver(a=>{let l=a[a.length-1];!document.hidden&&l.isIntersecting&&l.intersectionRect.width>0&&l.intersectionRect.height>0&&r(!0)},{threshold:[0,.01]}),r=a=>{i.disconnect(),document.removeEventListener("visibilitychange",o),e.removeEventListener("abort",s),t(a)},s=()=>r(!1),o=()=>{document.hidden||(i.unobserve(n),i.observe(n))};e.addEventListener("abort",s),document.addEventListener("visibilitychange",o),i.observe(n)})}async function AS(n,e,t,i,r,s=!1){let o=i?{turnId:i}:{};if(e.replaceChildren(),n.hidden=!1,!await kS(n,t))return;let{items:a}=await Ie("get_waiting_picks",{...o,inView:!0},9e4);if(!t.aborted){if(!a.length){s?r([]):n.hidden=!0;return}if(r(a),!!await kS(e,t))try{await Ie("mark_waiting_picks_shown",o)}catch{await kS(e,t)&&await Ie("mark_waiting_picks_shown",o).catch(()=>{})}}}function VA(n,e){let t=document.getElementById("waitingCard"),i=document.getElementById("waitingTitles"),r=document.getElementById("waitingMessage"),s=document.getElementById("waitingDismiss"),o=!1,a=!1,l=!1,c=!1,u=!0,d=!1,f=0,h,m,p,g;function y(){++f,m?.abort(),m=void 0,t.hidden=!0,i.replaceChildren(),r.textContent=""}s.onclick=()=>{c=!0,y(),Ie("dismiss_waiting_picks").catch(()=>{})};function b($){!o||c||!u||a||(r.textContent=Ce($ instanceof Error?$.message:"\u5F53\u524D Codex \u65E0\u6CD5\u5728\u4F1A\u8BDD\u4E2D\u6253\u5F00\u64AD\u653E\u5668"),t.hidden=!1)}async function S($=!1){if(!o)return;let P=Lf()||"inline";if(!$&&P===h)return;h=P;let k=++f;m?.abort();let D=m=new AbortController;if(P==="fullscreen"){if(a)return;let V=await(p??=Ie("activate_waiting_player"));if(k!==f)return;a=!0,t.hidden=!0,document.documentElement.dataset.surface="player",n(V);return}else p=void 0,a&&(a=!1,e(),document.documentElement.dataset.surface="waiting");if(c){y();return}let U=await Ie("get_waiting_status");if(k===f){if(u=U.visible,!u){y();return}r.textContent="",await AS(t,i,D.signal,void 0,V=>{let X=V.map(z=>{let B=document.createElement("button");return B.type="button",B.textContent=$S(z),B.onclick=()=>{x(z)},B}),q=document.createElement("button");q.type="button",q.textContent=Ce("\u66F4\u591A\u2026"),q.onclick=()=>{x()},i.replaceChildren(...X,q)},!0).catch(V=>{D.signal.aborted||b(V)})}}async function x($){if(!l){l=!0,r.textContent="";try{$?await Ie("select_waiting_pick",{seriesId:$.id}):await Ie("browse_waiting_catalog"),Lf()==="fullscreen"?await S(!0):(await NA(),t.hidden=!0)}catch(P){b(P),P instanceof Error&&P.message==="\u8FD9\u6761\u63A8\u8350\u5DF2\u7ED3\u675F"&&y()}finally{l=!1}}}async function _(){if(!(!o||a||l||c||document.hidden||d)){d=!0;try{let $=await Ie("get_waiting_status");if(!o||a||l||c)return;$.visible!==u&&(u=$.visible,u?await S(!0):y())}catch{!a&&!l&&(u=!1,y())}finally{d=!1}}}let I=()=>{S().catch(b)},T=()=>{!document.hidden&&o&&!a&&!c&&S(!0).catch(b)};return{connected(){o||(o=!0,g=setInterval(()=>{_()},1e3),document.addEventListener("visibilitychange",T),I())},modeChanged:I,dispose(){o=!1,clearInterval(g),document.removeEventListener("visibilitychange",T),y()}}}var F=n=>document.getElementById(n),Q=document.querySelector("video"),Yr=F("seek"),PS=F("play"),Of=F("center"),Zi=F("autonext"),jn=(n,e)=>{F(n).textContent=n==="title"?e:Ce(e)},We=n=>jn("notice",n),$t=n=>n instanceof Error?n.message:"\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",no=n=>Math.floor(n/60)+":"+String(Math.floor(n%60)).padStart(2,"0"),XF=n=>new Promise(e=>setTimeout(e,n));function wn(n,e){let t=document.createElement("button");return t.textContent=Ce(n),t.onclick=()=>{Promise.resolve(e()).catch(i=>We($t(i)))},t}var gr={identified:!1},qt=null,at=null,Qe=null,qe=[],kt,vl="",kn,bt=[],$n=!1,ct=0,Qn=0,Ki=0,An=!1,Ot=!1,wS,RS=0,Wr=Promise.resolve(),Wt={autoPrompt:!0,autoplayNext:!0,autoPauseOnFinish:!0,autoPlayOnStart:!0,searchTerms:["\u603B\u88C1","\u91CD\u751F","\u9006\u88AD"]},dn="idle",Jr,LS,ml,to=0,pl=0,vr=[],Nf=null,ZA=document.documentElement.dataset.surface==="waiting",qA=Array.from(crypto.getRandomValues(new Uint32Array(4)),n=>n.toString(16).padStart(8,"0")).join(""),gl=!1,WA,GA=null,KA,DS,yr;function Uf(){yr=void 0;let n=DS;DS=void 0,n&&Ie("confirm_waiting_playback",{playbackId:n},1800).catch(()=>{})}function qi(){PS.disabled=Of.disabled=!Qe?.playable,F("pair").disabled=!Qe;let n=Ce(An?"\u53D6\u6D88\u51C6\u5907":Q.paused?"\u64AD\u653E":"\u6682\u505C"),e=An?"x":Q.paused?"play":"pause";oo(PS,e,n),oo(Of,e,n),F("stage").classList.toggle("playing",!Q.paused),F("stage").classList.toggle("busy",An),F("prev").disabled=!Qe||!qe.slice(0,qe.indexOf(Qe)).some(t=>t.playable),F("next").disabled=!Qe||!kt&&!qe.slice(qe.indexOf(Qe)+1).some(t=>t.playable),Of.hidden=An,document.querySelectorAll("#episodes button").forEach(t=>t.setAttribute("aria-pressed",String(t.dataset.id===Qe?.id)))}function Yi(n=!1){if(!$n||!at||!Qe||!Number.isFinite(Q.duration)||!Q.duration||!Q.currentTime&&!n)return Wr;let e={seriesId:at.id,episodeId:Qe.id,title:at.title,label:Qe.label,positionMs:Math.round((dn==="finished"||Q.ended?Q.duration:Q.currentTime)*1e3),durationMs:Math.round(Q.duration*1e3)};return Wr=Wr.then(()=>Ie("save_progress",{...e,...n&&e.positionMs===0?{reset:!0}:{}},1800)).then(()=>{}).catch(()=>We("\u89C2\u770B\u8FDB\u5EA6\u6682\u672A\u5199\u5165\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u670D\u52A1")),Wr}function un(n="",e=!1){e||(yr=void 0),n==="\u5DF2\u624B\u52A8\u6682\u505C"&&Uf(),ct++,Jr=void 0,An=!1,dn!=="finished"&&(dn="idle"),Q.pause(),qi();let t=!!at&&/本轮已停止|本轮已中断/.test(n);return n&&We(t?"":n),F("stopped").hidden=!t,t&&jn("whyStopped",n),Yi()}function Xr(){$n=!1,dn="idle",ml?.abort(),ml=void 0,F("stopped").hidden=!0,F("resumed").hidden=!0,LS?.(),LS=void 0,Q.removeAttribute("src"),Q.load()}function YA(n){un("",!0),Xr(),F("link").hidden=!0,F("linkValue").value="",Qe=n,to=Math.floor(Math.max(0,qe.indexOf(n))/50),We("");let e="\u7B2C "+n.number+" \u96C6",t=n.label.replace(/\s/g,"")!=="\u7B2C"+n.number+"\u96C6";jn("subtitle",[e,t?n.label:"",n.codec].filter(Boolean).join(" \xB7 ")),jn("time","0:00"),Yr.value="0",Ji(Yr),qi(),n.playable||We("\u8BE5\u96C6\u5F53\u524D\u4E0D\u53EF\u64AD\u653E\uFF0C\u8BF7\u68C0\u67E5\u7247\u6E90\u8BB8\u53EF\u6216 FFmpeg \u81EA\u68C0\u7ED3\u679C")}function yl(){let n=Math.ceil(qe.length/50);F("groups").replaceChildren(...Array.from({length:n>1?n:0},(e,t)=>{let i=wn(qe[t*50].number+"\u2013"+qe[Math.min(qe.length,(t+1)*50)-1].number,()=>{to=t,yl()});return i.setAttribute("aria-pressed",String(t===to)),i})),F("episodes").replaceChildren(...qe.slice(to*50,(to+1)*50).map(e=>{let t=wn(String(e.number),()=>Ff(e));return t.disabled=!e.playable,t.title=e.label,t.dataset.id=e.id,t})),F("moreEpisodes").hidden=!kt,F("episodeCount").textContent=qe.length?Ce(qe.length+(kt?"+":"")+" \u96C6"):"",qi()}async function ro(n,e,t=!1,i){let r=i&&e;F("home").hidden=!0,F("watch").hidden=!1,F("back").focus({preventScroll:!0}),window.scrollTo(0,0),to=0;let s=++Qn;un(),yr=t?i:void 0;let o=ct;Xr(),Qe=null,qe=[],kt=void 0,at=n,Wi(),Q.poster=n.cover||"",jn("title",n.title),jn("subtitle","\u6B63\u5728\u8BFB\u53D6\u5206\u96C6\u2026"),yl(),QA(),await Wr;let[a,l]=await Promise.all([Ie("get_episodes",{seriesId:n.id}),Ie("get_history",{seriesId:n.id})]);e??=l.items[0]?.episodeId;let c=a;if(s!==Qn)return;qe=c.items||[],kt=c.cursor;let u=new Set;for(;e&&!qe.some(h=>h.id===e)&&kt&&!u.has(kt);){if(u.add(kt),c=await Ie("get_episodes",{seriesId:n.id,cursor:kt}),s!==Qn)return;qe.push(...c.items),kt=c.cursor}let d=e&&qe.find(h=>h.id===e&&(!t||h.playable))||!r&&(t&&qe.find(h=>h.playable)||qe[0]),f=t&&Ot&&(ct===o||!!i&&yr===i);d?YA(d):jn("subtitle","\u6682\u65E0\u53EF\u7528\u5206\u96C6"),yl(),f&&d&&s===Qn&&await so(i)}async function Ff(n){YA(n),yl(),await so()}async function JA(){if(!at||!kt)return;let n=Qn,e=kt;try{let t=await Ie("get_episodes",{seriesId:at.id,cursor:e});if(n!==Qn||e!==kt)return;qe.push(...t.items),kt=t.cursor===e?void 0:t.cursor,yl()}catch(t){We($t(t))}}F("moreEpisodes").onclick=JA;async function XA(n=!1){if(!Qe)return;let e=Qe.id,t=Qn,i=ct,r=qe.slice(qe.indexOf(Qe)+1).find(o=>o.playable),s=new Set;for(;!r&&kt&&!s.has(kt);){if(s.add(kt),await JA(),Qn!==t||Qe?.id!==e||ct!==i)return;r=qe.slice(qe.indexOf(Qe)+1).find(o=>o.playable)}!Ot||n&&!Zi.checked||(r?await Ff(r):n&&un("\u672C\u96C6\u5DF2\u64AD\u5B8C"))}F("prev").onclick=()=>{let n=qe.slice(0,qe.indexOf(Qe)).reverse().find(e=>e.playable);n&&Ff(n)};F("next").onclick=()=>{XA()};F("random").onclick=()=>{let n=qe.filter(r=>r.playable),e=vr.find(r=>r.seriesId===at?.id),t=e?n.findIndex(r=>r.id===e.episodeId):-1,i=t<0?n.slice(0,1):n.slice(Math.min(t+1,n.length-1));i.length&&Ff(i[Math.floor(Math.random()*i.length)])};async function QF(){Uf(),document.fullscreenElement&&await document.exitFullscreen(),F("stage").classList.remove("expanded"),Mf(),We(""),++Qn;let n=un();Xr(),Qe=null,at=null,qe=[],kt=void 0,F("home").hidden=!1,F("watch").hidden=!0,F("link").hidden=!0,bt.length?Hi():Qr(),await n,await zf(),!at&&bt.length&&Hi()}F("back").onclick=()=>{QF().catch(n=>We($t(n)))};function QA(){document.querySelectorAll(".card").forEach(n=>n.setAttribute("aria-pressed",String(n.dataset.id===at?.id)))}function Hi(){let n=[],e=new Set(vr.map(o=>o.seriesId)),t=vl?void 0:bt.find(o=>!e.has(o.id))||bt[0],i=bt.filter(o=>o!==t),r=nw();if(r&&n.push(r),F("featured").replaceChildren(),t){let o=wn("",()=>ro(t,void 0,!0)),a=Sl(t.title,t.episodes?Ce(t.episodes+" \u96C6"):""),l=document.createElement("span"),c=document.createElement("small"),u=document.createElement("strong"),d=document.createElement("span");if(o.className="feature",o.dataset.id=t.id,o.setAttribute("aria-label",Ce("\u64AD\u653E")+" \xB7 "+t.title),l.className="featureText",c.className="eyebrow",c.textContent=Ce(e.has(t.id)?"\u770B\u8FC7":"\u63A8\u8350"),u.textContent=t.title,l.append(c,u),t.description){let f=document.createElement("span");f.className="desc",f.textContent=t.description,l.append(f)}d.className="playPill",d.append(tr("play"),Ce("\u64AD\u653E")),l.append(d),o.append(a,l),F("featured").append(o),n.push({span:a,s:t})}Wi(),F("cards").replaceChildren(...i.slice(pl*12,(pl+1)*12).map(o=>{let a=wn("",()=>ro(o,void 0,!0));a.className="card",a.dataset.id=o.id,a.title=o.title;let l=Sl(o.title,o.episodes?Ce(o.episodes+" \u96C6"):""),c=document.createElement("span");return c.className="cardTitle",c.textContent=o.title,a.append(l,c),n.push({span:l,s:o}),a})),QA();let s=Ki;(async()=>{for(let{span:o,s:a}of n){if(s!==Ki)return;if(!a.cover&&(a.hasCover||a.lookupCover))try{a.cover=(await Ie("get_cover",{seriesId:a.id},9e3)).cover}catch{}a.cover&&(BS(o,a.cover),at?.id===a.id&&(Q.poster=a.cover))}})()}function Wi(){let e=Wt.autoPrompt&&!!qt?.turnId&&qt.state==="submitted"&&!at&&!vl&&bt.length>0&&Nf!==qt.turnId?qt.turnId:null;if(e===GA)return;GA=e,KA?.abort();let t=F("prompt"),i=F("picks");if(!e){t.hidden=!0;return}let r=KA=new AbortController;AS(t,i,r.signal,e,s=>{i.replaceChildren(...s.map(o=>wn($S(o),()=>(Ie("mark_waiting_picks_shown",{turnId:e}).catch(()=>{}),ro(bt.find(a=>a.id===o.id)??o,o.episodeId,!0,e)))),wn("\u66F4\u591A\u2026",()=>{ew(),F("query").focus()}))}).catch(()=>{r.signal.aborted||(t.hidden=!0)})}function ew(){Nf=qt?.turnId||null,Nf&&Ie("dismiss_waiting_picks",{turnId:Nf}).catch(()=>{}),Wi()}F("dismiss").onclick=ew;function eo(n,e=""){let t=F("catalogStatus"),i=F("cards"),r=F("query");if(t.dataset.state=n==="loading"&&bt.length?"busy":n,t.replaceChildren(),e){let s=document.createElement("span");s.textContent=Ce(e),t.append(s)}t.dataset.state==="busy"&&t.prepend(tr("spin")),n==="error"&&t.append(wn("\u91CD\u8BD5",()=>Qr())),n==="empty"&&vl&&t.append(wn("\u6E05\u9664\u641C\u7D22",()=>(r.value="",Qr(!1,"")))),t.querySelectorAll("button").forEach(s=>s.className="btn"),n==="loading"&&!bt.length?i.replaceChildren(...Array.from({length:6},()=>{let s=document.createElement("div"),o=document.createElement("span"),a=document.createElement("span");return s.className="skel",s.setAttribute("aria-hidden","true"),o.className="skelArt",a.className="skelLine",s.append(o,a),s})):i.querySelector(".skel")&&i.replaceChildren()}async function Qr(n=!1,e=vl){let t=++Ki;n||(vl=e,bt=[],kn=void 0,pl=0,Hi());let i=n?pl+1:0;F("more").hidden=!0,eo("loading","\u6B63\u5728\u8BFB\u53D6\u7247\u5E93\u2026");let r=n?[...bt]:[],s=!1;!n&&!e&&Ie("list_series",{preview:!0},9e4).then(o=>{t!==Ki||s||!o.items.length||(bt=o.items,Hi(),F("catalogStatus").dataset.state!=="error"&&eo(""),F("more").hidden=bt.length<=13)}).catch(()=>{});try{let o=new Set,a=(i+1)*12+(e?0:1),l=!n;for(;l||r.length<a&&kn&&!o.has(kn);){l=!1,kn&&o.add(kn);let u=await Ie("list_series",{query:e,cursor:kn},9e4);if(t!==Ki)return;let d=new Set(r.map(f=>f.id));for(let f of u.items)d.has(f.id)||(d.add(f.id),r.push(f));kn=u.cursor,kn&&o.has(kn)&&(kn=void 0)}s=r.length>0,s&&(bt=r);let c=Math.max(1,Math.ceil((bt.length-(e?0:1))/12));if(n&&i>=c&&!kn&&!e){await Qr();return}pl=i%c,Hi(),bt.length?eo(""):e?eo("empty","\u6CA1\u6709\u627E\u5230\u76F8\u7B26\u7684\u5267\u76EE"):eo("error","\u7EA2\u679C\u6682\u65F6\u6CA1\u6709\u8FD4\u56DE\u63A8\u8350\u5267\u76EE"),F("more").hidden=c<=1&&!kn}catch(o){t===Ki&&(eo("error",$t(o)),F("more").hidden=!n)}}async function zf(){vr=(await Ie("get_history")).items,nw(),F("history").replaceChildren(...vr.map(n=>{let e=document.createElement("div"),t=document.createElement("strong"),i=document.createElement("small");e.className="historyRow";let r=wn("",()=>tw(n));r.className="historyItem",t.textContent=n.title,i.textContent=n.label+" \xB7 "+no(n.positionMs/1e3),r.append(t,i);let s=wn("",async()=>{await Wr,await Ie("remove_history",{seriesId:n.seriesId}),await zf(),Hi()}),o=Ce("\u79FB\u9664 "+n.title+" \u7684\u89C2\u770B\u5386\u53F2");return s.className="icon sm",s.setAttribute("aria-label",o),s.title=o,s.append(tr("x")),e.append(r,s),e})),F("historyCount").textContent=vr.length?String(vr.length):"",F("resume").hidden=!vr.length}function tw(n){return ro(bt.find(e=>e.id===n.seriesId)||{id:n.seriesId,title:n.title},n.episodeId,!0)}function nw(){let n=vr[0];if(!n){F("continue").replaceChildren();return}let e=bt.find(f=>f.id===n.seriesId)||{id:n.seriesId,title:n.title},t=wn("",()=>tw(n)),i=Sl(n.title),r=document.createElement("span"),s=document.createElement("small"),o=document.createElement("strong"),a=document.createElement("span"),l=document.createElement("span"),c=document.createElement("i"),u=document.createElement("span"),d=n.durationMs?Math.min(1,n.positionMs/n.durationMs):0;return t.className="resumeCard",t.setAttribute("aria-label",Ce("\u7EE7\u7EED\u89C2\u770B \xB7 "+n.title+" \xB7 "+n.label)),r.className="resumeText",s.className="eyebrow",s.textContent=Ce("\u7EE7\u7EED\u89C2\u770B"),o.textContent=n.title,a.className="meta",a.textContent=n.label+" \xB7 "+no(n.positionMs/1e3)+(n.durationMs?" / "+no(n.durationMs/1e3):""),l.className="bar",c.style.setProperty("--p",(d*100).toFixed(1)+"%"),l.append(c),r.append(s,o,a,l),u.className="resumePlay",u.append(tr("play")),t.append(i,r,u),F("continue").replaceChildren(t),{span:i,s:e}}function rw(){let n=qt?.state==="submitted";F("lamp").classList.toggle("on",n),jn("state",!gr.identified&&Bn?"\u672A\u5173\u8054\u5BF9\u8BDD":!qt||qt.state==="unknown"?"\u7B49\u5F85\u56DE\u5408\u5F00\u59CB":n?"\u5F53\u524D\u56DE\u5408\u8FDB\u884C\u4E2D":qt.state==="interrupted"?"\u56DE\u5408\u5DF2\u4E2D\u65AD":"\u56DE\u5408\u5DF2\u505C\u6B62")}function Bf(){return Ot?(wS??=ez().finally(()=>{wS=void 0}),wS):Promise.resolve()}async function ez(){try{let n=await Ie("get_run_state",{observeSession:!0,playerInstance:document.hidden?void 0:qA},1800);if(!Ot)return;if(n.preferences){let r=Wt.autoPrompt!==n.preferences.autoPrompt;Wt=n.preferences,Zi.checked=Wt.autoplayNext,r&&Wi()}let e=BA(qt,n),t=zA(qt,n),i=qt?.state!==n.state||qt?.turnId!==n.turnId;qt=n,i&&Wi(),rw(),e&&at&&Wt.autoPauseOnFinish?un(e):t&&Wt.autoPlayOnStart&&at&&Qe?.playable&&Q.paused&&!An&&so(n.turnId,!0)}catch{if(!Ot)return;F("lamp").classList.remove("on"),jn("state","\u672C\u673A\u72B6\u6001\u4E0D\u53EF\u8FBE")}}function tz(){let n=Q.duration;!Number.isFinite(n)||!$n||(Yr.value=String(Math.round(Q.currentTime/n*1e3)),Ji(Yr),jn("time",no(Q.currentTime)+" / "+no(n)))}async function so(n,e=!1){if(!Qe?.playable||!at||!Ot)return;yr=e?void 0:n;let t=++ct,i=Qe,r=at;An=!0,qi(),F("stopped").hidden=!0;try{if(!$n){We("\u6B63\u5728\u51C6\u5907\u64AD\u653E\u2026");let s=await Ie("prepare_playback",{episodeId:i.id,retry:!0}),o=Date.now()+24e4;for(;s.status==="preparing"&&t===ct&&Date.now()<o;){if(We("\u6B63\u5728\u672C\u673A\u51C6\u5907\u6574\u96C6\u2026"),await XF(700),t!==ct)return;s=await Ie("prepare_playback",{episodeId:i.id})}if(t!==ct)return;if(s.status!=="ready")throw Error(s.reason||"\u51C6\u5907\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5");let a=s;if(Bn!=="src"in a)throw Error("\u672C\u96C6\u64AD\u653E\u5730\u5740\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u8BD5");await Wr;let l=await Ie("get_history",{seriesId:r.id,episodeId:i.id});if(t!==ct)return;Xr();let c=new AbortController;ml=c;let u=FA(Q,c.signal),d=m=>{ml===c&&(c.abort(Error(m)),$n&&(un(m),Xr()))};try{"stream"in a?LS=UA(Q,i.id,a.stream,a.manifest,d,()=>{ml===c&&iw()}):(Q.src=a.src,Q.load())}catch(m){d($t(m))}if(await u,t!==ct)return;let f=l.items[0],h=f&&f.positionMs<f.durationMs?f.positionMs/1e3:0;Q.currentTime=h>0&&h<Q.duration-5?h:0,Q.currentTime>0&&(jn("resumeTime","\u5DF2\u4ECE "+no(h)+" \u7EE7\u7EED"),F("resumed").hidden=!1),$n=!0}if(n){let s=await Ie("get_run_state",{observeSession:!0},1800);if(t!==ct)return;if(s.turnId!==n||s.state!=="submitted"||e&&!s.preferences?.autoPlayOnStart){un(e?"":"\u63A8\u8350\u6240\u5C5E\u4EFB\u52A1\u5DF2\u7ED3\u675F\uFF0C\u70B9\u51FB\u64AD\u653E\u7EE7\u7EED\u89C2\u770B");return}}if(t!==ct||!Ot)return;An=!1,dn==="finished"&&(Q.currentTime=0),dn="playing",Q.playbackRate=parseFloat(F("speed").value),n&&!e&&(Q.muted=!0);try{await Q.play()}catch(s){if(t!==ct||!Ot)return;if(!(s instanceof DOMException&&["AbortError","NotAllowedError"].includes(s.name))||!document.hidden&&document.hasFocus()&&Jr?.action!==t)throw s instanceof DOMException&&s.name==="NotAllowedError"&&n&&!e?Error("\u5BBF\u4E3B\u963B\u6B62\u4E86\u81EA\u52A8\u64AD\u653E\uFF0C\u8BF7\u70B9\u51FB\u64AD\u653E\u7EE7\u7EED"):s;Vf();return}t===ct&&(Uf(),We("\u6B63\u5728\u64AD\u653E"),RS=Date.now(),qi())}catch(s){t===ct&&($n||Xr(),un($t(s)))}}function nz(){!Q.paused||An?un("\u5DF2\u624B\u52A8\u6682\u505C"):so()}for(let n of[Q,Of,PS,F("resumePlayback")])n.addEventListener("click",nz);function iw(){!$n||dn!=="playing"||!Number.isFinite(Q.duration)||Q.currentTime<Q.duration-1||(dn="finished",Yi(),Zi.checked&&Ot?XA(!0).catch(n=>We($t(n))):un("\u672C\u96C6\u5DF2\u64AD\u5B8C"),Wr.then(zf).catch(()=>{}))}Q.onended=iw;Zi.onchange=()=>{Ie("set_preferences",{autoplayNext:Zi.checked}).then(n=>{Wt=n}).catch(n=>We($t(n)))};Q.ontimeupdate=()=>{tz(),!Q.paused&&Date.now()-RS>=5e3&&(RS=Date.now(),Yi())};Q.onpause=()=>{qi(),$n&&Yi(),(document.hidden||!document.hasFocus()||Jr?.action===ct)&&Vf()};Q.onplay=qi;Q.onplaying=Uf;Q.onerror=()=>{$n&&(un(IS(Q.error?.code)),Xr())};Yr.oninput=()=>{Ji(Yr),$n&&Number.isFinite(Q.duration)&&(dn==="finished"&&(dn="idle"),Q.currentTime=Number(Yr.value)*Q.duration/1e3)};Yr.onchange=()=>{Yi(Q.currentTime===0)};Q.onloadedmetadata=()=>{Q.videoWidth&&Q.videoHeight&&(F("stage").style.aspectRatio=Q.videoWidth+"/"+Q.videoHeight)};F("restart").onclick=()=>{dn==="finished"&&(dn="idle"),Q.currentTime=0,F("resumed").hidden=!0,Yi(!0)};F("mute").onclick=()=>{Q.volume===0?(Q.volume=.7,Q.muted=!1):Q.muted=!Q.muted};async function sw(){let n=F("stage");if(document.fullscreenElement){await document.exitFullscreen();return}if(n.classList.contains("expanded")){n.classList.remove("expanded"),Mf();return}try{await n.requestFullscreen()}catch{n.classList.add("expanded"),Mf()}}F("fullscreen").onclick=()=>{sw().catch(n=>We($t(n)))};document.addEventListener("fullscreenchange",Mf);function Mf(){let n=F("stage"),e=!!document.fullscreenElement||n.classList.contains("expanded");n.classList.toggle("isFull",e),oo(F("fullscreen"),e?"collapse":"expand",Ce(e?"\u9000\u51FA\u5168\u5C4F":"\u5168\u5C4F"))}var HA;F("stage").addEventListener("pointermove",()=>{let n=F("stage");n.classList.add("awake"),clearTimeout(HA),HA=setTimeout(()=>n.classList.remove("awake"),2400)});F("stage").addEventListener("pointerleave",()=>F("stage").classList.remove("awake"));document.addEventListener("keydown",n=>{n.key==="Escape"&&F("stage").classList.contains("expanded")&&sw()});var io=F("volume");Q.onvolumechange=()=>{let n=Q.muted||Q.volume===0;oo(F("mute"),n?"mute":"volume",Ce(n?"\u53D6\u6D88\u9759\u97F3":"\u9759\u97F3")),F("mute").setAttribute("aria-pressed",String(n)),io.value=String(Math.round(Q.volume*100)),Ji(io)};Q.volume=Number(io.value)/100;Ji(io);io.oninput=()=>{Q.volume=Number(io.value)/100,Q.muted=Q.volume===0};F("speed").onchange=n=>Q.playbackRate=parseFloat(n.target.value);var bl=F("query"),CS,jf=!1;function OS(){clearTimeout(CS),jf||Qr(!1,bl.value.trim())}function NS(){clearTimeout(CS),++Ki,!jf&&(bl.value.trim()?CS=setTimeout(OS,400):OS())}bl.addEventListener("input",NS);bl.addEventListener("compositionstart",()=>{jf=!0,NS()});bl.addEventListener("compositionend",()=>{jf=!1,NS()});F("search").onsubmit=n=>{n.preventDefault(),OS()};F("more").onclick=()=>{Qr(!0)};async function rz(){let n=at,e=Qe;if(!(!n||!e))try{await un();let t=await Ie("create_browser_pairing",{seriesId:n.id,episodeId:e.id,title:n.title});if(at!==n||Qe!==e)return;F("linkValue").value=t.url,F("link").hidden=!1,F("link").scrollIntoView({block:"nearest"}),setTimeout(()=>{F("linkValue").value===t.url&&(F("link").hidden=!0,F("linkValue").value="")},6e4)}catch(t){We($t(t))}}F("pair").onclick=rz;F("copy").onclick=async()=>{let n=F("linkValue");try{await navigator.clipboard.writeText(n.value),We("\u5DF2\u590D\u5236\uFF0C\u8BF7\u5728 Codex \u5185\u7F6E\u6D4F\u89C8\u5668\u6253\u5F00")}catch{n.select(),We("\u94FE\u63A5\u5DF2\u9009\u4E2D\uFF0C\u8BF7\u590D\u5236\u5E76\u5728 Codex \u5185\u7F6E\u6D4F\u89C8\u5668\u6253\u5F00")}};F("settingsCancel").onclick=()=>F("prefs").click();F("setupOpen").onclick=()=>{F("settings").hidden=!0,F("prefs").setAttribute("aria-expanded","false"),Df()};F("prefs").onclick=()=>{F("settings").hidden=!F("settings").hidden,F("prefs").setAttribute("aria-expanded",String(!F("settings").hidden)),F("autoPrompt").checked=Wt.autoPrompt,F("autoPauseOnFinish").checked=Wt.autoPauseOnFinish,F("autoPlayOnStart").checked=Wt.autoPlayOnStart,F("terms").value=Wt.searchTerms.join("\uFF0C")};F("settings").onsubmit=n=>{n.preventDefault();let e=F("terms").value.split(/[,,]/).map(t=>t.trim()).filter(Boolean);Ie("set_preferences",{autoPrompt:F("autoPrompt").checked,autoPauseOnFinish:F("autoPauseOnFinish").checked,autoPlayOnStart:F("autoPlayOnStart").checked,searchTerms:e}).then(async t=>{Wt=t,Zi.checked=Wt.autoplayNext,F("settings").hidden=!0,F("prefs").setAttribute("aria-expanded","false"),Wi(),at||await Qr()}).catch(t=>We($t(t)))};F("health").onclick=async()=>{let n=F("healthInfo");if(n.hidden=!n.hidden,F("health").setAttribute("aria-expanded",String(!n.hidden)),!n.hidden){n.textContent=Ce("\u6B63\u5728\u68C0\u67E5\u2026");try{let e=await Ie("get_health"),t=[["Node",e.runtime,!0],["\u8FDB\u5EA6\u5E93",e.database?"\u53EF\u5199":"\u4E0D\u53EF\u7528",e.database],["\u64AD\u653E\u7EC4\u4EF6",e.ffmpeg?"\u5C31\u7EEA":"\u51C6\u5907\u4E2D",e.ffmpeg]];n.replaceChildren(...t.map(([i,r,s])=>{let o=document.createElement("div"),a=document.createElement("span"),l=document.createElement("span");return o.className="healthRow "+(s?"ok":"bad"),a.textContent=Ce(i),l.textContent=Ce(r),o.append(tr(s?"check":"alert"),a,l),o}))}catch(e){n.textContent=$t(e)}}};F("choose").onclick=async()=>{try{let n=await Ie("list_sessions");F("choices").replaceChildren(...n.items.map(e=>wn("\u2026"+e.suffix+" \xB7 "+new Date(e.at).toLocaleString(),async()=>{await Ie("select_session",{choice:e.choice}),gr.identified=!0,MS(Ot&&!document.hidden),F("choose").hidden=!0,F("choices").replaceChildren(),await Bf()}))),n.items.length||We("\u8FD8\u6CA1\u6709\u672C\u673A\u56DE\u5408\u8BB0\u5F55\uFF0C\u53EF\u5148\u624B\u52A8\u89C2\u770B")}catch(n){We($t(n))}};function MS(n){return gr.identified?Ie("set_player_visible",{instance:qA,visible:n},1800).catch(()=>{}):Promise.resolve()}async function ow(){Ot&&(Ot=!1,await Promise.all([un("\u5DF2\u6682\u505C\uFF0C\u70B9\u51FB\u64AD\u653E\u7EE7\u7EED",!0),MS(!1)]))}function aw(n){if(n.action!==ct||!Ot||!$n||dn!=="playing"||!Q.paused||Q.ended||Q.error)return;let e=Q.currentTime;n.lastPosition!==void 0&&Math.abs(e-n.lastPosition)<.25||(n.lastPosition=e,Q.play().then(()=>{n.action===ct&&!Q.paused&&We("\u6B63\u5728\u64AD\u653E")}).catch(()=>{}))}function Vf(){!Ot||dn!=="playing"||(Jr?.action!==ct&&(Jr={action:ct}),aw(Jr))}function lw(){let n=Jr;n&&(Jr=void 0,Bf().then(()=>aw({action:n.action})))}function cw(){Ot&&(MS(!document.hidden),document.hidden?(Vf(),Yi()):lw(),Bf())}function uw(){!gl||Ot||(Ot=!0,cw(),yr&&Qe?.playable&&Q.paused&&!An&&so(yr))}document.addEventListener("visibilitychange",cw);window.addEventListener("blur",Vf);window.addEventListener("focus",lw);window.addEventListener("pagehide",()=>{ow()});window.addEventListener("pageshow",uw);async function dw(n){if(gl)return;if(gl=!0,yr=void 0,DS=n?.play?n.playbackId:void 0,navigator.mediaSession&&(navigator.mediaSession.setActionHandler("pause",()=>{un("\u5DF2\u624B\u52A8\u6682\u505C")}),navigator.mediaSession.setActionHandler("play",()=>{Q.paused&&!An&&so()})),WA=window.setInterval(()=>{Bf()},1e3),F("pair").hidden=Bn||ZA,F("choose").hidden=Bn||gr.identified,qt=null,rw(),uw(),jA(We),Ie("get_preferences").then(t=>{gl&&(Wt=t,Zi.checked=Wt.autoplayNext??!0,Wi())}).catch(t=>We($t(t))),n?.pick){let t=n.pick;await ro(t,t.episodeId,n.play,n.turnId),n.reason==="turn-ended"&&at?.id===t.id&&Q.paused&&!An&&We("\u63A8\u8350\u6240\u5C5E\u4EFB\u52A1\u5DF2\u7ED3\u675F\uFF0C\u70B9\u51FB\u64AD\u653E\u7EE7\u7EED\u89C2\u770B");return}F("home").hidden=!1,F("watch").hidden=!0;let e=Qr();zf().then(()=>{!at&&vr.length&&bt.length&&Hi()}).catch(t=>We($t(t))),gr.selection&&await ro({id:gr.selection.seriesId,title:gr.selection.title||"\u7EA2\u679C\u77ED\u5267"},gr.selection.episodeId),await e}function fw(){let n=ow();return gl=!1,yr=void 0,navigator.mediaSession&&(navigator.mediaSession.setActionHandler("pause",null),navigator.mediaSession.setActionHandler("play",null)),window.clearInterval(WA),++Qn,Xr(),n}var Cf=ZA?VA(n=>{dw(n).catch(e=>We($t(e)))},fw):null;MA(n=>{FS(OA()),gr=n,Cf?n.waitingTurn&&Cf.connected():dw().catch(e=>We($t(e)))},async()=>{Cf?.dispose(),await fw()},()=>Cf?.modeChanged()).catch(n=>We($t(n)));})();
|
|
2063
|
+
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:E.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:E.string().optional().describe("User's timezone in IANA format."),userAgent:E.string().optional().describe("Host application identifier."),platform:E.union([E.literal("web"),E.literal("desktop"),E.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:E.object({touch:E.boolean().optional().describe("Whether the device supports touch input."),hover:E.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:E.object({top:E.number().describe("Top safe area inset in pixels."),right:E.number().describe("Right safe area inset in pixels."),bottom:E.number().describe("Bottom safe area inset in pixels."),left:E.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),ZF=E.object({method:E.literal("ui/notifications/host-context-changed"),params:AA.describe("Partial context update containing only changed fields.")}),p3=E.object({method:E.literal("ui/update-model-context"),params:E.object({content:E.array(Xs).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:E.record(E.string(),E.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),g3=E.object({method:E.literal("ui/initialize"),params:E.object({appInfo:sl.describe("App identification (name and version)."),appCapabilities:VF.describe("Features and capabilities this app provides."),protocolVersion:E.string().describe("Protocol version this app supports.")})}),qF=E.object({protocolVersion:E.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:sl.describe("Host application identification and version."),hostCapabilities:jF.describe("Features and capabilities provided by the host."),hostContext:AA.describe("Rich context about the host environment.")}).passthrough(),WF={target:"draft-2020-12"};async function kA(n,e){let t=n["~standard"];if(t.jsonSchema)return t.jsonSchema[e](WF);if(t.vendor==="zod"){let{z:i}=await Promise.resolve().then(()=>(tl(),Yb));return i.toJSONSchema(n,{io:e})}throw Error(`Schema (vendor: ${t.vendor}) does not implement Standard JSON Schema (~standard.jsonSchema). Use a library that does (zod v4, ArkType, Valibot) or wrap your schema accordingly.`)}async function $A(n,e,t=""){let i=await n["~standard"].validate(e);if(i.issues){let r=i.issues.map(s=>{let o=s.path?.map(a=>typeof a=="object"?a.key:a).join(".");return o?`${o}: ${s.message}`:s.message}).join("; ");throw Error(t+r)}return i.value}function wA(n){let e=document.documentElement;e.setAttribute("data-theme",n),e.style.colorScheme=n}function PA(n,e=document.documentElement){for(let[t,i]of Object.entries(n))i!==void 0&&e.style.setProperty(t,i)}var Rf=class n extends vS{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;_registeredTools={};_initializedSent=!1;_assertInitialized(e){if(this._initializedSent)return;let t=`[ext-apps] App.${e}() called before connect() completed the ui/initialize handshake. Await app.connect() before calling this method, or move data loading to an ontoolresult handler.`;if(this.options?.strict)throw Error(t);console.warn(`${t}. This will throw in a future release.`)}eventSchemas={toolinput:NF,toolinputpartial:MF,toolresult:HF,toolcancelled:UF,hostcontextchanged:ZF};static ONE_SHOT_EVENTS=new Set(["toolinput","toolinputpartial","toolresult","toolcancelled"]);_everHadListener=new Set;_assertHandlerTiming(e){if(!n.ONE_SHOT_EVENTS.has(e)||this._everHadListener.has(e)||(this._everHadListener.add(e),!this._initializedSent))return;let t=`[ext-apps] "${String(e)}" handler registered after connect() completed the ui/initialize handshake. The host may have already sent this notification. Register handlers before calling app.connect().`;if(this.options?.strict)throw Error(t);console.warn(t)}setEventHandler(e,t){t&&this._assertHandlerTiming(e),super.setEventHandler(e,t)}addEventListener(e,t){this._assertHandlerTiming(e),super.addEventListener(e,t)}onEventDispatch(e,t){e==="hostcontextchanged"&&(this._hostContext={...this._hostContext,...t})}constructor(e,t={},i={autoResize:!0}){super(i),this._appInfo=e,this._capabilities=t,this.options=i,i.allowUnsafeEval||E.config({jitless:!0}),this.setRequestHandler(Ys,r=>(console.log("Received ping:",r.params),{})),this.setEventHandler("hostcontextchanged",void 0)}registerCapabilities(e){if(this.transport)throw Error("Cannot register capabilities after transport is established");this._capabilities=IA(this._capabilities,e)}registerTool(e,t,i){if(this._registeredTools[e])throw Error(`Tool ${e} is already registered`);let r=this,s=()=>{r._initializedSent&&r._capabilities.tools?.listChanged&&r.sendToolListChanged()},o=t.inputSchema!==void 0,a={title:t.title,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema,annotations:t.annotations,_meta:t._meta,enabled:!0,enable(){this.enabled=!0,s()},disable(){this.enabled=!1,s()},update(l){Object.assign(this,l),s()},remove(){r._registeredTools[e]===a&&(delete r._registeredTools[e],s())},handler:async(l,c)=>{if(!a.enabled)throw Error(`Tool ${e} is disabled`);let u;if(o){let d=a.inputSchema,f=d?await $A(d,l??{},`Invalid input for tool ${e}: `):l??{};u=await i(f,c)}else u=await i(c);return a.outputSchema&&!u.isError&&(u.structuredContent=await $A(a.outputSchema,u.structuredContent,`Invalid output for tool ${e}: `)),u}};return this._registeredTools[e]=a,!this._capabilities.tools&&!this.transport&&this.registerCapabilities({tools:{listChanged:!0}}),this.ensureToolHandlersInitialized(),s(),a}_toolHandlersInitialized=!1;ensureToolHandlersInitialized(){this._toolHandlersInitialized||(this._toolHandlersInitialized=!0,this.oncalltool=async(e,t)=>{let i=this._registeredTools[e.name];if(!i)throw Error(`Tool ${e.name} not found`);return i.handler(e.arguments,t)},this.onlisttools=async(e,t)=>({tools:await Promise.all(Object.entries(this._registeredTools).filter(([i,r])=>r.enabled).map(async([i,r])=>{let s={name:i,title:r.title,description:r.description,inputSchema:r.inputSchema?await kA(r.inputSchema,"input"):{type:"object",properties:{}}};return r.outputSchema&&(s.outputSchema=await kA(r.outputSchema,"output")),r.annotations&&(s.annotations=r.annotations),r._meta&&(s._meta=r._meta),s}))}))}async sendToolListChanged(e={}){this._assertInitialized("sendToolListChanged"),await this.notification({method:"notifications/tools/list_changed",params:e})}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(e){this.setEventHandler("toolinput",e)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(e){this.setEventHandler("toolinputpartial",e)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(e){this.setEventHandler("toolresult",e)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(e){this.setEventHandler("toolcancelled",e)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(e){this.setEventHandler("hostcontextchanged",e)}_onteardown;get onteardown(){return this._onteardown}set onteardown(e){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,e),this._onteardown=e,this.replaceRequestHandler(BF,(t,i)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(t.params,i)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(e){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,e),this._oncalltool=e,this.replaceRequestHandler(fS,(t,i)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(t.params,i)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(e){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,e),this._onlisttools=e,this.replaceRequestHandler(dS,(t,i)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(t.params,i)})}assertCapabilityForMethod(e){switch(e){case"sampling/createMessage":if(!this._hostCapabilities?.sampling)throw Error(`Host does not support sampling (required for ${e})`);break}}assertRequestHandlerCapability(e){switch(e){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${e})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${e} registered`)}}assertNotificationCapability(e){}assertTaskCapability(e){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(e){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(e,t){if(this._assertInitialized("callServerTool"),typeof e=="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${e}"). Did you mean: callServerTool({ name: "${e}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:e},Qs,{onprogress:()=>{},resetTimeoutOnProgress:!0,...t})}async readServerResource(e,t){return this._assertInitialized("readServerResource"),await this.request({method:"resources/read",params:e},sS,t)}async listServerResources(e,t){return this._assertInitialized("listServerResources"),await this.request({method:"resources/list",params:e},rS,t)}async createSamplingMessage(e,t){this._assertInitialized("createSamplingMessage");let i=e.tools?mS:hS;return await this.request({method:"sampling/createMessage",params:e},i,t)}sendMessage(e,t){return this._assertInitialized("sendMessage"),this.request({method:"ui/message",params:e},OF,t)}sendLog(e){return this.notification({method:"notifications/message",params:e})}updateModelContext(e,t){return this._assertInitialized("updateModelContext"),this.request({method:"ui/update-model-context",params:e},bf,t)}openLink(e,t){return this._assertInitialized("openLink"),this.request({method:"ui/open-link",params:e},DF,t)}sendOpenLink=this.openLink;downloadFile(e,t){return this._assertInitialized("downloadFile"),this.request({method:"ui/download-file",params:e},CF,t)}requestTeardown(e={}){return this.notification({method:"ui/notifications/request-teardown",params:e})}requestDisplayMode(e,t){return this._assertInitialized("requestDisplayMode"),this.request({method:"ui/request-display-mode",params:e},GF,t)}sendSizeChanged(e){return this.notification({method:"ui/notifications/size-changed",params:e})}setupSizeChangedNotifications(){let e=!1,t=0,i=0,r=()=>{e||(e=!0,requestAnimationFrame(()=>{e=!1;let o=document.documentElement,a=o.style.height;o.style.height="max-content";let l=Math.ceil(o.getBoundingClientRect().height);o.style.height=a;let c=Math.ceil(window.innerWidth);(c!==t||l!==i)&&(t=c,i=l,this.sendSizeChanged({width:c,height:l}))}))};r();let s=new ResizeObserver(r);return s.observe(document.documentElement),s.observe(document.body),()=>s.disconnect()}async connect(e=new yS(window.parent,window.parent),t){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");this._initializedSent=!1,await super.connect(e);try{let i=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:AF}},qF,t);if(i===void 0)throw Error(`Server sent invalid initialize result: ${i}`);this._hostCapabilities=i.hostCapabilities,this._hostInfo=i.hostInfo,this._hostContext=i.hostContext,await this.notification({method:"ui/notifications/initialized"}),this._initializedSent=!0,this.options?.autoResize&&this.setupSizeChangedNotifications()}catch(i){throw this.close(),i}}};function RA(n,e,t){let i,r=!1,s=()=>{r||i!==void 0||(i=requestAnimationFrame(()=>{i=void 0,!(r||!e())&&t(n.hidden?1:Math.max(1,Math.ceil(n.getBoundingClientRect().height)))}))},o=new ResizeObserver(s);return o.observe(n),s(),{refresh:s,dispose(){r=!0,o.disconnect(),i!==void 0&&cancelAnimationFrame(i)}}}var LA={name:"@kyun.si/codex-hongguo",version:"0.0.26",private:!0,license:"MIT",type:"module",engines:{node:">=22.16"},scripts:{"version:patch":"npm version patch --no-git-tag-version",preversion:"node scripts/version.mjs --next",version:"node scripts/version.mjs --sync",prebuild:"node scripts/version.mjs",build:"node scripts/build.mjs",test:"npm run build && node scripts/prepare-media.mjs && node --test test/*.test.mjs",package:"npm run build && node scripts/package.mjs","verify:install":"node scripts/verify-install.mjs","release:publish":"node scripts/publish.mjs"},dependencies:{"@modelcontextprotocol/ext-apps":"1.7.5","@modelcontextprotocol/sdk":"1.32.2","cross-spawn":"7.0.6",fflate:"0.8.3","hls.js":"1.7.4","m3u8-parser":"7.2.1","mpd-parser":"1.4.1",openhongguo:"0.2.0","xz-decompress":"0.2.3",zod:"4.6.7"},devDependencies:{"@types/node":"22.20.5",esbuild:"0.28.2",typescript:"5.9.3"}};var Bn=document.documentElement.dataset.host==="browser",CA=document.documentElement.dataset.surface==="waiting",_S="",Xn=Bn?null:new Rf({name:"\u7EA2\u679C\u77ED\u5267",version:LA.version},{},{autoResize:!CA}),xS,OA=()=>Xn?.getHostContext()?.locale||navigator.language,Lf=()=>Xn?.getHostContext()?.displayMode;async function NA(){if((await Xn?.requestDisplayMode({mode:"fullscreen"},{timeout:5e3}))?.mode!=="fullscreen")throw Error("\u5F53\u524D Codex \u65E0\u6CD5\u5728\u4F1A\u8BDD\u4E2D\u6253\u5F00\u64AD\u653E\u5668")}function DA(n){n&&(n.theme&&wA(n.theme),n.styles?.variables&&PA(n.styles.variables))}async function MA(n,e,t){if(Bn){let i=await fetch("context",{signal:AbortSignal.timeout(4e3)});if(!i.ok)throw Error("\u5206\u5C4F\u5DF2\u5931\u6548\uFF0C\u8BF7\u4ECE\u9762\u677F\u91CD\u65B0\u6253\u5F00");n(await i.json());return}Xn.ontoolresult=i=>{if(typeof i._meta?.panel!="string")return;_S=i._meta.panel;let r=typeof i._meta.waitingTurn=="string"?i._meta.waitingTurn:void 0;n({identified:!!i.structuredContent?.identified||!!r,waitingTurn:r})},Xn.onteardown=async()=>(xS?.dispose(),await e(),{}),Xn.onhostcontextchanged=i=>{DA(i),i.displayMode!==void 0&&(t(),xS?.refresh())},await Xn.connect(),DA(Xn.getHostContext()),CA&&(xS=RA(document.getElementById("waitingCard"),()=>(Lf()||"inline")==="inline",i=>{Xn.sendSizeChanged({height:i}).catch(()=>{})})),t()}async function Ie(n,e={},t=15e3){if(Bn){let r=await fetch("api/"+n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),keepalive:n==="save_progress",signal:AbortSignal.timeout(t)}),s=await r.json();if(!r.ok)throw Error(s.error||"\u5206\u5C4F\u8FDE\u63A5\u5DF2\u4E2D\u65AD");return s}if(!_S)throw Error("\u7B49\u5F85\u4F1A\u8BDD\u9762\u677F\u8FDE\u63A5");let i=await Xn.callServerTool({name:n,arguments:{...e,panel:_S}},{timeout:t});if(i.isError)throw Error(i.content?.[0]?.type==="text"?i.content[0].text:"\u672C\u673A\u670D\u52A1\u4E0D\u53EF\u8FBE");return i._meta?.data}var ES="https://hongguo.invalid/";function UA(n,e,t,i,r,s){if(!sr.isSupported())throw Error("\u5F53\u524D\u9762\u677F\u4E0D\u652F\u6301\u5206\u6BB5\u89E3\u7801\uFF0C\u53EF\u4F7F\u7528\u540C\u7A97\u5206\u5C4F");class o{context=null;stats=new li;abort(){this.stats.aborted=!0}destroy(){this.abort()}load(d,f,h){this.context=d,this.stats.loading.start=performance.now(),(async()=>{let p=d.url.slice(ES.length);if(!d.url.startsWith(ES))throw Error("\u65E0\u6548\u5A92\u4F53\u6765\u6E90");if(p==="index.m3u8")return i;let g=0,y;do{let b=await Ie("read_panel_chunk",{episodeId:e,stream:t,asset:p,offset:g},8e3);if(this.stats.aborted)return;if(!Number.isSafeInteger(b.size)||b.size<1||b.size>32*1024*1024)throw Error("\u5206\u6BB5\u957F\u5EA6\u65E0\u6548");y??=new Uint8Array(b.size);let S=atob(b.bytes);if(b.size!==y.length||!S.length||g+S.length>b.size)throw Error("\u5206\u6BB5\u4E0D\u5B8C\u6574");for(let x=0;x<S.length;x++)y[g+x]=S.charCodeAt(x);g+=S.length}while(g<y.length);return y.buffer})().then(p=>{this.stats.aborted||p===void 0||(this.stats.loading.first=this.stats.loading.end=performance.now(),this.stats.loaded=this.stats.total=typeof p=="string"?p.length:p.byteLength,h.onSuccess({url:d.url,data:p},this.stats,d,null))}).catch(()=>{this.stats.aborted||h.onError({code:0,text:"\u4FA7\u680F\u5206\u6BB5\u8BFB\u53D6\u5931\u8D25"},d,null,this.stats)})}}let a=new sr({loader:o,enableWorker:!1,maxBufferLength:16,maxMaxBufferLength:24,backBufferLength:12});a.on(sr.Events.MEDIA_ENDED,s),a.on(sr.Events.ERROR,(u,d)=>{d.fatal&&(d.type===sr.ErrorTypes.NETWORK_ERROR?r("\u4FA7\u680F\u5206\u6BB5\u8BFB\u53D6\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u70B9\u64AD"):r("\u4FA7\u680F\u65E0\u6CD5\u5904\u7406\u89C6\u9891\u5206\u6BB5\uFF0C\u53EF\u4F7F\u7528\u540C\u7A97\u5206\u5C4F"))});let l=u=>{u.disposition==="enforce"&&u.effectiveDirective==="media-src"&&(u.blockedURI==="blob"||u.blockedURI.startsWith("blob:"))&&r("\u684C\u9762\u5B89\u5168\u7B56\u7565\u963B\u6B62\u4E86\u4FA7\u680F\u8F7D\u5165\u672C\u5730\u89C6\u9891")},c=()=>{document.removeEventListener("securitypolicyviolation",l),a.destroy()};document.addEventListener("securitypolicyviolation",l);try{a.loadSource(ES+"index.m3u8"),a.attachMedia(n)}catch(u){throw c(),u}return c}function IS(n){switch(n){case 1:return"\u89C6\u9891\u52A0\u8F7D\u5DF2\u4E2D\u6B62\uFF0C\u53EF\u4EE5\u91CD\u65B0\u70B9\u64AD";case 2:return"\u8BFB\u53D6\u89C6\u9891\u6570\u636E\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u70B9\u64AD";case 3:return"\u64AD\u653E\u5668\u89E3\u7801\u89C6\u9891\u6570\u636E\u5931\u8D25\uFF0C\u53EF\u4F7F\u7528\u540C\u7A97\u5206\u5C4F";case 4:return"\u64AD\u653E\u5668\u65E0\u6CD5\u6253\u5F00\u89C6\u9891\u6765\u6E90\uFF0C\u53EF\u91CD\u65B0\u70B9\u64AD\u6216\u4F7F\u7528\u540C\u7A97\u5206\u5C4F";default:return"\u89C6\u9891\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u70B9\u64AD"}}function FA(n,e){return new Promise((t,i)=>{let r=()=>l(),s=()=>l(Error(IS(n.error?.code))),o=()=>l(e.reason),a=setTimeout(()=>l(Error("\u7B49\u5F85\u89C6\u9891\u5143\u6570\u636E\u8D85\u65F6\uFF0C\u8BF7\u91CD\u65B0\u70B9\u64AD")),3e4);function l(c){clearTimeout(a),n.removeEventListener("loadedmetadata",r),n.removeEventListener("error",s),e.removeEventListener("abort",o),c!==void 0?i(c):t()}n.addEventListener("loadedmetadata",r),n.addEventListener("error",s),e.addEventListener("abort",o),e.aborted&&o()})}function zA(n,e){return!!n&&!!e.turnId&&e.state==="submitted"&&n.turnId!==e.turnId}function BA(n,e){return!n||!e.turnId||e.state!=="stopped"&&e.state!=="interrupted"||n.turnId===e.turnId&&n.state!=="submitted"?null:e.state==="interrupted"?"\u672C\u8F6E\u5DF2\u4E2D\u65AD\uFF0C\u5DF2\u4E3A\u4F60\u6682\u505C":"\u672C\u8F6E\u5DF2\u505C\u6B62\uFF0C\u5DF2\u4E3A\u4F60\u6682\u505C"}var yt=n=>document.getElementById(n),hl=0,TS=!1;function JF(n){let e=n.hooks.status==="ready",t=n.hooks.events.some(s=>s.status==="needs_review");yt("setupTitle").textContent=Ce(t?"\u8BF7\u5BA1\u67E5\u7EA2\u679C\u7684\u56DE\u5408 Hooks":"\u5F00\u59CB\u4F7F\u7528\u7EA2\u679C");let i=[["Node",n.runtime,!0],["\u8FDB\u5EA6\u5E93",n.database?"\u53EF\u5199":"\u4E0D\u53EF\u7528",n.database],["\u64AD\u653E\u7EC4\u4EF6",n.ffmpeg?"\u5C31\u7EEA":"\u51C6\u5907\u4E2D",n.ffmpeg],["\u56DE\u5408\u8054\u52A8",e?"\u5DF2\u914D\u7F6E":n.hooks.status==="unknown"?"\u5F85\u786E\u8BA4":"\u5F85\u914D\u7F6E",e]];yt("setupRows").replaceChildren(...i.map(([s,o,a])=>{let l=document.createElement("div"),c=document.createElement("span"),u=document.createElement("span");return l.className="healthRow "+(a?"ok":"bad"),c.textContent=Ce(s),u.textContent=Ce(o),l.append(tr(a?"check":"alert"),c,u),l}));let r=n.database?n.ffmpeg?e?"\u56DE\u5408\u8054\u52A8\u5DF2\u5C31\u7EEA\u3002\u53EF\u5728\u8BBE\u7F6E\u4E2D\u914D\u7F6E\u4EFB\u52A1\u5F00\u59CB\u81EA\u52A8\u64AD\u653E\u548C\u4EFB\u52A1\u7ED3\u675F\u81EA\u52A8\u6682\u505C\u3002":n.hooks.status==="unknown"?"\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6 Hooks \u72B6\u6001\uFF0C\u8BF7\u5728\u5BBF\u4E3B\u8BBE\u7F6E\u4E2D\u6838\u5BF9\u3002\u73B0\u5728\u53EF\u4EE5\u5148\u624B\u52A8\u89C2\u770B\u3002":n.hooks.events.some(s=>s.status==="missing")?"\u5C1A\u672A\u53D1\u73B0\u5B8C\u6574\u7684\u56DE\u5408\u4E8B\u4EF6\u3002\u8BF7\u68C0\u67E5\u63D2\u4EF6\u5DF2\u542F\u7528\uFF0C\u5E76\u5728\u65B0\u7684\u672C\u5730\u5BF9\u8BDD\u4E2D\u91CD\u8BD5\u3002":"\u56DE\u5408\u8054\u52A8\u5C1A\u672A\u914D\u7F6E\u3002\u5B8C\u6210\u4E0B\u65B9\u64CD\u4F5C\u540E\u91CD\u65B0\u68C0\u67E5\uFF0C\u4E5F\u53EF\u4EE5\u5148\u624B\u52A8\u89C2\u770B\u3002":"\u64AD\u653E\u7EC4\u4EF6\u5C1A\u672A\u5C31\u7EEA\u3002\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u70B9\u51FB\u300C\u91CD\u65B0\u68C0\u67E5\u300D\uFF0C\u63D2\u4EF6\u4F1A\u81EA\u52A8\u51C6\u5907\u3002":"\u8FDB\u5EA6\u6682\u65F6\u65E0\u6CD5\u4FDD\u5B58\uFF0C\u8BF7\u68C0\u67E5\u7EA2\u679C\u7684\u6570\u636E\u76EE\u5F55\u6743\u9650\u3002";yt("setupHelp").textContent=Ce(r),yt("setupGuide").querySelector(".setupHooks").hidden=e}async function Df(n=!0){if(Bn)return;let e=++hl,t=yt("setupCheck");t.disabled=!0,n&&(yt("setupGuide").hidden=!1,yt("setupRows").replaceChildren(),yt("setupHelp").textContent=Ce("\u6B63\u5728\u68C0\u67E5\u2026"));try{let i=await Ie("get_setup_status");if(e!==hl)return;TS=i.dismissed,JF(i);let r=!i.database||!i.ffmpeg||i.hooks.status==="needs_attention";yt("setupGuide").hidden=!(n||!i.dismissed||r)}catch{if(e!==hl)return;yt("setupGuide").hidden=!(n||!TS),yt("setupRows").replaceChildren(),yt("setupHelp").textContent=Ce("\u68C0\u67E5\u672A\u5B8C\u6210\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u6216\u5728 Codex \u8BBE\u7F6E \u2192 Hooks \u6838\u5BF9\u56DE\u5408\u8054\u52A8\u3002"),yt("setupGuide").querySelector(".setupHooks").hidden=!1}finally{e===hl&&(t.disabled=!1)}}function jA(n){yt("setupOpen").hidden=Bn,yt("setupCheck").onclick=()=>{Df()},yt("setupDone").onclick=async()=>{++hl,TS=!0;let e=yt("setupDone");e.disabled=!0;try{await Ie("set_setup_dismissed",{dismissed:!0})}catch{n("\u672C\u6B21\u5DF2\u6536\u8D77\u6307\u5357\uFF0C\u6682\u65F6\u65E0\u6CD5\u4FDD\u5B58\u6B64\u8BBE\u7F6E\u3002")}finally{yt("setupGuide").hidden=!0,e.disabled=!1,yt("setupCheck").disabled=!1}},Df(!1)}function $S(n){return n.episodeId?Ce(n.kind==="next"?"\u770B\u4E0B\u4E00\u96C6":"\u7EE7\u7EED\u89C2\u770B")+" \xB7 "+n.title:n.title}function kS(n,e){return e.aborted?Promise.resolve(!1):new Promise(t=>{let i=new IntersectionObserver(a=>{let l=a[a.length-1];!document.hidden&&l.isIntersecting&&l.intersectionRect.width>0&&l.intersectionRect.height>0&&r(!0)},{threshold:[0,.01]}),r=a=>{i.disconnect(),document.removeEventListener("visibilitychange",o),e.removeEventListener("abort",s),t(a)},s=()=>r(!1),o=()=>{document.hidden||(i.unobserve(n),i.observe(n))};e.addEventListener("abort",s),document.addEventListener("visibilitychange",o),i.observe(n)})}async function AS(n,e,t,i,r,s=!1){let o=i?{turnId:i}:{};if(e.replaceChildren(),n.hidden=!1,!await kS(n,t))return;let{items:a}=await Ie("get_waiting_picks",{...o,inView:!0},9e4);if(!t.aborted){if(!a.length){s?r([]):n.hidden=!0;return}if(r(a),!!await kS(e,t))try{await Ie("mark_waiting_picks_shown",o)}catch{await kS(e,t)&&await Ie("mark_waiting_picks_shown",o).catch(()=>{})}}}function VA(n,e){let t=document.getElementById("waitingCard"),i=document.getElementById("waitingTitles"),r=document.getElementById("waitingMessage"),s=document.getElementById("waitingDismiss"),o=!1,a=!1,l=!1,c=!1,u=!0,d=!1,f=0,h,m,p,g;function y(){++f,m?.abort(),m=void 0,t.hidden=!0,i.replaceChildren(),r.textContent=""}s.onclick=()=>{c=!0,y(),Ie("dismiss_waiting_picks").catch(()=>{})};function b($){!o||c||!u||a||(r.textContent=Ce($ instanceof Error?$.message:"\u5F53\u524D Codex \u65E0\u6CD5\u5728\u4F1A\u8BDD\u4E2D\u6253\u5F00\u64AD\u653E\u5668"),t.hidden=!1)}async function S($=!1){if(!o)return;let P=Lf()||"inline";if(!$&&P===h)return;h=P;let k=++f;m?.abort();let D=m=new AbortController;if(P==="fullscreen"){if(a)return;let V=await(p??=Ie("activate_waiting_player"));if(k!==f)return;a=!0,t.hidden=!0,document.documentElement.dataset.surface="player",n(V);return}else p=void 0,a&&(a=!1,e(),document.documentElement.dataset.surface="waiting");if(c){y();return}let U=await Ie("get_waiting_status");if(k===f){if(u=U.visible,!u){y();return}r.textContent="",await AS(t,i,D.signal,void 0,V=>{let X=V.map(z=>{let B=document.createElement("button");return B.type="button",B.textContent=$S(z),B.onclick=()=>{x(z)},B}),q=document.createElement("button");q.type="button",q.textContent=Ce("\u66F4\u591A\u2026"),q.onclick=()=>{x()},i.replaceChildren(...X,q)},!0).catch(V=>{D.signal.aborted||b(V)})}}async function x($){if(!l){l=!0,r.textContent="";try{$?await Ie("select_waiting_pick",{seriesId:$.id}):await Ie("browse_waiting_catalog"),Lf()==="fullscreen"?await S(!0):(await NA(),t.hidden=!0)}catch(P){b(P),P instanceof Error&&P.message==="\u8FD9\u6761\u63A8\u8350\u5DF2\u7ED3\u675F"&&y()}finally{l=!1}}}async function _(){if(!(!o||a||l||c||document.hidden||d)){d=!0;try{let $=await Ie("get_waiting_status");if(!o||a||l||c)return;$.visible!==u&&(u=$.visible,u?await S(!0):y())}catch{!a&&!l&&(u=!1,y())}finally{d=!1}}}let I=()=>{S().catch(b)},T=()=>{!document.hidden&&o&&!a&&!c&&S(!0).catch(b)};return{connected(){o||(o=!0,g=setInterval(()=>{_()},1e3),document.addEventListener("visibilitychange",T),I())},modeChanged:I,dispose(){o=!1,clearInterval(g),document.removeEventListener("visibilitychange",T),y()}}}var F=n=>document.getElementById(n),Q=document.querySelector("video"),Yr=F("seek"),PS=F("play"),Of=F("center"),Zi=F("autonext"),jn=(n,e)=>{F(n).textContent=n==="title"?e:Ce(e)},We=n=>jn("notice",n),$t=n=>n instanceof Error?n.message:"\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5",no=n=>Math.floor(n/60)+":"+String(Math.floor(n%60)).padStart(2,"0"),XF=n=>new Promise(e=>setTimeout(e,n));function wn(n,e){let t=document.createElement("button");return t.textContent=Ce(n),t.onclick=()=>{Promise.resolve(e()).catch(i=>We($t(i)))},t}var gr={identified:!1},qt=null,at=null,Qe=null,qe=[],kt,vl="",kn,bt=[],$n=!1,ct=0,Qn=0,Ki=0,An=!1,Ot=!1,wS,RS=0,Wr=Promise.resolve(),Wt={autoPrompt:!0,autoplayNext:!0,autoPauseOnFinish:!0,autoPlayOnStart:!0,searchTerms:["\u603B\u88C1","\u91CD\u751F","\u9006\u88AD"]},dn="idle",Jr,LS,ml,to=0,pl=0,vr=[],Nf=null,ZA=document.documentElement.dataset.surface==="waiting",qA=Array.from(crypto.getRandomValues(new Uint32Array(4)),n=>n.toString(16).padStart(8,"0")).join(""),gl=!1,WA,GA=null,KA,DS,yr;function Uf(){yr=void 0;let n=DS;DS=void 0,n&&Ie("confirm_waiting_playback",{playbackId:n},1800).catch(()=>{})}function qi(){PS.disabled=Of.disabled=!Qe?.playable,F("pair").disabled=!Qe;let n=Ce(An?"\u53D6\u6D88\u51C6\u5907":Q.paused?"\u64AD\u653E":"\u6682\u505C"),e=An?"x":Q.paused?"play":"pause";oo(PS,e,n),oo(Of,e,n),F("stage").classList.toggle("playing",!Q.paused),F("stage").classList.toggle("busy",An),F("prev").disabled=!Qe||!qe.slice(0,qe.indexOf(Qe)).some(t=>t.playable),F("next").disabled=!Qe||!kt&&!qe.slice(qe.indexOf(Qe)+1).some(t=>t.playable),Of.hidden=An,document.querySelectorAll("#episodes button").forEach(t=>t.setAttribute("aria-pressed",String(t.dataset.id===Qe?.id)))}function Yi(n=!1){if(!$n||!at||!Qe||!Number.isFinite(Q.duration)||!Q.duration||!Q.currentTime&&!n)return Wr;let e={seriesId:at.id,episodeId:Qe.id,title:at.title,label:Qe.label,positionMs:Math.round((dn==="finished"||Q.ended?Q.duration:Q.currentTime)*1e3),durationMs:Math.round(Q.duration*1e3)};return Wr=Wr.then(()=>Ie("save_progress",{...e,...n&&e.positionMs===0?{reset:!0}:{}},1800)).then(()=>{}).catch(()=>We("\u89C2\u770B\u8FDB\u5EA6\u6682\u672A\u5199\u5165\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u670D\u52A1")),Wr}function un(n="",e=!1){e||(yr=void 0),n==="\u5DF2\u624B\u52A8\u6682\u505C"&&Uf(),ct++,Jr=void 0,An=!1,dn!=="finished"&&(dn="idle"),Q.pause(),qi();let t=!!at&&/本轮已停止|本轮已中断/.test(n);return n&&We(t?"":n),F("stopped").hidden=!t,t&&jn("whyStopped",n),Yi()}function Xr(){$n=!1,dn="idle",ml?.abort(),ml=void 0,F("stopped").hidden=!0,F("resumed").hidden=!0,LS?.(),LS=void 0,Q.removeAttribute("src"),Q.load()}function YA(n){un("",!0),Xr(),F("link").hidden=!0,F("linkValue").value="",Qe=n,to=Math.floor(Math.max(0,qe.indexOf(n))/50),We("");let e="\u7B2C "+n.number+" \u96C6",t=n.label.replace(/\s/g,"")!=="\u7B2C"+n.number+"\u96C6";jn("subtitle",[e,t?n.label:"",n.codec].filter(Boolean).join(" \xB7 ")),jn("time","0:00"),Yr.value="0",Ji(Yr),qi(),n.playable||We("\u8BE5\u96C6\u5F53\u524D\u4E0D\u53EF\u64AD\u653E\uFF0C\u8BF7\u68C0\u67E5\u7247\u6E90\u8BB8\u53EF\u6216 FFmpeg \u81EA\u68C0\u7ED3\u679C")}function yl(){let n=Math.ceil(qe.length/50);F("groups").replaceChildren(...Array.from({length:n>1?n:0},(e,t)=>{let i=wn(qe[t*50].number+"\u2013"+qe[Math.min(qe.length,(t+1)*50)-1].number,()=>{to=t,yl()});return i.setAttribute("aria-pressed",String(t===to)),i})),F("episodes").replaceChildren(...qe.slice(to*50,(to+1)*50).map(e=>{let t=wn(String(e.number),()=>Ff(e));return t.disabled=!e.playable,t.title=e.label,t.dataset.id=e.id,t})),F("moreEpisodes").hidden=!kt,F("episodeCount").textContent=qe.length?Ce(qe.length+(kt?"+":"")+" \u96C6"):"",qi()}async function ro(n,e,t=!1,i){let r=i&&e;F("home").hidden=!0,F("watch").hidden=!1,F("back").focus({preventScroll:!0}),window.scrollTo(0,0),to=0;let s=++Qn;un(),yr=t?i:void 0;let o=ct;Xr(),Qe=null,qe=[],kt=void 0,at=n,Wi(),Q.poster=n.cover||"",jn("title",n.title),jn("subtitle","\u6B63\u5728\u8BFB\u53D6\u5206\u96C6\u2026"),yl(),QA(),await Wr;let[a,l]=await Promise.all([Ie("get_episodes",{seriesId:n.id}),Ie("get_history",{seriesId:n.id})]);e??=l.items[0]?.episodeId;let c=a;if(s!==Qn)return;qe=c.items||[],kt=c.cursor;let u=new Set;for(;e&&!qe.some(h=>h.id===e)&&kt&&!u.has(kt);){if(u.add(kt),c=await Ie("get_episodes",{seriesId:n.id,cursor:kt}),s!==Qn)return;qe.push(...c.items),kt=c.cursor}let d=e&&qe.find(h=>h.id===e&&(!t||h.playable))||!r&&(t&&qe.find(h=>h.playable)||qe[0]),f=t&&Ot&&(ct===o||!!i&&yr===i);d?YA(d):jn("subtitle","\u6682\u65E0\u53EF\u7528\u5206\u96C6"),yl(),f&&d&&s===Qn&&await so(i)}async function Ff(n){YA(n),yl(),await so()}async function JA(){if(!at||!kt)return;let n=Qn,e=kt;try{let t=await Ie("get_episodes",{seriesId:at.id,cursor:e});if(n!==Qn||e!==kt)return;qe.push(...t.items),kt=t.cursor===e?void 0:t.cursor,yl()}catch(t){We($t(t))}}F("moreEpisodes").onclick=JA;async function XA(n=!1){if(!Qe)return;let e=Qe.id,t=Qn,i=ct,r=qe.slice(qe.indexOf(Qe)+1).find(o=>o.playable),s=new Set;for(;!r&&kt&&!s.has(kt);){if(s.add(kt),await JA(),Qn!==t||Qe?.id!==e||ct!==i)return;r=qe.slice(qe.indexOf(Qe)+1).find(o=>o.playable)}!Ot||n&&!Zi.checked||(r?await Ff(r):n&&un("\u672C\u96C6\u5DF2\u64AD\u5B8C"))}F("prev").onclick=()=>{let n=qe.slice(0,qe.indexOf(Qe)).reverse().find(e=>e.playable);n&&Ff(n)};F("next").onclick=()=>{XA()};F("random").onclick=()=>{let n=qe.filter(r=>r.playable),e=vr.find(r=>r.seriesId===at?.id),t=e?n.findIndex(r=>r.id===e.episodeId):-1,i=t<0?n.slice(0,1):n.slice(Math.min(t+1,n.length-1));i.length&&Ff(i[Math.floor(Math.random()*i.length)])};async function QF(){Uf(),document.fullscreenElement&&await document.exitFullscreen(),F("stage").classList.remove("expanded"),Mf(),We(""),++Qn;let n=un();Xr(),Qe=null,at=null,qe=[],kt=void 0,F("home").hidden=!1,F("watch").hidden=!0,F("link").hidden=!0,bt.length?Hi():Qr(),await n,await zf(),!at&&bt.length&&Hi()}F("back").onclick=()=>{QF().catch(n=>We($t(n)))};function QA(){document.querySelectorAll(".card").forEach(n=>n.setAttribute("aria-pressed",String(n.dataset.id===at?.id)))}function Hi(){let n=[],e=new Set(vr.map(o=>o.seriesId)),t=vl?void 0:bt.find(o=>!e.has(o.id))||bt[0],i=bt.filter(o=>o!==t),r=nw();if(r&&n.push(r),F("featured").replaceChildren(),t){let o=wn("",()=>ro(t,void 0,!0)),a=Sl(t.title,t.episodes?Ce(t.episodes+" \u96C6"):""),l=document.createElement("span"),c=document.createElement("small"),u=document.createElement("strong"),d=document.createElement("span");if(o.className="feature",o.dataset.id=t.id,o.setAttribute("aria-label",Ce("\u64AD\u653E")+" \xB7 "+t.title),l.className="featureText",c.className="eyebrow",c.textContent=Ce(e.has(t.id)?"\u770B\u8FC7":"\u63A8\u8350"),u.textContent=t.title,l.append(c,u),t.description){let f=document.createElement("span");f.className="desc",f.textContent=t.description,l.append(f)}d.className="playPill",d.append(tr("play"),Ce("\u64AD\u653E")),l.append(d),o.append(a,l),F("featured").append(o),n.push({span:a,s:t})}Wi(),F("cards").replaceChildren(...i.slice(pl*12,(pl+1)*12).map(o=>{let a=wn("",()=>ro(o,void 0,!0));a.className="card",a.dataset.id=o.id,a.title=o.title;let l=Sl(o.title,o.episodes?Ce(o.episodes+" \u96C6"):""),c=document.createElement("span");return c.className="cardTitle",c.textContent=o.title,a.append(l,c),n.push({span:l,s:o}),a})),QA();let s=Ki;(async()=>{for(let{span:o,s:a}of n){if(s!==Ki)return;if(!a.cover&&(a.hasCover||a.lookupCover))try{a.cover=(await Ie("get_cover",{seriesId:a.id},9e3)).cover}catch{}a.cover&&(BS(o,a.cover),at?.id===a.id&&(Q.poster=a.cover))}})()}function Wi(){let e=Wt.autoPrompt&&!!qt?.turnId&&qt.state==="submitted"&&!at&&!vl&&bt.length>0&&Nf!==qt.turnId?qt.turnId:null;if(e===GA)return;GA=e,KA?.abort();let t=F("prompt"),i=F("picks");if(!e){t.hidden=!0;return}let r=KA=new AbortController;AS(t,i,r.signal,e,s=>{i.replaceChildren(...s.map(o=>wn($S(o),()=>(Ie("mark_waiting_picks_shown",{turnId:e}).catch(()=>{}),ro(bt.find(a=>a.id===o.id)??o,o.episodeId,!0,e)))),wn("\u66F4\u591A\u2026",()=>{ew(),F("query").focus()}))}).catch(()=>{r.signal.aborted||(t.hidden=!0)})}function ew(){Nf=qt?.turnId||null,Nf&&Ie("dismiss_waiting_picks",{turnId:Nf}).catch(()=>{}),Wi()}F("dismiss").onclick=ew;function eo(n,e=""){let t=F("catalogStatus"),i=F("cards"),r=F("query");if(t.dataset.state=n==="loading"&&bt.length?"busy":n,t.replaceChildren(),e){let s=document.createElement("span");s.textContent=Ce(e),t.append(s)}t.dataset.state==="busy"&&t.prepend(tr("spin")),n==="error"&&t.append(wn("\u91CD\u8BD5",()=>Qr())),n==="empty"&&vl&&t.append(wn("\u6E05\u9664\u641C\u7D22",()=>(r.value="",Qr(!1,"")))),t.querySelectorAll("button").forEach(s=>s.className="btn"),n==="loading"&&!bt.length?i.replaceChildren(...Array.from({length:6},()=>{let s=document.createElement("div"),o=document.createElement("span"),a=document.createElement("span");return s.className="skel",s.setAttribute("aria-hidden","true"),o.className="skelArt",a.className="skelLine",s.append(o,a),s})):i.querySelector(".skel")&&i.replaceChildren()}async function Qr(n=!1,e=vl){let t=++Ki;n||(vl=e,bt=[],kn=void 0,pl=0,Hi());let i=n?pl+1:0;F("more").hidden=!0,eo("loading","\u6B63\u5728\u8BFB\u53D6\u7247\u5E93\u2026");let r=n?[...bt]:[],s=!1;!n&&!e&&Ie("list_series",{preview:!0},9e4).then(o=>{t!==Ki||s||!o.items.length||(bt=o.items,Hi(),F("catalogStatus").dataset.state!=="error"&&eo(""),F("more").hidden=bt.length<=13)}).catch(()=>{});try{let o=new Set,a=(i+1)*12+(e?0:1),l=!n;for(;l||r.length<a&&kn&&!o.has(kn);){l=!1,kn&&o.add(kn);let u=await Ie("list_series",{query:e,cursor:kn},9e4);if(t!==Ki)return;let d=new Set(r.map(f=>f.id));for(let f of u.items)d.has(f.id)||(d.add(f.id),r.push(f));kn=u.cursor,kn&&o.has(kn)&&(kn=void 0)}s=r.length>0,s&&(bt=r);let c=Math.max(1,Math.ceil((bt.length-(e?0:1))/12));if(n&&i>=c&&!kn&&!e){await Qr();return}pl=i%c,Hi(),bt.length?eo(""):e?eo("empty","\u6CA1\u6709\u627E\u5230\u76F8\u7B26\u7684\u5267\u76EE"):eo("error","\u7EA2\u679C\u6682\u65F6\u6CA1\u6709\u8FD4\u56DE\u63A8\u8350\u5267\u76EE"),F("more").hidden=c<=1&&!kn}catch(o){t===Ki&&(eo("error",$t(o)),F("more").hidden=!n)}}async function zf(){vr=(await Ie("get_history")).items,nw(),F("history").replaceChildren(...vr.map(n=>{let e=document.createElement("div"),t=document.createElement("strong"),i=document.createElement("small");e.className="historyRow";let r=wn("",()=>tw(n));r.className="historyItem",t.textContent=n.title,i.textContent=n.label+" \xB7 "+no(n.positionMs/1e3),r.append(t,i);let s=wn("",async()=>{await Wr,await Ie("remove_history",{seriesId:n.seriesId}),await zf(),Hi()}),o=Ce("\u79FB\u9664 "+n.title+" \u7684\u89C2\u770B\u5386\u53F2");return s.className="icon sm",s.setAttribute("aria-label",o),s.title=o,s.append(tr("x")),e.append(r,s),e})),F("historyCount").textContent=vr.length?String(vr.length):"",F("resume").hidden=!vr.length}function tw(n){return ro(bt.find(e=>e.id===n.seriesId)||{id:n.seriesId,title:n.title},n.episodeId,!0)}function nw(){let n=vr[0];if(!n){F("continue").replaceChildren();return}let e=bt.find(f=>f.id===n.seriesId)||{id:n.seriesId,title:n.title},t=wn("",()=>tw(n)),i=Sl(n.title),r=document.createElement("span"),s=document.createElement("small"),o=document.createElement("strong"),a=document.createElement("span"),l=document.createElement("span"),c=document.createElement("i"),u=document.createElement("span"),d=n.durationMs?Math.min(1,n.positionMs/n.durationMs):0;return t.className="resumeCard",t.setAttribute("aria-label",Ce("\u7EE7\u7EED\u89C2\u770B \xB7 "+n.title+" \xB7 "+n.label)),r.className="resumeText",s.className="eyebrow",s.textContent=Ce("\u7EE7\u7EED\u89C2\u770B"),o.textContent=n.title,a.className="meta",a.textContent=n.label+" \xB7 "+no(n.positionMs/1e3)+(n.durationMs?" / "+no(n.durationMs/1e3):""),l.className="bar",c.style.setProperty("--p",(d*100).toFixed(1)+"%"),l.append(c),r.append(s,o,a,l),u.className="resumePlay",u.append(tr("play")),t.append(i,r,u),F("continue").replaceChildren(t),{span:i,s:e}}function rw(){let n=qt?.state==="submitted";F("lamp").classList.toggle("on",n),jn("state",!gr.identified&&Bn?"\u672A\u5173\u8054\u5BF9\u8BDD":!qt||qt.state==="unknown"?"\u7B49\u5F85\u56DE\u5408\u5F00\u59CB":n?"\u5F53\u524D\u56DE\u5408\u8FDB\u884C\u4E2D":qt.state==="interrupted"?"\u56DE\u5408\u5DF2\u4E2D\u65AD":"\u56DE\u5408\u5DF2\u505C\u6B62")}function Bf(){return Ot?(wS??=ez().finally(()=>{wS=void 0}),wS):Promise.resolve()}async function ez(){try{let n=await Ie("get_run_state",{observeSession:!0,playerInstance:document.hidden?void 0:qA},1800);if(!Ot)return;if(n.preferences){let r=Wt.autoPrompt!==n.preferences.autoPrompt;Wt=n.preferences,Zi.checked=Wt.autoplayNext,r&&Wi()}let e=BA(qt,n),t=zA(qt,n),i=qt?.state!==n.state||qt?.turnId!==n.turnId;qt=n,i&&Wi(),rw(),e&&at&&Wt.autoPauseOnFinish?un(e):t&&Wt.autoPlayOnStart&&at&&Qe?.playable&&Q.paused&&!An&&so(n.turnId,!0)}catch{if(!Ot)return;F("lamp").classList.remove("on"),jn("state","\u672C\u673A\u72B6\u6001\u4E0D\u53EF\u8FBE")}}function tz(){let n=Q.duration;!Number.isFinite(n)||!$n||(Yr.value=String(Math.round(Q.currentTime/n*1e3)),Ji(Yr),jn("time",no(Q.currentTime)+" / "+no(n)))}async function so(n,e=!1){if(!Qe?.playable||!at||!Ot)return;yr=e?void 0:n;let t=++ct,i=Qe,r=at;An=!0,qi(),F("stopped").hidden=!0;try{if(!$n){We("\u6B63\u5728\u51C6\u5907\u64AD\u653E\u2026");let s=await Ie("prepare_playback",{episodeId:i.id,retry:!0}),o=Date.now()+24e4;for(;s.status==="preparing"&&t===ct&&Date.now()<o;){if(We("\u6B63\u5728\u672C\u673A\u51C6\u5907\u6574\u96C6\u2026"),await XF(700),t!==ct)return;s=await Ie("prepare_playback",{episodeId:i.id})}if(t!==ct)return;if(s.status!=="ready")throw Error(s.reason||"\u51C6\u5907\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5");let a=s;if(Bn!=="src"in a)throw Error("\u672C\u96C6\u64AD\u653E\u5730\u5740\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u8BD5");await Wr;let l=await Ie("get_history",{seriesId:r.id,episodeId:i.id});if(t!==ct)return;Xr();let c=new AbortController;ml=c;let u=FA(Q,c.signal),d=m=>{ml===c&&(c.abort(Error(m)),$n&&(un(m),Xr()))};try{"stream"in a?LS=UA(Q,i.id,a.stream,a.manifest,d,()=>{ml===c&&iw()}):(Q.src=a.src,Q.load())}catch(m){d($t(m))}if(await u,t!==ct)return;let f=l.items[0],h=f&&f.positionMs<f.durationMs?f.positionMs/1e3:0;Q.currentTime=h>0&&h<Q.duration-5?h:0,Q.currentTime>0&&(jn("resumeTime","\u5DF2\u4ECE "+no(h)+" \u7EE7\u7EED"),F("resumed").hidden=!1),$n=!0}if(n){let s=await Ie("get_run_state",{observeSession:!0},1800);if(t!==ct)return;if(s.turnId!==n||s.state!=="submitted"||e&&!s.preferences?.autoPlayOnStart){un(e?"":"\u63A8\u8350\u6240\u5C5E\u4EFB\u52A1\u5DF2\u7ED3\u675F\uFF0C\u70B9\u51FB\u64AD\u653E\u7EE7\u7EED\u89C2\u770B");return}}if(t!==ct||!Ot)return;An=!1,dn==="finished"&&(Q.currentTime=0),dn="playing",Q.playbackRate=parseFloat(F("speed").value),n&&!e&&(Q.muted=!0);try{await Q.play()}catch(s){if(t!==ct||!Ot)return;if(!(s instanceof DOMException&&["AbortError","NotAllowedError"].includes(s.name))||!document.hidden&&document.hasFocus()&&Jr?.action!==t)throw s instanceof DOMException&&s.name==="NotAllowedError"&&n&&!e?Error("\u5BBF\u4E3B\u963B\u6B62\u4E86\u81EA\u52A8\u64AD\u653E\uFF0C\u8BF7\u70B9\u51FB\u64AD\u653E\u7EE7\u7EED"):s;Vf();return}t===ct&&(Uf(),We("\u6B63\u5728\u64AD\u653E"),RS=Date.now(),qi())}catch(s){t===ct&&($n||Xr(),un($t(s)))}}function nz(){!Q.paused||An?un("\u5DF2\u624B\u52A8\u6682\u505C"):so()}for(let n of[Q,Of,PS,F("resumePlayback")])n.addEventListener("click",nz);function iw(){!$n||dn!=="playing"||!Number.isFinite(Q.duration)||Q.currentTime<Q.duration-1||(dn="finished",Yi(),Zi.checked&&Ot?XA(!0).catch(n=>We($t(n))):un("\u672C\u96C6\u5DF2\u64AD\u5B8C"),Wr.then(zf).catch(()=>{}))}Q.onended=iw;Zi.onchange=()=>{Ie("set_preferences",{autoplayNext:Zi.checked}).then(n=>{Wt=n}).catch(n=>We($t(n)))};Q.ontimeupdate=()=>{tz(),!Q.paused&&Date.now()-RS>=5e3&&(RS=Date.now(),Yi())};Q.onpause=()=>{qi(),$n&&Yi(),(document.hidden||!document.hasFocus()||Jr?.action===ct)&&Vf()};Q.onplay=qi;Q.onplaying=Uf;Q.onerror=()=>{$n&&(un(IS(Q.error?.code)),Xr())};Yr.oninput=()=>{Ji(Yr),$n&&Number.isFinite(Q.duration)&&(dn==="finished"&&(dn="idle"),Q.currentTime=Number(Yr.value)*Q.duration/1e3)};Yr.onchange=()=>{Yi(Q.currentTime===0)};Q.onloadedmetadata=()=>{Q.videoWidth&&Q.videoHeight&&(F("stage").style.aspectRatio=Q.videoWidth+"/"+Q.videoHeight)};F("restart").onclick=()=>{dn==="finished"&&(dn="idle"),Q.currentTime=0,F("resumed").hidden=!0,Yi(!0)};F("mute").onclick=()=>{Q.volume===0?(Q.volume=.7,Q.muted=!1):Q.muted=!Q.muted};async function sw(){let n=F("stage");if(document.fullscreenElement){await document.exitFullscreen();return}if(n.classList.contains("expanded")){n.classList.remove("expanded"),Mf();return}try{await n.requestFullscreen()}catch{n.classList.add("expanded"),Mf()}}F("fullscreen").onclick=()=>{sw().catch(n=>We($t(n)))};document.addEventListener("fullscreenchange",Mf);function Mf(){let n=F("stage"),e=!!document.fullscreenElement||n.classList.contains("expanded");n.classList.toggle("isFull",e),oo(F("fullscreen"),e?"collapse":"expand",Ce(e?"\u9000\u51FA\u5168\u5C4F":"\u5168\u5C4F"))}var HA;F("stage").addEventListener("pointermove",()=>{let n=F("stage");n.classList.add("awake"),clearTimeout(HA),HA=setTimeout(()=>n.classList.remove("awake"),2400)});F("stage").addEventListener("pointerleave",()=>F("stage").classList.remove("awake"));document.addEventListener("keydown",n=>{n.key==="Escape"&&F("stage").classList.contains("expanded")&&sw()});var io=F("volume");Q.onvolumechange=()=>{let n=Q.muted||Q.volume===0;oo(F("mute"),n?"mute":"volume",Ce(n?"\u53D6\u6D88\u9759\u97F3":"\u9759\u97F3")),F("mute").setAttribute("aria-pressed",String(n)),io.value=String(Math.round(Q.volume*100)),Ji(io)};Q.volume=Number(io.value)/100;Ji(io);io.oninput=()=>{Q.volume=Number(io.value)/100,Q.muted=Q.volume===0};F("speed").onchange=n=>Q.playbackRate=parseFloat(n.target.value);var bl=F("query"),CS,jf=!1;function OS(){clearTimeout(CS),jf||Qr(!1,bl.value.trim())}function NS(){clearTimeout(CS),++Ki,!jf&&(bl.value.trim()?CS=setTimeout(OS,400):OS())}bl.addEventListener("input",NS);bl.addEventListener("compositionstart",()=>{jf=!0,NS()});bl.addEventListener("compositionend",()=>{jf=!1,NS()});F("search").onsubmit=n=>{n.preventDefault(),OS()};F("more").onclick=()=>{Qr(!0)};async function rz(){let n=at,e=Qe;if(!(!n||!e))try{await un();let t=await Ie("create_browser_pairing",{seriesId:n.id,episodeId:e.id,title:n.title});if(at!==n||Qe!==e)return;F("linkValue").value=t.url,F("link").hidden=!1,F("link").scrollIntoView({block:"nearest"}),setTimeout(()=>{F("linkValue").value===t.url&&(F("link").hidden=!0,F("linkValue").value="")},6e4)}catch(t){We($t(t))}}F("pair").onclick=rz;F("copy").onclick=async()=>{let n=F("linkValue");try{await navigator.clipboard.writeText(n.value),We("\u5DF2\u590D\u5236\uFF0C\u8BF7\u5728 Codex \u5185\u7F6E\u6D4F\u89C8\u5668\u6253\u5F00")}catch{n.select(),We("\u94FE\u63A5\u5DF2\u9009\u4E2D\uFF0C\u8BF7\u590D\u5236\u5E76\u5728 Codex \u5185\u7F6E\u6D4F\u89C8\u5668\u6253\u5F00")}};F("settingsCancel").onclick=()=>F("prefs").click();F("setupOpen").onclick=()=>{F("settings").hidden=!0,F("prefs").setAttribute("aria-expanded","false"),Df()};F("prefs").onclick=()=>{F("settings").hidden=!F("settings").hidden,F("prefs").setAttribute("aria-expanded",String(!F("settings").hidden)),F("autoPrompt").checked=Wt.autoPrompt,F("autoPauseOnFinish").checked=Wt.autoPauseOnFinish,F("autoPlayOnStart").checked=Wt.autoPlayOnStart,F("terms").value=Wt.searchTerms.join("\uFF0C")};F("settings").onsubmit=n=>{n.preventDefault();let e=F("terms").value.split(/[,,]/).map(t=>t.trim()).filter(Boolean);Ie("set_preferences",{autoPrompt:F("autoPrompt").checked,autoPauseOnFinish:F("autoPauseOnFinish").checked,autoPlayOnStart:F("autoPlayOnStart").checked,searchTerms:e}).then(async t=>{Wt=t,Zi.checked=Wt.autoplayNext,F("settings").hidden=!0,F("prefs").setAttribute("aria-expanded","false"),Wi(),at||await Qr()}).catch(t=>We($t(t)))};F("health").onclick=async()=>{let n=F("healthInfo");if(n.hidden=!n.hidden,F("health").setAttribute("aria-expanded",String(!n.hidden)),!n.hidden){n.textContent=Ce("\u6B63\u5728\u68C0\u67E5\u2026");try{let e=await Ie("get_health"),t=[["Node",e.runtime,!0],["\u8FDB\u5EA6\u5E93",e.database?"\u53EF\u5199":"\u4E0D\u53EF\u7528",e.database],["\u64AD\u653E\u7EC4\u4EF6",e.ffmpeg?"\u5C31\u7EEA":"\u51C6\u5907\u4E2D",e.ffmpeg]];n.replaceChildren(...t.map(([i,r,s])=>{let o=document.createElement("div"),a=document.createElement("span"),l=document.createElement("span");return o.className="healthRow "+(s?"ok":"bad"),a.textContent=Ce(i),l.textContent=Ce(r),o.append(tr(s?"check":"alert"),a,l),o}))}catch(e){n.textContent=$t(e)}}};F("choose").onclick=async()=>{try{let n=await Ie("list_sessions");F("choices").replaceChildren(...n.items.map(e=>wn("\u2026"+e.suffix+" \xB7 "+new Date(e.at).toLocaleString(),async()=>{await Ie("select_session",{choice:e.choice}),gr.identified=!0,MS(Ot&&!document.hidden),F("choose").hidden=!0,F("choices").replaceChildren(),await Bf()}))),n.items.length||We("\u8FD8\u6CA1\u6709\u672C\u673A\u56DE\u5408\u8BB0\u5F55\uFF0C\u53EF\u5148\u624B\u52A8\u89C2\u770B")}catch(n){We($t(n))}};function MS(n){return gr.identified?Ie("set_player_visible",{instance:qA,visible:n},1800).catch(()=>{}):Promise.resolve()}async function ow(){Ot&&(Ot=!1,await Promise.all([un("\u5DF2\u6682\u505C\uFF0C\u70B9\u51FB\u64AD\u653E\u7EE7\u7EED",!0),MS(!1)]))}function aw(n){if(n.action!==ct||!Ot||!$n||dn!=="playing"||!Q.paused||Q.ended||Q.error)return;let e=Q.currentTime;n.lastPosition!==void 0&&Math.abs(e-n.lastPosition)<.25||(n.lastPosition=e,Q.play().then(()=>{n.action===ct&&!Q.paused&&We("\u6B63\u5728\u64AD\u653E")}).catch(()=>{}))}function Vf(){!Ot||dn!=="playing"||(Jr?.action!==ct&&(Jr={action:ct}),aw(Jr))}function lw(){let n=Jr;n&&(Jr=void 0,Bf().then(()=>aw({action:n.action})))}function cw(){Ot&&(MS(!document.hidden),document.hidden?(Vf(),Yi()):lw(),Bf())}function uw(){!gl||Ot||(Ot=!0,cw(),yr&&Qe?.playable&&Q.paused&&!An&&so(yr))}document.addEventListener("visibilitychange",cw);window.addEventListener("blur",Vf);window.addEventListener("focus",lw);window.addEventListener("pagehide",()=>{ow()});window.addEventListener("pageshow",uw);async function dw(n){if(gl)return;if(gl=!0,yr=void 0,DS=n?.play?n.playbackId:void 0,navigator.mediaSession&&(navigator.mediaSession.setActionHandler("pause",()=>{un("\u5DF2\u624B\u52A8\u6682\u505C")}),navigator.mediaSession.setActionHandler("play",()=>{Q.paused&&!An&&so()})),WA=window.setInterval(()=>{Bf()},1e3),F("pair").hidden=Bn||ZA,F("choose").hidden=Bn||gr.identified,qt=null,rw(),uw(),jA(We),Ie("get_preferences").then(t=>{gl&&(Wt=t,Zi.checked=Wt.autoplayNext??!0,Wi())}).catch(t=>We($t(t))),n?.pick){let t=n.pick;await ro(t,t.episodeId,n.play,n.turnId),n.reason==="turn-ended"&&at?.id===t.id&&Q.paused&&!An&&We("\u63A8\u8350\u6240\u5C5E\u4EFB\u52A1\u5DF2\u7ED3\u675F\uFF0C\u70B9\u51FB\u64AD\u653E\u7EE7\u7EED\u89C2\u770B");return}F("home").hidden=!1,F("watch").hidden=!0;let e=Qr();zf().then(()=>{!at&&vr.length&&bt.length&&Hi()}).catch(t=>We($t(t))),gr.selection&&await ro({id:gr.selection.seriesId,title:gr.selection.title||"\u7EA2\u679C\u77ED\u5267"},gr.selection.episodeId),await e}function fw(){let n=ow();return gl=!1,yr=void 0,navigator.mediaSession&&(navigator.mediaSession.setActionHandler("pause",null),navigator.mediaSession.setActionHandler("play",null)),window.clearInterval(WA),++Qn,Xr(),n}var Cf=ZA?VA(n=>{dw(n).catch(e=>We($t(e)))},fw):null;MA(n=>{FS(OA()),gr=n,Cf?n.waitingTurn&&Cf.connected():dw().catch(e=>We($t(e)))},async()=>{Cf?.dispose(),await fw()},()=>Cf?.modeChanged()).catch(n=>We($t(n)));})();
|
|
2064
2064
|
|
|
2065
2065
|
</script>
|
|
2066
2066
|
</body>
|