@kangsicj/nexussync 1.6.11 → 1.6.13

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.
@@ -8,7 +8,7 @@
8
8
  // @icon https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/assets/icon.svg
9
9
  // @updateURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.meta.js
10
10
  // @downloadURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.user.js
11
- // @version 1.6.11
11
+ // @version 1.6.13
12
12
  // @description Watch any web video together in perfect sync: cinema mode, live AI subtitles & translation, chat bubbles with auto-translation, quick ink, cover, go-together to the next episode.
13
13
  // @description:ko 어떤 웹 영상이든 완벽한 싱크로 함께 보기: 시네마 모드, 실시간 AI 자막·번역, 자동 번역 말풍선 채팅, 잠깐 그리기, 가리기, 다음 화도 함께.
14
14
  // @match *://*/*
@@ -8,7 +8,7 @@
8
8
  // @icon https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/assets/icon.svg
9
9
  // @updateURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.meta.js
10
10
  // @downloadURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.user.js
11
- // @version 1.6.11
11
+ // @version 1.6.13
12
12
  // @description Watch any web video together in perfect sync: cinema mode, live AI subtitles & translation, chat bubbles with auto-translation, quick ink, cover, go-together to the next episode.
13
13
  // @description:ko 어떤 웹 영상이든 완벽한 싱크로 함께 보기: 시네마 모드, 실시간 AI 자막·번역, 자동 번역 말풍선 채팅, 잠깐 그리기, 가리기, 다음 화도 함께.
14
14
  // @match *://*/*
@@ -46,12 +46,12 @@
46
46
 
47
47
  // The version of the code that is actually running (the manager's metadata can lag
48
48
  // behind when an old copy is still installed).
49
- const NXU_VERSION = '1.6.11';
49
+ const NXU_VERSION = '1.6.13';
50
50
  // Rank used by the one-instance guard below and to tell newer builds apart in a room.
51
51
  // It is independent of the public version (1.0.0 is the first public release, after
52
52
  // private builds that reached ranks up to 10.2.0), so every older copy still installed
53
53
  // steps aside instead of this release.
54
- const NXU_RANK = '11.6.11';
54
+ const NXU_RANK = '11.6.13';
55
55
  const NXU_SESSION = Math.random().toString(36).slice(2, 10); // this page load // raise with every release
56
56
  // App icon (same artwork as assets/icon.svg / @icon), inlined so it shows offline too.
57
57
  const NXU_ICON = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTYgMjU2IiByb2xlPSJpbWciIGFyaWEtbGFiZWw9Ik5leHVzU3luYyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJueGJnIiB4MT0iMCIgeTE9IjAiIHgyPSIxIiB5Mj0iMSI+PHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjNWIyZWZmIi8+PHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjZmY0ZmEzIi8+PC9saW5lYXJHcmFkaWVudD48cmFkaWFsR3JhZGllbnQgaWQ9Im54Z2xvdyIgY3g9IjAuODIiIGN5PSIwLjE0IiByPSIwLjciPjxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iIzdjZjlmZiIgc3RvcC1vcGFjaXR5PSIwLjU1Ii8+PHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjN2NmOWZmIiBzdG9wLW9wYWNpdHk9IjAiLz48L3JhZGlhbEdyYWRpZW50PjxsaW5lYXJHcmFkaWVudCBpZD0ibnhwbGF5IiB4MT0iMCIgeTE9IjAiIHgyPSIxIiB5Mj0iMSI+PHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjZmZmZmZmIi8+PHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjZmZlM2YxIi8+PC9saW5lYXJHcmFkaWVudD48Y2xpcFBhdGggaWQ9Im54ciI+PHJlY3Qgd2lkdGg9IjI1NiIgaGVpZ2h0PSIyNTYiIHJ4PSI1OCIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNueHIpIj48cmVjdCB3aWR0aD0iMjU2IiBoZWlnaHQ9IjI1NiIgZmlsbD0idXJsKCNueGJnKSIvPjxyZWN0IHdpZHRoPSIyNTYiIGhlaWdodD0iMjU2IiBmaWxsPSJ1cmwoI254Z2xvdykiLz48ZyBmaWxsPSJub25lIiBzdHJva2U9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMTUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCI+PHBhdGggZD0iTTYwIDExNiBBNzAgNzAgMCAwIDEgMTc4IDcyIi8+PHBhdGggZD0iTTE5NiAxNDAgQTcwIDcwIDAgMCAxIDc4IDE4NCIvPjwvZz48cGF0aCBkPSJNMTg2IDUwIEwyMDAgOTIgTDE1NyA4NiBaIiBmaWxsPSIjZmZmZmZmIi8+PHBhdGggZD0iTTcwIDIwNiBMNTYgMTY0IEw5OSAxNzAgWiIgZmlsbD0iI2ZmZmZmZiIvPjxwYXRoIGQ9Ik0xMTAgOTIgUTEwNCA4OCAxMDQgOTYgTDEwNCAxNjAgUTEwNCAxNjggMTEwIDE2NCBMMTYyIDEzMiBRMTY4IDEyOCAxNjIgMTI0IFoiIGZpbGw9InVybCgjbnhwbGF5KSIvPjwvZz48L3N2Zz4=';
