-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.html
More file actions
5702 lines (5150 loc) · 255 KB
/
Copy pathindex.html
File metadata and controls
5702 lines (5150 loc) · 255 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<link rel="shortcut icon" type="image/ico" href="assets/favicon.ico" />
<!-- DNS prefetch / preconnect hints for common Stremio and debrid endpoints.
Resolves TLS handshake + DNS lookup ahead of stream start so the
browser's <video> element can start filling its buffer immediately
instead of burning 200-500ms on each new connection on stream change. -->
<link rel="dns-prefetch" href="//real-debrid.com" />
<link rel="dns-prefetch" href="//download.real-debrid.com" />
<link rel="dns-prefetch" href="//alldebrid.com" />
<link rel="dns-prefetch" href="//premiumize.me" />
<link rel="dns-prefetch" href="//torbox.app" />
<link rel="dns-prefetch" href="//strem.io" />
<link rel="dns-prefetch" href="//cinemeta-live.strem.io" />
<link rel="dns-prefetch" href="//v3-cinemeta.strem.io" />
<link rel="dns-prefetch" href="//torrentio.strem.fun" />
<link rel="dns-prefetch" href="//images.metahub.space" />
<link rel="preconnect" href="https://download.real-debrid.com" crossorigin />
<link rel="preconnect" href="https://real-debrid.com" crossorigin />
<style>
[focused], :focus { outline: 2px solid #7b5bf5 !important; outline-offset: 2px; }
button:focus { outline: 3px solid #a78bfa !important; outline-offset: 2px; }
</style>
<title>Stremio - Freedom to Stream</title>
<script>
// Configurable streaming server URL
// Usage: ?server=http://192.168.1.50:11470
// Saved to localStorage so you only need to pass it once.
(function() {
var params = new URLSearchParams(window.location.search);
var server = params.get('server');
if (server) {
server = server.replace(/\/+$/, '');
localStorage.setItem('stremio_server_url', server);
}
window.__STREMIO_SERVER_URL__ = localStorage.getItem('stremio_server_url') || 'http://127.0.0.1:11470';
})();
</script>
<script>
// XSS escape helper for dynamic innerHTML values
function esc(s) { var d = document.createElement('div'); d.textContent = s; return d.innerHTML; }
</script>
<script>
// VIDAA keyboard fix v5 — intercept programmatic input.value changes
// The VIDAA system keyboard sets input.value directly without firing DOM events.
// This script: (1) overrides the value setter to fire synthetic events,
// (2) polls as fallback, (3) directly updates URL hash as nuclear option.
(function() {
window.__STREMIO_PATCH_VERSION__ = 5;
// Layer 1: Override HTMLInputElement.prototype.value setter
try {
var desc = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
if (desc && desc.set) {
var origSet = desc.set;
var origGet = desc.get;
var guard = false;
Object.defineProperty(HTMLInputElement.prototype, 'value', {
get: origGet,
set: function(v) {
var old = origGet.call(this);
origSet.call(this, v);
if (v !== old && !guard) {
guard = true;
try {
this.dispatchEvent(new Event('input', { bubbles: true }));
} catch(e) {}
guard = false;
}
},
configurable: true
});
}
} catch(e) {}
// Layer 2: Polling fallback (250ms — balanced for TV CPU)
var _prev = '';
setInterval(function() {
try {
var hash = window.location.hash || '';
if (hash.indexOf('#/search') !== 0) { _prev = ''; return; }
var el = document.querySelector('input[type="text"]')
|| document.querySelector('input[placeholder]')
|| document.querySelector('input');
if (!el) return;
var v = el.value || '';
if (v === _prev) return;
_prev = v;
try {
el.dispatchEvent(new Event('input', { bubbles: true }));
el.dispatchEvent(new Event('change', { bubbles: true }));
} catch(e) {}
// Layer 3: Nuclear option — directly update URL hash
if (v.length > 0) {
var encoded = encodeURIComponent(v);
if (hash.indexOf('query=' + encoded) === -1) {
window.location.hash = '#/search?query=' + encoded;
}
}
} catch(e) {}
}, 250);
})();
</script>
<script defer="defer" src="runtime.js?v=7"></script>
<script defer="defer" src="main.js?v=7"></script>
<script defer="defer" src="service.js?v=7"></script>
<script defer="defer" src="webOSTV.js?v=7"></script>
</head>
<body><noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<div id="splash" style="position:fixed;top:0;left:0;width:100%;height:100%;background:#0a0a14;z-index:100001;display:flex;flex-direction:column;align-items:center;justify-content:center;">
<img src="logo.png" width="100" style="margin-bottom:1.5rem;opacity:0.9;">
<div style="color:rgba(255,255,255,0.5);font-size:1rem;font-family:PlusJakartaSans,sans-serif;">Loading...</div>
<div style="margin-top:1rem;width:120px;height:3px;background:rgba(255,255,255,0.1);border-radius:2px;overflow:hidden;">
<div id="splash-bar" style="width:0%;height:100%;background:#7b5bf5;border-radius:2px;transition:width 0.3s;"></div>
</div>
</div>
<div id="patch-version" style="position:fixed;bottom:4px;right:8px;color:rgba(255,255,255,0.3);font-size:10px;z-index:99999;pointer-events:none;">v7</div>
</body>
<script>
window.__BUILD_COMMIT__ = 'b5e0f7d';
// Register service worker with auto-update
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./sw.js').then(function(reg) {
reg.addEventListener('updatefound', function() {
var newWorker = reg.installing;
if (newWorker) {
newWorker.addEventListener('statechange', function() {
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
newWorker.postMessage('skipWaiting');
console.log('[sw] New version installed, refreshing...');
setTimeout(function() { location.reload(); }, 1000);
}
});
}
});
}).catch(function() {});
}
</script>
<script>
// Server URL sync — push ?server= URL into WASM core
(function() {
var serverUrl = window.__STREMIO_SERVER_URL__;
if (!serverUrl || serverUrl === 'http://127.0.0.1:11470') return;
var attempts = 0;
var interval = setInterval(function() {
if (++attempts > 60) { clearInterval(interval); return; }
if (!window.core) return;
clearInterval(interval);
window.core.getState('ctx').then(function(ctxState) {
if (!ctxState || !ctxState.profile || !ctxState.profile.settings) return;
var currentSettings = ctxState.profile.settings;
if (currentSettings.streamingServerUrl === serverUrl) {
console.log('[server-sync] URL already correct');
return;
}
console.log('[server-sync] Syncing URL to WASM core:', serverUrl);
var newSettings = {};
for (var k in currentSettings) newSettings[k] = currentSettings[k];
newSettings.streamingServerUrl = serverUrl;
window.core.dispatch({ action: 'Ctx', args: { action: 'UpdateSettings', args: newSettings } }, 'ctx').then(function() {
console.log('[server-sync] Settings updated, reloading streaming server');
return window.core.dispatch({ action: 'StreamingServer', args: { action: 'Reload' } }, 'streaming_server');
}).then(function() {
console.log('[server-sync] Streaming server reloaded successfully');
}).catch(function(e) {
console.error('[server-sync] Error:', e);
});
}).catch(function(e) {
console.error('[server-sync] Failed to get ctx state:', e);
});
}, 500);
})();
</script>
<script>
// Auto-reload streaming server when URL changes in Settings UI
(function() {
var lastKnownUrl = null;
var watchDelay = 0;
setInterval(function() {
if (++watchDelay < 5) return; // Skip first 10 seconds to let server-sync finish
if (!window.core) return;
if ((window.location.hash || '').indexOf('#/settings') !== 0) return;
window.core.getState('ctx').then(function(state) {
if (!state || !state.profile || !state.profile.settings) return;
var url = state.profile.settings.streamingServerUrl;
if (lastKnownUrl === null) { lastKnownUrl = url; return; }
if (url !== lastKnownUrl) {
console.log('[server-watch] URL changed:', lastKnownUrl, '->', url);
lastKnownUrl = url;
window.__STREMIO_SERVER_URL__ = url;
try { localStorage.setItem('stremio_server_url', url); } catch(e) {}
window.core.dispatch({ action: 'StreamingServer', args: { action: 'Reload' } }, 'streaming_server').then(function() {
console.log('[server-watch] Streaming server reloaded');
}).catch(function(e) {
console.error('[server-watch] Reload failed:', e);
});
}
}).catch(function() {});
}, 2000);
})();
</script>
<script>
// Smart DV/HDR stream handling
// Based on live hardware testing on Hisense PX1HE (100L5H):
// - DV+HDR in MKV at 4K: PLAYS NATIVELY (no transcoding needed)
// - DV+HDR in MP4: crashes browser (container issue)
// - Content >4K (4320p/8K upscale): black screen (decoder limit)
// - HEVC 4K 10-bit: plays fine
// - AV1: not supported
// NOTE: Other TVs may have different codec support — users can disable
// the playback warning via Settings > STREMIO TV > Playback Warning
(function() {
var WARN_KEY = 'stremio_playback_warning';
window.__DV_PROFILE7_DETECTED__ = false;
window.__STREAM_INFO__ = {};
// Default OFF — do not block streams that look stalled, many eventually recover
// and the full-screen overlay blocks the TV remote from navigating elsewhere.
// Users who want the codec/stall helper can opt in via Settings > STREMIO TV > Playback Warning.
try { if (localStorage.getItem(WARN_KEY) === null) localStorage.setItem(WARN_KEY, 'false'); } catch(e) {}
function isWarningEnabled() {
try { return localStorage.getItem(WARN_KEY) === 'true'; } catch(e) { return false; }
}
// Monitor video element for playback failures — warn only on actual failure
var watchInterval = null;
function startPlaybackWatch() {
if (watchInterval) return;
watchInterval = setInterval(function() {
var hash = window.location.hash || '';
if (hash.indexOf('#/player/') !== 0) {
if (watchInterval) { clearInterval(watchInterval); watchInterval = null; }
return;
}
if (!isWarningEnabled()) return; // User disabled playback warning
if (window.__QUIET_PLAYER_ACTIVE__) return; // Freed CPU for the video decoder
var video = document.querySelector('video');
if (!video) return;
// Check for >4K resolution (decoder limit)
if (video.videoWidth > 4096 || video.videoHeight > 2160) {
console.warn('[stream] Resolution ' + video.videoWidth + 'x' + video.videoHeight + ' exceeds 4K — may cause issues');
window.__STREAM_INFO__.oversize = true;
}
// Detect stalled DV playback (black screen = video loads but no frames render)
if (video.readyState >= 2 && video.currentTime === 0 && !video.paused && !video.ended) {
// Video thinks it's playing but stuck at 0 — possible black screen
if (!window.__STREAM_INFO__.stallCheck) {
window.__STREAM_INFO__.stallCheck = Date.now();
} else if (Date.now() - window.__STREAM_INFO__.stallCheck > 8000) {
// 8 seconds with no progress — likely a black screen
console.warn('[stream] Playback stalled — possible codec/container issue');
showPlaybackWarning();
window.__STREAM_INFO__.stallCheck = null;
}
} else {
window.__STREAM_INFO__.stallCheck = null;
}
}, 2000);
}
// Watch for player route
var wasInPlayer = false;
setInterval(function() {
var hash = window.location.hash || '';
var inPlayer = hash.indexOf('#/player/') === 0;
if (inPlayer) {
if (!wasInPlayer) { window.__STREAM_INFO__ = {}; }
startPlaybackWatch();
}
if (!inPlayer) { window.__FORCE_TRANSCODE__ = false; }
wasInPlayer = inPlayer;
}, 1000);
// Intercept probe responses — log codec info but DON'T block playback
var origFetch = window.fetch;
window.fetch = function(url, opts) {
var result = origFetch.apply(this, arguments);
try {
if (typeof url === 'string' && url.indexOf('/hlsv2/') !== -1 && url.indexOf('probe') !== -1) {
result.then(function(response) {
var cloned = response.clone();
cloned.json().then(function(data) {
if (data && Array.isArray(data.streams)) {
for (var i = 0; i < data.streams.length; i++) {
var s = data.streams[i];
if (s.track === 'video') {
window.__STREAM_INFO__.videoCodec = s.codec;
window.__STREAM_INFO__.width = s.width;
window.__STREAM_INFO__.height = s.height;
if (s.codec && /^dv(he|h1)/.test(s.codec)) {
window.__DV_PROFILE7_DETECTED__ = s.codec;
console.log('[DV] Detected:', s.codec, s.width + 'x' + s.height, '— letting browser attempt native playback');
}
}
}
}
}).catch(function() {});
});
}
} catch(e) {}
return result;
};
function showPlaybackWarning() {
var existing = document.getElementById('dv-warning');
if (existing) return;
var codec = window.__STREAM_INFO__.videoCodec || 'unknown';
var res = (window.__STREAM_INFO__.width || '?') + 'x' + (window.__STREAM_INFO__.height || '?');
var isOversize = window.__STREAM_INFO__.width > 4096 || window.__STREAM_INFO__.height > 2160;
var overlay = document.createElement('div');
overlay.id = 'dv-warning';
overlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.92);z-index:100000;display:flex;flex-direction:column;align-items:center;justify-content:center;color:white;font-family:PlusJakartaSans,sans-serif;';
var title = isOversize ? 'Resolution Too High' : 'Playback Issue Detected';
// Only advertise transcode as a remedy when a REAL streaming server is
// configured. Bare-TV / Real-Debrid users have no server, so telling them
// to "transcode via your streaming server" is a dead end.
var srvUrlW = window.__STREMIO_SERVER_URL__ || '';
var serverReadyW = srvUrlW && srvUrlW !== 'http://127.0.0.1:11470';
var detail = isOversize
? 'This stream is ' + esc(res) + ' which exceeds your TV\'s 4K decode limit. Try a 2160p or 1080p source instead.'
: 'This stream (' + esc(codec) + ' @ ' + esc(res) + ') is not rendering. The container format may be incompatible. Try a 1080p or MP4 version of this title'
+ (serverReadyW ? ', or use your streaming server to transcode it.' : '. (Transcoding needs a separate Stremio streaming-server PC — Settings ▸ Server.)');
var inner = '<div style="font-size:2.2rem;margin-bottom:1rem;font-weight:700;">' + title + '</div>'
+ '<div style="font-size:1.1rem;color:rgba(255,255,255,0.65);margin-bottom:2rem;text-align:center;max-width:560px;line-height:1.5;">' + detail + '</div>'
+ '<div id="dv-actions" style="display:flex;gap:1.2rem;"></div>';
overlay.innerHTML = inner;
var actionsDiv = overlay.querySelector('#dv-actions');
// Native Player button (VIDAA only)
var hasNativePlayer = false;
try { hasNativePlayer = typeof omi_platform !== 'undefined' && typeof omi_platform.sendPlatformMessage === 'function'; } catch(e) {}
if (hasNativePlayer) {
var nativeBtn = document.createElement('button');
nativeBtn.textContent = 'Open in Native Player';
nativeBtn.style.cssText = 'padding:0.9rem 2.2rem;font-size:1.1rem;background:#7b5bf5;color:white;border:none;border-radius:8px;cursor:pointer;font-family:inherit;font-weight:600;';
nativeBtn.setAttribute('tabindex', '0');
nativeBtn.onfocus = function() { this.style.outline = '3px solid #a78bfa'; };
nativeBtn.onblur = function() { this.style.outline = 'none'; };
nativeBtn.onclick = function() {
var video = document.querySelector('video');
var streamUrl = video ? video.currentSrc || video.src : null;
if (!streamUrl) return;
// M2: do NOT remove the overlay until we KNOW the handoff worked.
// The launcher resolves a verified boolean; only on success do we
// clear the stall flag + dismiss. On failure the recovery UI stays.
nativeBtn.textContent = 'Trying…';
nativeBtn.disabled = true;
Promise.resolve(window.__launchNativePlayer(streamUrl)).then(function(opened) {
if (opened) {
window.__STREAM_INFO__.stallCheck = null;
overlay.remove();
} else {
nativeBtn.textContent = 'TV player didn’t open — try another option';
nativeBtn.disabled = false;
}
});
};
actionsDiv.appendChild(nativeBtn);
}
// H4/M3: Force Transcode only works with a REAL streaming server. Gate it
// exactly like the Blue-button handler does. Without a server, don't
// pretend transcode is available — show it disabled with an honest label.
var transBtn = document.createElement('button');
transBtn.textContent = serverReadyW ? 'Force Transcode' : 'Transcode (needs streaming-server PC)';
var transBg = serverReadyW ? (hasNativePlayer ? 'rgba(255,255,255,0.1)' : '#7b5bf5') : 'rgba(255,255,255,0.05)';
var transColor = serverReadyW ? 'white' : 'rgba(255,255,255,0.4)';
var transBorder = serverReadyW ? (hasNativePlayer ? '1px solid rgba(255,255,255,0.25)' : 'none') : '1px solid rgba(255,255,255,0.1)';
transBtn.style.cssText = 'padding:0.9rem 2.2rem;font-size:1.1rem;background:' + transBg + ';color:' + transColor + ';border:' + transBorder + ';border-radius:8px;cursor:' + (serverReadyW ? 'pointer' : 'not-allowed') + ';font-family:inherit;font-weight:600;';
transBtn.setAttribute('tabindex', '0');
if (!serverReadyW) {
transBtn.disabled = true;
transBtn.setAttribute('aria-disabled', 'true');
transBtn.title = 'Force transcode requires a separate Stremio streaming server (Settings ▸ Server). Real-Debrid / bare-TV setups have none.';
}
transBtn.onfocus = function() { this.style.outline = '3px solid #a78bfa'; };
transBtn.onblur = function() { this.style.outline = 'none'; };
transBtn.onclick = function() {
if (!serverReadyW) return; // gated: no real server, do nothing
window.__STREAM_INFO__.stallCheck = null;
window.__FORCE_TRANSCODE__ = true;
overlay.remove();
var ch = window.location.hash;
window.location.hash = '#/home';
setTimeout(function() { window.location.hash = ch; }, 100);
};
actionsDiv.appendChild(transBtn);
var skipBtn = document.createElement('button');
skipBtn.textContent = 'Try Another Source';
skipBtn.style.cssText = 'padding:0.9rem 2.2rem;font-size:1.1rem;background:rgba(255,255,255,0.1);color:white;border:1px solid rgba(255,255,255,0.25);border-radius:8px;cursor:pointer;font-family:inherit;font-weight:600;';
skipBtn.setAttribute('tabindex', '0');
skipBtn.onfocus = function() { this.style.outline = '3px solid #a78bfa'; };
skipBtn.onblur = function() { this.style.outline = 'none'; };
skipBtn.onclick = function() {
window.__STREAM_INFO__.stallCheck = null;
overlay.remove();
window.history.back();
};
actionsDiv.appendChild(skipBtn);
var dismissBtn = document.createElement('button');
dismissBtn.textContent = 'Dismiss';
dismissBtn.style.cssText = 'padding:0.9rem 2.2rem;font-size:1.1rem;background:rgba(255,255,255,0.05);color:rgba(255,255,255,0.4);border:1px solid rgba(255,255,255,0.1);border-radius:8px;cursor:pointer;font-family:inherit;font-weight:600;';
dismissBtn.setAttribute('tabindex', '0');
dismissBtn.onfocus = function() { this.style.outline = '3px solid #a78bfa'; };
dismissBtn.onblur = function() { this.style.outline = 'none'; };
dismissBtn.onclick = function() { window.__STREAM_INFO__.stallCheck = null; overlay.remove(); };
actionsDiv.appendChild(dismissBtn);
document.body.appendChild(overlay);
setTimeout(function() { transBtn.focus(); }, 100);
}
window.__showPlaybackWarning = showPlaybackWarning;
// Register settings toggle
var regInterval = setInterval(function() {
if (!window.__registerVidaaSettingsItem) return;
clearInterval(regInterval);
window.__registerVidaaSettingsItem({
id: 'playback-warning-toggle',
type: 'toggle',
label: 'Playback Warning',
description: 'Shows a helper overlay when playback stalls (offers native player / transcode / go-back). OFF by default — most streams eventually recover and the overlay blocks the remote.',
lsKey: WARN_KEY,
defaultValue: false
});
}, 200);
})();
</script>
<script>
// Enhanced error messages for TV users
(function() {
window.__STREMIO_ERROR_ENHANCER__ = function(err) {
if (!err) return null;
var msg = err.message || '';
var code = err.code || 0;
if (window.__DV_PROFILE7_DETECTED__ && window.__STREAM_INFO__ && window.__STREAM_INFO__.stallCheck) {
return 'Dolby Vision stream (' + window.__DV_PROFILE7_DETECTED__ + ') failed to render. Try an MKV source or use a streaming server for transcoding.';
}
if (msg.indexOf('not supported') !== -1 || msg === 'MEDIA_ERR_SRC_NOT_SUPPORTED') {
return 'This video codec is not supported by your TV. Try a different source, or configure a streaming server for transcoding (Settings \u2192 Server).';
}
if (msg === 'MEDIA_ERR_DECODE') {
return 'Video decode error \u2014 the codec may not be compatible. Try a different source or enable transcoding.';
}
if (msg === 'MEDIA_ERR_NETWORK') {
return 'Network error \u2014 check your connection and streaming server status.';
}
if (msg.indexOf('CONVERT_FAILED') !== -1 || msg.indexOf('transcode') !== -1 || msg.indexOf('Transcode') !== -1) {
return 'Transcoding failed \u2014 verify your streaming server is running and accessible.';
}
return msg;
};
})();
</script>
<script>
// Splash screen — remove when core is ready
(function() {
var bar = document.getElementById('splash-bar');
var progress = 0;
var tick = setInterval(function() {
progress = Math.min(progress + Math.random() * 15, 90);
if (bar) bar.style.width = progress + '%';
}, 400);
var safetyTimer = null;
var check = setInterval(function() {
if (window.core && typeof window.core.getState === 'function') {
clearInterval(check);
clearInterval(tick);
if (safetyTimer) clearTimeout(safetyTimer);
if (bar) bar.style.width = '100%';
setTimeout(function() {
var splash = document.getElementById('splash');
if (splash) {
splash.style.transition = 'opacity 0.3s';
splash.style.opacity = '0';
setTimeout(function() { splash.remove(); }, 300);
}
}, 200);
}
}, 300);
// Safety: remove after 30s regardless
safetyTimer = setTimeout(function() {
clearInterval(check);
clearInterval(tick);
var splash = document.getElementById('splash');
if (splash) splash.remove();
}, 30000);
})();
</script>
<script>
// Resolution indicator in player
(function() {
var indicator = null;
var hideTimer = null;
function createIndicator() {
if (indicator) return indicator;
indicator = document.createElement('div');
indicator.id = 'quality-indicator';
indicator.style.cssText = 'position:fixed;top:14px;right:14px;background:rgba(0,0,0,0.75);color:white;padding:5px 12px;border-radius:6px;font-size:13px;z-index:99998;pointer-events:none;font-family:monospace;display:none;backdrop-filter:blur(4px);';
document.body.appendChild(indicator);
return indicator;
}
function showIndicator() {
if (!indicator) return;
indicator.style.display = 'block';
indicator.style.opacity = '1';
clearTimeout(hideTimer);
hideTimer = setTimeout(function() {
if (indicator) { indicator.style.transition = 'opacity 0.5s'; indicator.style.opacity = '0'; }
}, 5000);
}
document.addEventListener('keydown', function() {
if ((window.location.hash || '').indexOf('#/player/') === 0 && indicator) {
indicator.style.transition = 'none';
showIndicator();
}
});
setInterval(function() {
var hash = window.location.hash || '';
if (hash.indexOf('#/player/') !== 0) {
if (indicator) { indicator.style.display = 'none'; indicator.style.opacity = '0'; }
return;
}
if (!indicator) createIndicator();
var video = document.querySelector('video');
if (!video || !video.videoWidth) return;
var el = indicator;
var w = video.videoWidth, h = video.videoHeight;
var label;
if (w >= 3840) label = '4K';
else if (w >= 2560) label = '1440p';
else if (w >= 1920) label = '1080p';
else if (w >= 1280) label = '720p';
else if (w >= 854) label = '480p';
else label = w + 'x' + h;
// Append codec/HDR info from VIDAA state
if (window.__VIDAA_STATE__) {
if (window.__VIDAA_STATE__.videoCodec) label += ' ' + window.__VIDAA_STATE__.videoCodec;
if (window.__VIDAA_STATE__.hdr) label += ' ' + window.__VIDAA_STATE__.hdr;
if (window.__VIDAA_STATE__.dolbyVision) label += ' DV';
}
if (window.__STREAM_INFO__ && window.__STREAM_INFO__.videoCodec) {
if (label.indexOf(window.__STREAM_INFO__.videoCodec) === -1) {
label += ' ' + window.__STREAM_INFO__.videoCodec;
}
}
// Buffer health dot
var bufferSec = 0;
try { if (video.buffered.length) bufferSec = video.buffered.end(video.buffered.length - 1) - video.currentTime; } catch(e) {}
var dotColor = bufferSec > 30 ? '#4ade80' : bufferSec > 10 ? '#fbbf24' : '#f87171';
el.innerHTML = '<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:' + dotColor + ';margin-right:6px;vertical-align:middle;"></span>' + esc(label);
// Only refresh content — do NOT auto-show. The indicator is shown on Red button
// press (in player with stats disabled) or on any keydown in player. This prevents
// the icon from being stuck visible permanently.
}, 3000);
})();
</script>
<script>
// VIDAA remote color button mappings
(function() {
var healthOverlay = null;
function showToast(msg, bg, ms) {
var t = document.createElement('div');
t.style.cssText = 'position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:' + (bg || 'rgba(0,0,0,0.88)') + ';color:white;padding:16px 28px;border-radius:10px;font-size:1.05rem;font-family:PlusJakartaSans,sans-serif;z-index:100000;pointer-events:none;text-align:center;max-width:500px;';
t.textContent = msg;
document.body.appendChild(t);
setTimeout(function() { t.remove(); }, ms || 2500);
}
document.addEventListener('keydown', function(e) {
var code = e.keyCode;
// Red (403) — toggle quality indicator (only outside the player).
// Inside the player the Stream Stats overlay owns Red (registered on window).
// Outside the player, show the quality indicator even though the interval
// normally only renders it in player — just to confirm the button is wired.
if (code === 403) {
var inPlayer = (window.location.hash || '').indexOf('#/player/') !== -1;
if (!inPlayer) {
var qi = document.getElementById('quality-indicator');
if (qi) qi.style.display = qi.style.display === 'none' ? 'block' : 'none';
}
}
// Green (404) — toggle server health overlay
if (code === 404) {
if (healthOverlay) { healthOverlay.remove(); healthOverlay = null; return; }
var h = window.__SERVER_HEALTH__ || {};
var url = window.__STREMIO_SERVER_URL__ || 'default';
var isDefault = !url || url === 'default' || url === 'http://127.0.0.1:11470';
var statusColor, statusText;
if (h.status === 'online') { statusColor = '#4ade80'; statusText = 'online'; }
else if (isDefault) { statusColor = '#94a3b8'; statusText = 'not configured'; }
else { statusColor = '#f87171'; statusText = h.status || 'offline'; }
healthOverlay = document.createElement('div');
healthOverlay.style.cssText = 'position:fixed;bottom:60px;right:14px;background:rgba(0,0,0,0.9);color:white;padding:16px 20px;border-radius:10px;font-size:13px;z-index:99999;font-family:monospace;min-width:260px;backdrop-filter:blur(4px);';
var note = isDefault && h.status !== 'online'
? '<div style="margin-top:8px;color:rgba(255,255,255,0.6);font-size:11px;line-height:1.4;">Streaming server is optional. Real-Debrid users do not need one.</div>'
: '';
healthOverlay.innerHTML = '<div style="font-weight:700;margin-bottom:8px;font-size:14px;">Server Health</div>'
+ '<div>Status: <span style="color:' + statusColor + ';">' + esc(statusText) + '</span></div>'
+ '<div>Latency: ' + (h.latency ? h.latency + 'ms' : 'N/A') + '</div>'
+ '<div>Version: ' + esc(h.version || 'N/A') + '</div>'
+ '<div>URL: ' + esc(url) + '</div>'
+ note;
document.body.appendChild(healthOverlay);
setTimeout(function() { if (healthOverlay) { healthOverlay.remove(); healthOverlay = null; } }, 10000);
}
// Blue (406) — force transcode current stream (reloads player).
// Only useful if a streaming server is configured. Do not require the
// cached health flag here; health checks are intentionally quiet in the
// player and can be stale even when the server is reachable.
if (code === 406) {
var ph = window.location.hash || '';
if (ph.indexOf('#/player/') !== 0) return;
var srvUrl = window.__STREMIO_SERVER_URL__ || '';
var serverReady = srvUrl && srvUrl !== 'http://127.0.0.1:11470';
if (!serverReady) {
showToast('Force transcode needs a streaming server.\nCheck Settings > Server.', 'rgba(180,60,60,0.92)', 3500);
return;
}
window.__FORCE_TRANSCODE__ = true;
console.log('[remote] Force transcode enabled, reloading stream');
showToast('Forcing transcode...', null, 1500);
try {
window.location.hash = '#/home';
setTimeout(function() { window.location.hash = ph; }, 200);
} catch(err) {
console.error('[remote] Force transcode reload failed:', err.message);
showToast('Could not reload stream', 'rgba(180,60,60,0.92)', 2500);
}
}
// Info (457) — show one-shot stream info panel.
// Only fires when Stream Stats overlay is explicitly disabled — otherwise
// Info is owned by the stats overlay and we'd be double-triggering.
// Some remotes (55Q6QV projector, many Hisense projectors) have no Info
// button at all, so Red is accepted as an alias when in the player and
// the stats overlay is off.
var inPlayerNow = (window.location.hash || '').indexOf('#/player/') === 0;
var statsDisabled = localStorage.getItem('stremio_stream_stats') === 'false';
var infoTriggered = (code === 457) || (code === 403 && inPlayerNow && statsDisabled);
if (infoTriggered && statsDisabled) {
var video = document.querySelector('video');
if (!video) return;
var info = document.getElementById('stream-info');
if (info) { info.remove(); return; }
info = document.createElement('div');
info.id = 'stream-info';
info.style.cssText = 'position:fixed;top:60px;left:14px;background:rgba(0,0,0,0.85);color:white;padding:16px 20px;border-radius:10px;font-size:13px;z-index:99999;font-family:monospace;min-width:260px;backdrop-filter:blur(4px);';
var bufferedStr = 'N/A';
try { if (video.buffered.length) bufferedStr = Math.round(video.buffered.end(video.buffered.length - 1)) + 's'; } catch(e) {}
info.innerHTML = '<div style="font-weight:700;margin-bottom:8px;font-size:14px;">Stream Info</div>'
+ '<div>Resolution: ' + esc((video.videoWidth || '?') + 'x' + (video.videoHeight || '?')) + '</div>'
+ '<div>Duration: ' + Math.round(video.duration || 0) + 's</div>'
+ '<div>Buffered: ' + esc(bufferedStr) + '</div>'
+ '<div>Current: ' + Math.round(video.currentTime || 0) + 's</div>'
+ '<div>Paused: ' + video.paused + '</div>'
+ '<div>DV P7: ' + esc(window.__DV_PROFILE7_DETECTED__ || 'No') + '</div>';
if (window.__VIDAA_CAPS__) {
info.innerHTML += '<div style="margin-top:8px;border-top:1px solid rgba(255,255,255,0.15);padding-top:8px;">'
+ '<div style="font-weight:700;margin-bottom:4px;">VIDAA Device</div>'
+ '<div>Model: ' + esc(window.__VIDAA_CAPS__.model || '?') + '</div>'
+ '<div>Chipset: ' + esc(window.__VIDAA_CAPS__.chipset || '?') + '</div>'
+ '<div>HDR: ' + esc(JSON.stringify(window.__VIDAA_CAPS__.hdrInfo || {})) + '</div>'
+ '<div>Atmos: ' + esc(window.__VIDAA_CAPS__.dolbyAtmos || '?') + '</div>'
+ '</div>';
}
if (window.__VIDAA_STATE__ && Object.keys(window.__VIDAA_STATE__).length > 0) {
info.innerHTML += '<div style="margin-top:4px;">'
+ '<div>DV: ' + esc(window.__VIDAA_STATE__.dolbyVision || 'N/A') + '</div>'
+ '<div>HDR: ' + esc(window.__VIDAA_STATE__.hdr || 'N/A') + '</div>'
+ '<div>Codec: ' + esc(window.__VIDAA_STATE__.videoCodec || 'N/A') + '</div>'
+ '</div>';
}
document.body.appendChild(info);
setTimeout(function() { if (info) info.remove(); }, 10000);
}
});
})();
</script>
<script>
// ═══════════════════════════════════════════════════════════════════════
// Native player handoff — SINGLE consolidated, HONEST launcher.
// ═══════════════════════════════════════════════════════════════════════
// IMPORTANT (read before "fixing"): omi_platform.sendPlatformMessage is a real
// Opera/Vewd bridge, but its ONLY working message type on shipped VIDAA firmware
// is AllAppsUpdate (launcher refresh). The message types we send here
// (launchNativePlayer / openMediaPlayer / playVideo) are NOT acted on by any
// confirmed VIDAA firmware (issues #28, #29 — three users saw "nothing
// happens"). The send is fire-and-forget with NO acknowledgement.
//
// So we MUST NOT report success just because a message was dispatched. The only
// observable signal that a native app actually took the foreground is the
// browser document being backgrounded: visibilitychange->hidden, window blur,
// or pagehide. We listen for any of those within a short window. If none
// arrives we treat the handoff as FAILED. Per 2026 research there is NO
// guarantee VIDAA's Opera-based browser even fires these events on foreground
// loss (Opera TV historically allowed the Page Visibility API to be disabled),
// so we are deliberately CONSERVATIVE: failure is the default, success requires
// a positive signal.
//
// The launcher returns a Promise<boolean> reflecting the VERIFIED outcome.
// Callers MUST act on the resolved value (un-pause the browser <video>, show
// honest advice) — never assume success.
//
// This is the ONLY place __launchNativePlayer is defined. The previous three
// racing redefinitions (original / title-enhanced / watched-wrapper, each
// re-installed by setInterval + setTimeout) clobbered each other
// nondeterministically. They are consolidated here in deterministic order:
// build payload+title -> fire-and-forget send -> verify backgrounding ->
// (only if verified AND toggle on) optional watched-tracking.
(function() {
'use strict';
var HANDOFF_KEY = 'stremio_native_handoff'; // also the watched-tracking toggle key
var DEFAULT_VERIFY_MS = 2000; // window to observe app backgrounding
var DEFAULT_WATCHED_DELAY_MS = 30000; // delay before marking watched (verified only)
function hasNative() {
try { return typeof omi_platform !== 'undefined' && typeof omi_platform.sendPlatformMessage === 'function'; } catch(e) { return false; }
}
function guessNativeMimeType(url) {
var path = '';
try { path = String(url || '').split('?')[0].toLowerCase(); } catch(e) {}
if (path.indexOf('.mkv') !== -1) return 'video/x-matroska';
if (path.indexOf('.m3u8') !== -1) return 'application/vnd.apple.mpegurl';
if (path.indexOf('.mpd') !== -1) return 'application/dash+xml';
if (path.indexOf('.webm') !== -1) return 'video/webm';
if (path.indexOf('.mov') !== -1) return 'video/quicktime';
if (path.indexOf('.mp4') !== -1 || path.indexOf('.m4v') !== -1) return 'video/mp4';
return 'video/mp4';
}
window.__guessNativeMimeType = guessNativeMimeType;
// Scrape a human title for the native player payload. Best-effort only.
function getPlayerTitle() {
try {
var titleEls = document.querySelectorAll('[class*="title"], [class*="Title"]');
for (var i = 0; i < titleEls.length; i++) {
var txt = (titleEls[i].textContent || '').trim();
if (txt.length > 3 && txt.length < 200 && txt.indexOf('Settings') === -1 && txt.indexOf('Stremio') === -1) {
return txt;
}
}
var hash = window.location.hash || '';
var match = hash.match(/[?&]title=([^&]+)/);
if (match) return decodeURIComponent(match[1]);
if (window.__STREAM_INFO__ && window.__STREAM_INFO__.title) return window.__STREAM_INFO__.title;
} catch(e) {}
return 'Stremio';
}
// Cache the title from detail pages so we have it when the player opens.
setInterval(function() {
var hash = window.location.hash || '';
if (hash.indexOf('#/detail') === 0 || hash.indexOf('#/metadetails') === 0) {
try {
var h1s = document.querySelectorAll('h1, h2, [class*="title"], [class*="Title"], [class*="name"], [class*="Name"]');
for (var i = 0; i < h1s.length; i++) {
var txt = (h1s[i].textContent || '').trim();
if (txt.length > 2 && txt.length < 200) {
window.__STREAM_INFO__ = window.__STREAM_INFO__ || {};
window.__STREAM_INFO__.title = txt;
break;
}
}
} catch(e) {}
}
}, 2000);
// Returns a Promise<boolean> that resolves true ONLY if the document is
// observed to background within `ms`. Conservative: no signal => false.
function verifyBackgrounding(ms) {
return new Promise(function(resolve) {
var settled = false;
function done(ok) {
if (settled) return;
settled = true;
try { document.removeEventListener('visibilitychange', onVis); } catch(e) {}
try { window.removeEventListener('blur', onBlur); } catch(e) {}
try { window.removeEventListener('pagehide', onHide); } catch(e) {}
clearTimeout(timer);
resolve(ok);
}
function onVis() { if (document.visibilityState === 'hidden' || document.hidden === true) done(true); }
function onBlur() { done(true); }
function onHide() { done(true); }
// If we're already hidden, that's a positive signal.
if (document.visibilityState === 'hidden' || document.hidden === true) { resolve(true); return; }
document.addEventListener('visibilitychange', onVis);
window.addEventListener('blur', onBlur);
window.addEventListener('pagehide', onHide);
var timer = setTimeout(function() { done(false); }, ms);
});
}
// Mark-as-watched — VERIFIED handoffs only, behind the existing toggle.
// NOTE: we deliberately do NOT write any fake currentTime/progress. The old
// code set currentTime = duration*0.9 which corrupted the resume point on
// every (always-"true") handoff. That is removed entirely.
function markAsWatched(handoff) {
try {
if (!window.core || !handoff || !handoff.hash) return;
window.core.getState('player').then(function(playerState) {
if (!playerState) return;
var metaId = null, videoId = null;
try {
if (playerState.metaItem) metaId = playerState.metaItem.id;
if (playerState.video) videoId = playerState.video.id;
} catch(e) {}
if (metaId) {
try {
window.core.dispatch({
action: 'Ctx',
args: { action: 'MarkAsWatched', args: { id: metaId, videoId: videoId, isWatched: true } }
}, 'ctx');
console.log('[watched] Marked as watched (VERIFIED handoff):', metaId, videoId);
} catch(e) {
console.log('[watched] MarkAsWatched dispatch failed:', e.message);
}
}
}).catch(function(e) {
console.log('[watched] Failed to get player state:', e.message);
});
} catch(e) {}
}
function watchedTrackingEnabled() {
try { return localStorage.getItem(HANDOFF_KEY) === 'true'; } catch(e) { return false; }
}
// Shared recovery helper for ALL auto/recovery call sites. When a handoff
// fails (verified false), callers MUST un-pause the browser <video> so the
// user isn't left staring at a frozen, paused player with no feedback, and
// surface honest advice. Non-blocking, dismissible.
var lastFailToastAt = 0;
window.__recoverAfterFailedHandoff = function(video, opts) {
opts = opts || {};
// Best-effort resume of the browser player.
try {
video = video || document.querySelector('video');
if (video && video.paused) {
var p = video.play();
if (p && typeof p.catch === 'function') p.catch(function() {});
}
} catch(e) {}
if (opts.silent) return;
// Throttle toasts so repeated stalls don't spam.
var now = Date.now();
if (now - lastFailToastAt < 6000) return;
lastFailToastAt = now;
var existing = document.getElementById('__handoff-fail-toast');
if (existing) existing.remove();
var toast = document.createElement('div');
toast.id = '__handoff-fail-toast';
toast.className = 'dv-honest-toast';
toast.style.cssText = 'position:fixed;bottom:60px;left:50%;transform:translateX(-50%);background:rgba(20,20,20,0.95);color:#fff;padding:12px 18px;border-radius:10px;font-size:14px;z-index:99999;font-family:PlusJakartaSans,sans-serif;max-width:460px;text-align:center;line-height:1.4;display:flex;flex-direction:column;gap:8px;';
var msg = document.createElement('div');
msg.textContent = 'The TV’s built-in player didn’t open — resuming here. This stream may be too heavy for the TV browser; try a 1080p or MP4 version of this title.';
toast.appendChild(msg);
var btn = document.createElement('button');
btn.textContent = 'OK';
btn.style.cssText = 'background:rgba(255,255,255,0.14);color:#fff;border:none;border-radius:8px;padding:6px 16px;font-size:13px;font-family:inherit;font-weight:600;cursor:pointer;align-self:center;';
btn.setAttribute('tabindex', '0');
btn.onfocus = function() { this.style.outline = '2px solid #fff'; };
btn.onblur = function() { this.style.outline = 'none'; };
btn.onclick = function() { toast.remove(); };
toast.appendChild(btn);
document.body.appendChild(toast);
setTimeout(function() { if (toast.parentNode) toast.remove(); }, 9000);
};
// The ONE launcher. Returns Promise<boolean> = verified opened?
// opts: { verifyTimeoutMs, watchedDelayMs } (test/override hooks)
window.__launchNativePlayer = function(url, opts) {
opts = opts || {};
var verifyMs = opts.verifyTimeoutMs != null ? opts.verifyTimeoutMs
: (window.__NATIVE_VERIFY_TIMEOUT_MS__ != null ? window.__NATIVE_VERIFY_TIMEOUT_MS__ : DEFAULT_VERIFY_MS);
var watchedDelay = opts.watchedDelayMs != null ? opts.watchedDelayMs : DEFAULT_WATCHED_DELAY_MS;
if (!hasNative()) {
console.log('[native] omi_platform unavailable — native player not supported on this device');
return Promise.resolve(false);
}
if (!url) {
var video = document.querySelector('video');
url = video ? video.currentSrc || video.src : null;
}
if (!url) { console.log('[native] No stream URL found'); return Promise.resolve(false); }
var title = getPlayerTitle() || 'Stremio';
var mimeType = guessNativeMimeType(url);
console.log('[native] Attempting native handoff (title:', title + '):', String(url).substring(0, 100));
// Arm verification BEFORE sending so we don't miss a fast backgrounding.
var verifyPromise = verifyBackgrounding(verifyMs);
// Fire-and-forget — try every message type; swallow throws. Sending says
// NOTHING about whether the native player actually opened.
var messages = [
{type: 'launchNativePlayer', url: url, title: title, mimeType: mimeType},
{type: 'openMediaPlayer', url: url, title: title},
{type: 'playVideo', url: url, mimeType: mimeType, title: title}
];
for (var i = 0; i < messages.length; i++) {
try {
omi_platform.sendPlatformMessage(JSON.stringify(messages[i]));
console.log('[native] Sent (unacked):', messages[i].type);
} catch(e) {
console.log('[native] Send threw:', messages[i].type, e.message);
}
}
return verifyPromise.then(function(opened) {
if (!opened) {
console.warn('[native] No backgrounding signal within ' + verifyMs + 'ms — treating handoff as FAILED.');
return false;
}
console.log('[native] Backgrounding observed — handoff VERIFIED.');
// Only on a VERIFIED handoff, and only if the user enabled watched
// tracking, record + (after delay) mark as watched. No resume-point
// corruption ever.
if (watchedTrackingEnabled()) {
try {
var v = document.querySelector('video');
var handoff = {
hash: window.location.hash || '',
time: Date.now(),
duration: v ? v.duration : 0,
currentTime: v ? v.currentTime : 0
};
setTimeout(function() { markAsWatched(handoff); }, watchedDelay);
} catch(e) {}
}
return true;
});
};
// Yellow button (405) — launch native player with current stream.
// Always bind; check omi_platform at press time so later-injected APIs still work.
document.addEventListener('keydown', function(e) {
if (e.keyCode !== 405) return;
var hash = window.location.hash || '';
if (hash.indexOf('#/player/') !== 0) return;
function mkToast(text, bg) {
var toast = document.createElement('div');
toast.style.cssText = 'position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:' + (bg || 'rgba(0,0,0,0.9)') + ';color:white;padding:20px 40px;border-radius:12px;font-size:1.2rem;font-family:PlusJakartaSans,sans-serif;z-index:100000;pointer-events:none;text-align:center;max-width:500px;';
toast.textContent = text;
document.body.appendChild(toast);
setTimeout(function() { toast.remove(); }, 3500);
return toast;
}
if (!hasNative()) {
mkToast('Native player not available on this device', 'rgba(180,60,60,0.92)');
return;
}
// Honest flow: show a "trying" hint, then replace with the VERIFIED result.
var tryToast = mkToast('Trying the TV’s player…', 'rgba(0,0,0,0.9)');
var video = document.querySelector('video');