@@ -764,7 +764,7 @@ async function handle(m) {
764
764
  tuneSrcSame: '🟢 Same video on every device — kept in step automatically, frame by frame.', tuneSrcDiff: '🟠 Different versions (length differs by {s}) — the timing is found automatically after a little playing, or set it here.', tuneSrcUnknown: 'Waiting for the others’ video…', tuneSrcShifted: '🟠 Same length, but the scenes differ — the timing is lined up automatically while you play, or set it here.', tuneDiffPicture: 'Same time, but the pictures differ', tuneShiftFound: 'Same length but different scenes: timing set to {s} automatically (tap to undo).',
765
765
  tuneSameReset: '⏱ Same video as the others: timing correction removed.', tuneAutoApplied: 'Different version: timing set to {s} automatically (tap to undo).', tuneSuggest: 'Your videos differ by {s}. Tap to line them up.',
766
766
  subMenu: 'Subtitles', xsubOff: 'Off', subTrack: 'From the video', subSearch: '🔎 Find subtitles (OpenSubtitles)', subFile: '📂 Open a subtitle file…', subAi: '🧠 AI live subtitles', subDelay: 'Timing', subLater: 'later', subEarlier: 'earlier', xsubSize: 'Size',
767
- subLoaded: '💬 Subtitles: {name}', subMulti: 'Several subtitles at once — tap one to take it away.', subNone: 'No subtitles found in this video.', subSuggest: '💬 No subtitles? Find them', subLoadFail: 'Could not load these subtitles.',
767
+ subLoaded: '💬 Subtitles: {name}', subMulti: 'Several subtitles at once — each dot is the colour of its lines on screen; tap one to take it away.', subNone: 'No subtitles found in this video.', subMoreLangs: '🌐 {n} more languages', subSiteOnly: 'This site loads that subtitle only from its own menu — switch to the site controls (top right) and pick it there.', subSuggest: '💬 No subtitles? Find them', subLoadFail: 'Could not load these subtitles.',
768
768
  osTitle: 'Find subtitles', osTmdbLooking: 'Looking up the English title on TMDB…', osTmdbNone: 'No English title found on TMDB — type it yourself if you know it.', osQuery: 'Title (English titles work best)', osSeason: 'Season', osEpisode: 'Episode', osLang: 'Language', osSearch: 'Search', osSearching: 'Searching…', osNone: 'Nothing found. Try the English title, or remove the year.', osError: 'OpenSubtitles did not answer. Try again in a moment.', osDownloads: '{n} downloads', osLoading: 'Loading…', osHint: 'Subtitles come from OpenSubtitles.org and are shown in NexusSync’s own style; use “Timing” in the subtitle menu if they are early or late.',
769
769
  viewMenu: 'Picture', viewAudio: 'Soundtrack', viewBright: 'Brightness', viewBoost: 'Volume boost', viewReset: 'Reset', boostBlocked: 'This video’s sound cannot be boosted here (it comes from another site).',
770
770
  settings: 'Settings', setProfile: 'Profile', setAvatar: 'Avatar', setStatus: 'Status message', setStatusPh: 'e.g. Popcorn ready 🍿', setReactions: 'My reactions',
@@ -889,7 +889,7 @@ async function handle(m) {
889
889
  tuneSrcSame: '🟢 모두 같은 영상이에요 — 프레임 단위로 자동으로 맞추고 있어요.', tuneSrcDiff: '🟠 서로 다른 버전이에요 (길이 차이 {s}) — 잠시 재생하면 자동으로 맞추고, 여기서 직접 맞출 수도 있어요.', tuneSrcUnknown: '다른 사람의 영상 정보를 기다리는 중…', tuneSrcShifted: '🟠 길이는 같지만 장면이 달라요 — 재생하는 동안 자동으로 맞추고, 여기서 직접 맞출 수도 있어요.', tuneDiffPicture: '시간은 같지만 화면이 달라요', tuneShiftFound: '길이는 같지만 장면이 달라서 타이밍을 {s} 자동 보정했어요 (누르면 되돌리기).',
890
890
  tuneSameReset: '⏱ 상대와 같은 영상이라 타이밍 보정을 해제했어요.', tuneAutoApplied: '다른 버전이라 타이밍을 {s} 자동 보정했어요 (누르면 되돌리기).', tuneSuggest: '서로 영상 길이가 {s} 달라요. 눌러서 맞춰 보세요.',
891
891
  subMenu: '자막', xsubOff: '끄기', subTrack: '영상에 포함된 자막', subSearch: '🔎 자막 찾기 (OpenSubtitles)', subFile: '📂 자막 파일 열기…', subAi: '🧠 AI 실시간 자막', subDelay: '싱크', subLater: '늦게', subEarlier: '빠르게', xsubSize: '크기',
892
- subLoaded: '💬 자막: {name}', subMulti: '자막 여러 개를 함께 보는 중 — 누르면 그 자막만 꺼져요.', subNone: '이 영상에는 포함된 자막이 없어요.', subSuggest: '💬 자막이 없나요? 찾아보기', subLoadFail: '자막을 불러오지 못했어요.',
892
+ subLoaded: '💬 자막: {name}', subMulti: '자막 여러 개를 함께 보는 중 — 점 색이 화면 자막 색이에요. 누르면 그 자막만 꺼져요.', subNone: '이 영상에는 포함된 자막이 없어요.', subMoreLangs: '🌐 다른 언어 {n}개 더 보기', subSiteOnly: '이 사이트는 자기 메뉴에서만 이 자막을 불러와요. 오른쪽 위에서 사이트 컨트롤로 바꾼 뒤 거기서 골라 주세요.', subSuggest: '💬 자막이 없나요? 찾아보기', subLoadFail: '자막을 불러오지 못했어요.',
893
893
  osTitle: '자막 찾기', osTmdbLooking: 'TMDB에서 영어 제목을 찾는 중…', osTmdbNone: 'TMDB에서 영어 제목을 찾지 못했어요 — 알고 있다면 직접 입력하세요.', osQuery: '제목 (영어 제목이 가장 잘 찾아져요)', osSeason: '시즌', osEpisode: '회차', osLang: '언어', osSearch: '검색', osSearching: '찾는 중…', osNone: '찾지 못했어요. 영어 제목으로 바꾸거나 연도를 빼 보세요.', osError: 'OpenSubtitles가 응답하지 않아요. 잠시 후 다시 시도하세요.', osDownloads: '다운로드 {n}회', osLoading: '불러오는 중…', osHint: '자막은 OpenSubtitles.org에서 가져와 NexusSync 스타일로 보여 줘요. 빠르거나 늦으면 자막 메뉴의 “싱크”로 맞추세요.',
894
894
  viewMenu: '화면', viewAudio: '오디오 트랙', viewBright: '밝기', viewBoost: '볼륨 부스트', viewReset: '초기화', boostBlocked: '이 영상은 다른 사이트에서 오는 소리라 여기서 키울 수 없어요.',
895
895
  settings: '설정', setProfile: '프로필', setAvatar: '아바타', setStatus: '상태 메시지', setStatusPh: '예: 팝콘 준비 완료 🍿', setReactions: '내 리액션',
@@ -1419,12 +1419,13 @@ async function handle(m) {
1419
1419
  nexusControls() { return IS_TOP ? cinemaControlsMode() !== 'site' : this._frameNexus === true; },
1420
1420
  _startAmbient(video, root) {
1421
1421
  this._stopAmbient();
1422
+ this._ambientPaused = false;
1422
1423
  if (!video || !root || !this.ambientEnabled()) return;
1423
1424
  try { if (video.mediaKeys || video.webkitKeys) return; } catch (_) { } // DRM video always draws black
1424
1425
  const doc = video.ownerDocument;
1425
1426
  if (root.getRootNode() !== doc) return; // player inside a site's shadow DOM: our styles can't reach it
1426
1427
  const seeThrough = this._seeThrough(video, root);
1427
- if (seeThrough) { logDebug('Ambient light off for this player: ' + seeThrough, 'info'); return; }
1428
+ if (seeThrough) { logDebug('Ambient light off for this player: ' + seeThrough, 'info'); this._ambientPaused = true; return; }
1428
1429
  const view = doc.defaultView || window;
1429
1430
  const lite = IS_TOUCH;
1430
1431
  const layer = doc.createElement('div');
@@ -1446,6 +1447,8 @@ async function handle(m) {
1446
1447
  else (doc.body || doc.documentElement).appendChild(layer);
1447
1448
  root.classList.add('nxu-ambient-on');
1448
1449
  this._matchLayerZ(layer, root);
1450
+ const cleared = new Map();
1451
+ this._clearBackdrops(video, root, cleared);
1449
1452
  // Reading a video frame is the costly part (it was almost all of cinema's CPU time at
1450
1453
  // 16 a second). Six a second with a stronger blend looks the same: the glow eases
1451
1454
  // between scenes anyway, and a cut still shows within a fraction of a second.
@@ -1508,7 +1511,26 @@ async function handle(m) {
1508
1511
  stopped = true;
1509
1512
  if (rvfc && frameHandle) { try { video.cancelVideoFrameCallback(frameHandle); } catch (_) { } }
1510
1513
  };
1511
- this._ambient = { layer, root, timer, video, view, onSeek, onMeta, stage, stop, redraw: () => draw(true) };
1514
+ this._ambient = { layer, root, timer, video, view, onSeek, onMeta, stage, stop, cleared, redraw: () => draw(true) };
1515
+ },
1516
+ // Any box between the picture and the cinema root with its own background (a player's
1517
+ // black "bg-black" frame) would cover the glow. Those get a see-through background,
1518
+ // set inline so a site that rewrites its class names (React and the like) keeps it;
1519
+ // re-checked while cinema is on, put back as it was when the glow stops.
1520
+ _clearBackdrops(video, root, cleared) {
1521
+ try {
1522
+ const view = video.ownerDocument.defaultView || window;
1523
+ for (let el = video.parentElement; el && el.nodeType === 1; el = el.parentElement) {
1524
+ const cs = view.getComputedStyle(el);
1525
+ const color = cs.backgroundColor;
1526
+ const opaque = (color && color !== 'transparent' && !/rgba\([^)]*,\s*0\)$/.test(color)) || (cs.backgroundImage && cs.backgroundImage !== 'none');
1527
+ if (opaque && el.style.getPropertyPriority('background') !== 'important') {
1528
+ if (!cleared.has(el)) cleared.set(el, el.style.getPropertyValue('background'));
1529
+ el.style.setProperty('background', 'transparent', 'important');
1530
+ }
1531
+ if (el === root) break;
1532
+ }
1533
+ } catch (_) { }
1512
1534
  },
1513
1535
  // The glow sits behind the picture, which only works when the picture covers it. A
1514
1536
  // player that shows the video see-through (faded, blended, blurred, or hidden while
@@ -1562,6 +1584,7 @@ async function handle(m) {
1562
1584
  a.video.removeEventListener('resize', a.onMeta);
1563
1585
  a.view.removeEventListener('resize', a.stage);
1564
1586
  a.layer.remove();
1587
+ a.cleared?.forEach((was, el) => { if (was) el.style.setProperty('background', was); else el.style.removeProperty('background'); });
1565
1588
  a.root.classList.remove('nxu-ambient-on', 'nxu-ambient-stage');
1566
1589
  a.root.style.removeProperty('--nxu-stage-x');
1567
1590
  a.root.style.removeProperty('--nxu-stage-y');
@@ -1763,8 +1786,13 @@ async function handle(m) {
1763
1786
  } else if (a) {
1764
1787
  // The site may fade or blur its video later (e.g. once it starts playing).
1765
1788
  const why = this._seeThrough(a.video, a.root);
1766
- if (why) { logDebug('Ambient light off for this player: ' + why, 'info'); this._stopAmbient(); }
1767
- else this._matchLayerZ(a.layer, a.root);
1789
+ if (why) { logDebug('Ambient light off for this player: ' + why, 'info'); this._stopAmbient(); this._ambientPaused = true; }
1790
+ else { this._matchLayerZ(a.layer, a.root); this._clearBackdrops(a.video, a.root, a.cleared); }
1791
+ } else if (this._ambientPaused && this.ambientEnabled() && this.applied.video && this.applied.chain[0]?.root) {
1792
+ // Turned off only while the site faded or covered its picture (loading,
1793
+ // seeking): back on once the picture shows again, while the setting is on.
1794
+ const v = this.applied.video, root = this.applied.chain[0].root;
1795
+ if (!this._seeThrough(v, root)) { this._ambientPaused = false; this._startAmbient(v, root); if (this._ambient) logDebug('Ambient light back on.', 'info'); }
1768
1796
  }
1769
1797
  const root = this.applied.chain[0]?.root || this.applied.siteRoot;
1770
1798
  if (root && (this.nexusControls() !== root.classList.contains('nxu-site-ui-off') || (this.nexusControls() && this.applied.video?.hasAttribute('controls')))) {
@@ -7453,6 +7481,7 @@ async function handle(m) {
7453
7481
  wrapper?.classList.toggle('touch-peek', IS_TOUCH && STATE.isCinema);
7454
7482
  getContainer()?.classList.remove('chrome-idle');
7455
7483
  if (CUE_MIRROR.box) CUE_MIRROR.render();
7484
+ if (IS_TOP && STATE.isCinema) { try { CINEMA_UI.placeSiteBar(); } catch (_) { } }
7456
7485
  getOpenPanels().forEach(panel => {
7457
7486
  panel.style.opacity = '1';
7458
7487
  panel.style.pointerEvents = 'auto';
@@ -8485,6 +8514,8 @@ async function handle(m) {
8485
8514
  .nx-xsub { position:absolute; left:50%; bottom:9%; transform:translateX(-50%); width:min(92%, 1100px); display:flex; flex-direction:column; align-items:center; gap:4px; z-index:66; pointer-events:none; opacity:0; transition:opacity 0.18s ease, bottom 0.3s ease; --xs:1; }
8486
8515
  .nx-xsub.on { opacity:1; }
8487
8516
  .nx-xsub-line.l1 { color:#ffe98a; }
8517
+ .cc-menu button .cc-swatch-label { display:inline-flex; align-items:center; margin-right:auto; }
8518
+ .cc-menu button .cc-swatch { display:inline-block; width:12px; height:12px; border-radius:50%; margin-right:6px; vertical-align:-1px; box-shadow:0 0 0 1px rgba(255,255,255,0.4); }
8488
8519
  .nx-xsub-line.l2 { color:#9be7ff; font-size:calc(clamp(13px, 2.2cqw, 28px) * var(--xs)); }
8489
8520
  .nexus-container.cinema-nexus:not(.chrome-idle) .nx-xsub { bottom:calc(104px + env(safe-area-inset-bottom, 0px)); }
8490
8521
  .nx-xsub-line { display:inline-block; max-width:100%; padding:0.12em 0.55em; border-radius:0.35em; background:rgba(8,10,14,0.62); color:#fff; text-align:center; white-space:pre-line; overflow-wrap:anywhere;
@@ -10470,6 +10501,21 @@ async function handle(m) {
10470
10501
  },
10471
10502
  active() { return this.layers.length > 0; },
10472
10503
  hasTrack(tr) { return this.layers.some(l => l.track === tr); },
10504
+ // 1 = your subtitle language, 2 = English, 3 = anything else (labels or codes like "kor").
10505
+ langRank(tr) {
10506
+ const want = baseLang(STORE.get('nxu_subtitle_language', '') || navigator.language || 'en') || 'en';
10507
+ const is = (code) => {
10508
+ const lang = String(tr.language || '').toLowerCase(), label = String(tr.label || '').toLowerCase();
10509
+ if (lang === code || lang.startsWith(code + '-') || lang.startsWith(code + '_')) return true;
10510
+ const three = { ko: ['kor'], en: ['eng'], ja: ['jpn', 'jap'], zh: ['chi', 'zho'], es: ['spa'], fr: ['fre', 'fra'], de: ['ger', 'deu'], pt: ['por'], ru: ['rus'], it: ['ita'], vi: ['vie'], th: ['tha'], id: ['ind'] }[code] || [];
10511
+ if (three.includes(lang)) return true;
10512
+ try {
10513
+ const names = [new Intl.DisplayNames(['en'], { type: 'language' }).of(code), new Intl.DisplayNames([code], { type: 'language' }).of(code)].map(s => String(s).toLowerCase());
10514
+ return names.some(n => n && label.startsWith(n));
10515
+ } catch (_) { return false; }
10516
+ };
10517
+ return is(want) ? 1 : want !== 'en' && is('en') ? 2 : 3;
10518
+ },
10473
10519
  _ensureBox() {
10474
10520
  const c = getContainer();
10475
10521
  if (!c) return null;
@@ -10494,9 +10540,21 @@ async function handle(m) {
10494
10540
  this.layers = this.layers.filter(x => x !== l);
10495
10541
  if (!this.layers.length) this.off(); else this.tick(true);
10496
10542
  },
10543
+ // Each subtitle keeps its colour while it is on (white, yellow, blue), so taking one
10544
+ // away does not repaint the others.
10545
+ COLORS: ['#ffffff', '#ffe98a', '#9be7ff'],
10546
+ colorOf(l) { return this.COLORS[l?.color || 0]; },
10547
+ // "Korean 2" when the video has several tracks of the same name (as in the menu).
10548
+ trackName(tr) {
10549
+ const all = this.tracks();
10550
+ const base = tr.label || tr.language || t('subTrack') + ' ' + (all.indexOf(tr) + 1);
10551
+ const same = all.filter(x => (x.label || x.language || '') === (tr.label || tr.language || ''));
10552
+ return same.length > 1 && (tr.label || tr.language) ? `${base} ${same.indexOf(tr) + 1}` : base;
10553
+ },
10497
10554
  _add(layer) {
10498
10555
  while (this.layers.length >= this.MAX) { this._drop(this.layers[0]); this.layers.shift(); }
10499
10556
  layer.id = Math.random().toString(36).slice(2, 8);
10557
+ layer.color = [0, 1, 2].find(c => !this.layers.some(l => l.color === c)) ?? 0;
10500
10558
  this.layers.push(layer);
10501
10559
  try { CUE_MIRROR.render(); } catch (_) { }
10502
10560
  this._loop();
@@ -10509,7 +10567,45 @@ async function handle(m) {
10509
10567
  this._onCue = this._onCue || (() => this.tick());
10510
10568
  tr.mode = 'hidden'; // cues still arrive, the browser does not draw them itself
10511
10569
  tr.addEventListener('cuechange', this._onCue);
10512
- this._add({ kind: 'track', track: tr, label: tr.label || tr.language || t('subTrack') });
10570
+ this._add({ kind: 'track', track: tr, label: this.trackName(tr) });
10571
+ this._askSite(tr);
10572
+ },
10573
+ // Some players list every language as an empty track and fetch the cues only when the
10574
+ // language is picked in their own menu (meowtv). Picked here, such a track stays empty:
10575
+ // pick it in the site's menu too, the same entry (the n-th one of that name), then close it.
10576
+ _askSite(tr) {
10577
+ const v = STATE.video;
10578
+ if (!v || tr._nxuAsked) return;
10579
+ setTimeout(async () => {
10580
+ if (!this.hasTrack(tr) || tr.cues?.length) return;
10581
+ // A <track src> loads its own file: nothing to ask the site for.
10582
+ if ([...v.querySelectorAll('track')].some(el => el.track === tr && el.src)) return;
10583
+ tr._nxuAsked = true;
10584
+ const label = (tr.label || '').trim();
10585
+ const same = this.tracks().filter(x => (x.label || '').trim() === label);
10586
+ const nth = Math.max(0, same.indexOf(tr));
10587
+ const wait = (ms) => new Promise(r => setTimeout(r, ms));
10588
+ const isSubBtn = (b) => /subtit|caption|자막|\bcc\b/i.test([b.getAttribute('aria-label'), b.title, b.getAttribute('data-tooltip'), b.textContent.length < 20 ? b.textContent : ''].join(' '));
10589
+ let scope = v.parentElement;
10590
+ for (let i = 0; scope && i < 8 && ![...scope.querySelectorAll('button,[role="button"]')].some(isSubBtn); i++) scope = scope.parentElement;
10591
+ const toggle = scope && [...scope.querySelectorAll('button,[role="button"]')].find(isSubBtn);
10592
+ if (label && toggle) {
10593
+ try {
10594
+ toggle.click();
10595
+ await wait(400);
10596
+ const pick = [...scope.querySelectorAll('button,[role="menuitem"],[role="menuitemradio"],[role="option"],li')]
10597
+ .filter(el => !el.contains(toggle) && (el.innerText || el.textContent || '').trim() === label);
10598
+ const target = pick[Math.min(nth, pick.length - 1)];
10599
+ if (target) target.click();
10600
+ await wait(300);
10601
+ if (target?.isConnected && target.getClientRects().length) toggle.click(); // close the site's menu
10602
+ } catch (_) { }
10603
+ }
10604
+ await wait(2500);
10605
+ if (!this.hasTrack(tr)) return;
10606
+ if (tr.cues?.length) { this.tick(true); logDebug(`Subtitles: "${label}" loaded through the site's own menu.`, 'info'); }
10607
+ else showToast(t('subSiteOnly'));
10608
+ }, 1500);
10513
10609
  },
10514
10610
  useCues(cues, label) { this._add({ kind: 'cues', cues: cues.sort((a, b) => a.s - b.s), label }); },
10515
10611
  _loop() { clearInterval(this._timer); this._timer = setInterval(() => this.tick(), 150); this.tick(true); },
@@ -10541,8 +10637,8 @@ async function handle(m) {
10541
10637
  const tm = this._now();
10542
10638
  if (tm == null) return;
10543
10639
  const at = tm - this.delay;
10544
- const groups = this.layers.map((l, i) => ({ i, text: this._textOf(l, at) }));
10545
- const sig = groups.map(g => g.text).join('\u0001');
10640
+ const groups = this.layers.map((l, i) => ({ i, c: l.color || 0, text: this._textOf(l, at) }));
10641
+ const sig = groups.map(g => g.text).join('\u0001') + this.layers.map(l => l.id).join();
10546
10642
  if (!force && sig === this._last && this._box?.isConnected) return;
10547
10643
  this._last = sig;
10548
10644
  const any = groups.some(g => g.text);
@@ -10550,7 +10646,7 @@ async function handle(m) {
10550
10646
  const box = any ? this._ensureBox() : this._box;
10551
10647
  if (!box) return;
10552
10648
  const kids = [];
10553
- groups.forEach(g => { if (g.text) g.text.split('\n').filter(Boolean).slice(0, 3).forEach(line => kids.push(createEl('span', 'nx-xsub-line l' + g.i, line))); });
10649
+ groups.forEach(g => { if (g.text) g.text.split('\n').filter(Boolean).slice(0, 3).forEach(line => kids.push(createEl('span', 'nx-xsub-line l' + g.c, line))); });
10554
10650
  box.replaceChildren(...kids);
10555
10651
  box.classList.toggle('on', any);
10556
10652
  },
@@ -10638,16 +10734,21 @@ async function handle(m) {
10638
10734
  if (this._root === root) return;
10639
10735
  this.stop();
10640
10736
  this._root = root;
10641
- this._obs = new MutationObserver(() => { if (!this._timer) this._timer = setTimeout(() => { this._timer = 0; this.scan(); }, 80); });
10737
+ // Scanned again a little later too: the list of the player's text layers is refreshed
10738
+ // a moment after the player redraws.
10739
+ this._obs = new MutationObserver(() => {
10740
+ if (!this._timer) this._timer = setTimeout(() => { this._timer = 0; this.scan(); }, 80);
10741
+ clearTimeout(this._late); this._late = setTimeout(() => this.scan(), 350);
10742
+ });
10642
10743
  this._obs.observe(root, { childList: true, subtree: true, characterData: true });
10643
10744
  this.scan();
10644
10745
  },
10645
10746
  stop() {
10646
10747
  this._obs?.disconnect(); this._obs = null; this._root = null;
10647
- clearTimeout(this._timer); this._timer = 0;
10748
+ clearTimeout(this._timer); this._timer = 0; clearTimeout(this._late);
10648
10749
  document.querySelectorAll('.nxu-dsub-src').forEach(n => n.classList.remove('nxu-dsub-src'));
10649
10750
  if (this._src && !SUBS.active()) SUBS._render('');
10650
- this._src = null; this._cands.clear();
10751
+ this._src = null; this._srcSig = null; this._cands.clear();
10651
10752
  },
10652
10753
  _text(el) { return String(el.innerText || el.textContent || '').replace(/[ \t]+/g, ' ').replace(/\n{2,}/g, '\n').trim().slice(0, 300); },
10653
10754
  scan() {
@@ -10658,16 +10759,27 @@ async function handle(m) {
10658
10759
  const cands = new Set();
10659
10760
  try { root.querySelectorAll(this.SEL).forEach(el => cands.add(el)); } catch (_) { }
10660
10761
  (CINEMA._textLayers || []).forEach(el => cands.add(el));
10762
+ // Many players (React and the like) draw each line as a new element: candidates are
10763
+ // followed by their place and look (tag, classes, parent), not by the element itself.
10764
+ const sigOf = (el) => `${el.tagName}|${el.className}|${el.parentElement?.className || ''}|${el.parentElement?.tagName || ''}`;
10765
+ if (this._srcSig) {
10766
+ const tag = this._srcSig.split('|')[0];
10767
+ const again = [...cands, ...root.getElementsByTagName(tag)].find(el => el.isConnected && !el.contains(v) && sigOf(el) === this._srcSig);
10768
+ if (again) { this._src = again; again.classList.add('nxu-dsub-src'); this._show(); return; }
10769
+ if (this._src && !this._src.isConnected) { this._src = null; if (!SUBS.active()) SUBS._render(''); }
10770
+ return;
10771
+ }
10661
10772
  const now = Date.now();
10662
10773
  for (const el of cands) {
10663
10774
  if (!el.isConnected || el.contains(v) || el.closest('.nxu-cue-mirror') || el.querySelector('button, input, svg, [role="slider"]')) continue;
10664
10775
  const txt = this._text(el);
10665
- const c = this._cands.get(el) || { last: null, changes: [], };
10776
+ const key = sigOf(el);
10777
+ const c = this._cands.get(key) || { last: null, changes: [], };
10666
10778
  if (txt !== c.last) { if (c.last !== null) c.changes.push(now); c.last = txt; }
10667
10779
  c.changes = c.changes.filter(ts => now - ts < 30000);
10668
- this._cands.set(el, c);
10780
+ this._cands.set(key, c);
10669
10781
  // Two changes of its text within half a minute: subtitles, not a title.
10670
- if (c.changes.length >= 2) { this._src = el; el.classList.add('nxu-dsub-src'); logDebug('Site subtitles shown in the NexusSync layer.', 'info'); this._show(); return; }
10782
+ if (c.changes.length >= 2) { this._src = el; this._srcSig = key; el.classList.add('nxu-dsub-src'); logDebug('Site subtitles shown in the NexusSync layer.', 'info'); this._show(); return; }
10671
10783
  }
10672
10784
  },
10673
10785
  _show() {
@@ -12563,7 +12675,7 @@ async function handle(m) {
12563
12675
  root.append(gesture, scrim, rippleL, rippleR, spinner, center, flash, scrub, top, bottom, menu, help);
12564
12676
  container.appendChild(root);
12565
12677
  this.root = root;
12566
- this.els = { gesture, scrim, rippleL, rippleR, flash, spinner, spinnerLabel, scrub, title, room, helpBtn, rotateBtn, modeBtn, exitBtn, center, cBack, cPlay, cFwd, bottom, seek, track, bufferBar, progress, pins, thumb, range, hover, playBtn, backBtn, fwdBtn, vol, muteBtn, volume, time, live, rateBtn, subBtn, viewBtn, fitBtn, ambientBtn, pipBtn, fsBtn, menu, help };
12678
+ this.els = { top, gesture, scrim, rippleL, rippleR, flash, spinner, spinnerLabel, scrub, title, room, helpBtn, rotateBtn, modeBtn, exitBtn, center, cBack, cPlay, cFwd, bottom, seek, track, bufferBar, progress, pins, thumb, range, hover, playBtn, backBtn, fwdBtn, vol, muteBtn, volume, time, live, rateBtn, subBtn, viewBtn, fitBtn, ambientBtn, pipBtn, fsBtn, menu, help };
12567
12679
 
12568
12680
  const stop = (e) => e.stopPropagation();
12569
12681
  [top, bottom, menu, help, center].forEach(el => el.addEventListener('pointerdown', stop));
@@ -12904,15 +13016,30 @@ async function handle(m) {
12904
13016
  this.els.help.classList.remove('open');
12905
13017
  menu.classList.toggle('open', open);
12906
13018
  menu.dataset.kind = 'sub';
12907
- if (!open) return;
13019
+ if (!open) { this._subAll = false; return; }
12908
13020
  const item = (label, sel, fn) => { const b = createEl('button', sel ? 'sel' : '', label, { type: 'button', role: 'menuitemradio' }); b.onclick = (ev) => { ev.stopPropagation(); fn(); }; return b; };
12909
13021
  const tracks = SUBS.tracks();
12910
13022
  const nothing = !SUBS.active() && !TRANSLATOR.active && !DOM_SUBS._src;
12911
13023
  const kids = [createEl('div', 'cc-menu-title', t('subMenu')),
12912
13024
  item(t('xsubOff'), nothing, () => { SUBS.off(); if (TRANSLATOR.active) TRANSLATOR.stop(t('subOff')); this.toggleSubMenu(false); })];
12913
13025
  // Several can be on at once (up to three): tap to add, tap again to take away.
12914
- tracks.forEach((tr, i) => kids.push(item('🎞 ' + (tr.label || tr.language || t('subTrack') + ' ' + (i + 1)), SUBS.hasTrack(tr), () => { SUBS.useTrack(tr); this.toggleSubMenu(true); })));
12915
- SUBS.layers.filter(l => l.kind === 'cues').forEach(l => kids.push(item('💬 ' + l.label, true, () => { SUBS.remove(l.id); this.toggleSubMenu(true); })));
13026
+ const name = (tr, i) => tr.label || tr.language || t('subTrack') + ' ' + (i + 1);
13027
+ const seen = {}, total = {};
13028
+ tracks.forEach((tr, i) => { const n = name(tr, i); total[n] = (total[n] || 0) + 1; });
13029
+ const rows = tracks.map((tr, i) => { const n = name(tr, i); seen[n] = (seen[n] || 0) + 1; return { tr, label: total[n] > 1 ? `${n} ${seen[n]}` : n, rank: SUBS.hasTrack(tr) ? 0 : SUBS.langRank(tr), i }; });
13030
+ rows.sort((a, b) => a.rank - b.rank || a.i - b.i);
13031
+ // A long list (players offering 100+ tracks) shows your languages first, the rest on request.
13032
+ const fold = rows.length > 12 && !this._subAll;
13033
+ const shown = fold ? rows.filter(r => r.rank < 3) : rows;
13034
+ const swatch = (layer, label, icon) => { const b = item('', true, () => { }); const s = createEl('span', 'cc-swatch'); s.style.background = SUBS.colorOf(layer); const wrap = createEl('span', 'cc-swatch-label'); wrap.append(s, document.createTextNode(icon + ' ' + label)); b.append(wrap); return b; };
13035
+ shown.forEach(r => {
13036
+ const layer = SUBS.layers.find(l => l.track === r.tr);
13037
+ const b = layer ? swatch(layer, r.label, '🎞') : item('🎞 ' + r.label, false, () => { });
13038
+ b.onclick = (ev) => { ev.stopPropagation(); SUBS.useTrack(r.tr); this.toggleSubMenu(true); };
13039
+ kids.push(b);
13040
+ });
13041
+ if (fold && shown.length < rows.length) kids.push(item(t('subMoreLangs', { n: rows.length - shown.length }), false, () => { this._subAll = true; this.toggleSubMenu(true); }));
13042
+ SUBS.layers.filter(l => l.kind === 'cues').forEach(l => { const b = swatch(l, l.label, '💬'); b.onclick = (ev) => { ev.stopPropagation(); SUBS.remove(l.id); this.toggleSubMenu(true); }; kids.push(b); });
12916
13043
  if (SUBS.layers.length > 1) kids.push(createEl('div', 'cc-menu-note', t('subMulti')));
12917
13044
  kids.push(item(t('subSearch'), false, () => { this.toggleSubMenu(false); OPENSUBS.open(); }));
12918
13045
  kids.push(item(t('subFile'), false, () => { this.toggleSubMenu(false); SUBS.openFile(); }));
@@ -13036,6 +13163,35 @@ async function handle(m) {
13036
13163
  return was;
13037
13164
  },
13038
13165
 
13166
+ // With the site's own controls, our two buttons (switch / exit) sit at the top right, where
13167
+ // many players keep theirs (cast, settings…). They step down below any site control there,
13168
+ // so neither covers the other.
13169
+ placeSiteBar() {
13170
+ const top = this.els?.top;
13171
+ if (!top) return;
13172
+ if (!STATE.isCinema || this.controlsMode() === 'nexus') { top.style.top = ''; return; }
13173
+ const now = Date.now();
13174
+ if (now - (this._barAt || 0) < 700) return;
13175
+ this._barAt = now;
13176
+ const boxes = [this.els.modeBtn, this.els.exitBtn].filter(b => b.getClientRects().length).map(b => b.getBoundingClientRect());
13177
+ if (!boxes.length) return;
13178
+ const host = document.getElementById('nxu-host');
13179
+ const from = Math.min(...boxes.map(r => r.left)) - 8, to = Math.max(...boxes.map(r => r.right)) + 8;
13180
+ const band = Math.min(140, innerHeight / 4);
13181
+ let low = 0;
13182
+ for (let x = Math.max(0, from); x <= Math.min(innerWidth - 1, to); x += 16) {
13183
+ for (let y = 2; y <= band; y += 10) {
13184
+ const el = document.elementsFromPoint(x, y).find(n => n !== host && !host?.contains(n));
13185
+ const c = el?.closest?.('button,a[href],[role="button"],select,input');
13186
+ if (!c) continue;
13187
+ const r = c.getBoundingClientRect();
13188
+ if (r.height < 90 && r.width < innerWidth / 2 && r.top < band) low = Math.max(low, r.bottom);
13189
+ }
13190
+ }
13191
+ const base = top.parentElement?.getBoundingClientRect().top || 0;
13192
+ top.style.top = low ? `${Math.round(low - base)}px` : '';
13193
+ },
13194
+
13039
13195
  // While paused (or a menu is open) the controls stay up instead of fading out.
13040
13196
  keepVisible() {
13041
13197
  if (!STATE.isCinema || !this.root || this.controlsMode() !== 'nexus') return false;
@@ -13069,7 +13225,10 @@ async function handle(m) {
13069
13225
  this.els.fsBtn.style.display = fullscreenSupported() ? '' : 'none';
13070
13226
  this.els.volume.style.display = IS_IOS ? 'none' : '';
13071
13227
  this.els.pipBtn.style.display = STATE.video && (document.pictureInPictureEnabled || typeof STATE.video.webkitSetPresentationMode === 'function') ? '' : 'none';
13072
- this.els.title.textContent = document.title || HOST;
13228
+ const msTitle = !MEDIA_SESSION._owned && navigator.mediaSession?.metadata?.title;
13229
+ this.els.title.textContent = msTitle || document.title || HOST;
13230
+ this._barAt = 0;
13231
+ this.placeSiteBar();
13073
13232
  if (!on) this._resetGestures();
13074
13233
  clearInterval(this._loop);
13075
13234
  this._loop = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kangsicj/nexussync",
3
- "version": "1.6.11",
3
+ "version": "1.6.13",
4
4
  "description": "Watch-together userscript: media sync, cinema mode, live AI subtitles, chat bubbles and quick ink for Violentmonkey, Tampermonkey and iOS Userscripts.",
5
5
  "keywords": [
6
6
  "userscript",