@kangsicj/nexussync 1.6.15 → 1.6.16

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.15
11
+ // @version 1.6.16
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.15
11
+ // @version 1.6.16
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.15';
49
+ const NXU_VERSION = '1.6.16';
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.15';
54
+ const NXU_RANK = '11.6.16';
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=';
@@ -1279,7 +1279,8 @@ async function handle(m) {
1279
1279
  visibility: hidden !important; pointer-events: none !important; transition: none !important; animation: none !important; }
1280
1280
  .nxu-site-ui-off :is([class*="caption" i], [class*="subtitle" i], [class*="text-track" i], [class*="cue" i], [class*="danmaku" i]) { visibility: visible !important; }
1281
1281
  .nxu-site-ui-off .nxu-site-hide { visibility: hidden !important; pointer-events: none !important; transition: none !important; animation: none !important; }
1282
- .nxu-site-ui-off .nxu-dsub-src, .nxu-site-ui-off .nxu-dsub-src * { visibility: hidden !important; }
1282
+ /* Hidden by opacity (not visibility): what the site itself shows or hides inside can still be read. */
1283
+ .nxu-site-ui-off .nxu-dsub-src { opacity: 0 !important; clip-path: inset(100%) !important; pointer-events: none !important; transition: none !important; animation: none !important; }
1283
1284
  .nxu-cue-mirror { position: absolute !important; left: calc(50% + var(--nxu-cue-shift, 0px)) !important; right: auto !important; top: auto !important; bottom: var(--nxu-cue-bottom, 6%) !important; transform: translateX(-50%) !important;
1284
1285
  width: var(--nxu-cue-width, 90%) !important; max-width: 96% !important; height: auto !important; margin: 0 !important; padding: 0 !important; border: 0 !important; background: none !important;
1285
1286
  flex-direction: column !important; align-items: center !important; gap: 3px !important; z-index: 2147483646 !important; transition: bottom 0.3s ease !important; pointer-events: none !important; visibility: visible !important; opacity: 1 !important; }
@@ -1426,7 +1427,8 @@ async function handle(m) {
1426
1427
  _startAmbient(video, root) {
1427
1428
  this._stopAmbient();
1428
1429
  this._ambientPaused = false;
1429
- if (!video || !root || !this.ambientEnabled()) return;
1430
+ if (!video || !root || !this.ambientEnabled() || (this._ambientBlocked && this._ambientBlockedFor === video)) return;
1431
+ this._ambientBlocked = false; this._ambientBlockedFor = video; this._layerBelow = false;
1430
1432
  try { if (video.mediaKeys || video.webkitKeys) return; } catch (_) { } // DRM video always draws black
1431
1433
  const doc = video.ownerDocument;
1432
1434
  if (root.getRootNode() !== doc) return; // player inside a site's shadow DOM: our styles can't reach it
@@ -1455,6 +1457,8 @@ async function handle(m) {
1455
1457
  this._matchLayerZ(layer, root);
1456
1458
  const cleared = new Map();
1457
1459
  this._clearBackdrops(video, root, cleared);
1460
+ setTimeout(() => this._guardGlow(), 60);
1461
+ setTimeout(() => this._guardGlow(), 900);
1458
1462
  // Reading a video frame is the costly part (it was almost all of cinema's CPU time at
1459
1463
  // 16 a second). Six a second with a stronger blend looks the same: the glow eases
1460
1464
  // between scenes anyway, and a cut still shows within a fraction of a second.
@@ -1574,10 +1578,50 @@ async function handle(m) {
1574
1578
  try {
1575
1579
  const z = (root.ownerDocument.defaultView || window).getComputedStyle(root).zIndex;
1576
1580
  // One below the root (never level with it: some layouts then drew the glow on top).
1577
- const want = /^-?\d+$/.test(z) ? String(Math.max(-2147483647, Number(z) - 1)) : '0';
1581
+ const cs = (root.ownerDocument.defaultView || window).getComputedStyle(root);
1582
+ // A root that is not positioned ignores its z-index: any positioned layer at 0 or
1583
+ // more would be drawn over it (the whole picture looked blurred), so the glow goes below.
1584
+ const want = this._layerBelow || cs.position === 'static' ? '-1' : /^-?\d+$/.test(z) ? String(Math.max(-2147483647, Number(z) - 1)) : '0';
1578
1585
  if (layer.style.getPropertyValue('z-index') !== want) layer.style.setProperty('z-index', want, 'important');
1579
1586
  } catch (_) { }
1580
1587
  },
1588
+ // Is the glow drawn over the picture? Asked of the browser itself (what is on top at the
1589
+ // middle of the video), whatever the page's layout does. The glow and the video are
1590
+ // made hit-testable for the question only.
1591
+ _glowCoversVideo(a) {
1592
+ const doc = a.video.ownerDocument;
1593
+ const r = a.video.getBoundingClientRect();
1594
+ if (r.width < 40 || r.height < 40 || typeof doc.elementsFromPoint !== 'function') return false;
1595
+ const view = doc.defaultView || window;
1596
+ const x = Math.min(view.innerWidth - 2, Math.max(1, r.left + r.width / 2)), y = Math.min(view.innerHeight - 2, Math.max(1, r.top + r.height / 2));
1597
+ const keepL = a.layer.style.getPropertyValue('pointer-events'), prioL = a.layer.style.getPropertyPriority('pointer-events');
1598
+ const keepV = a.video.style.getPropertyValue('pointer-events'), prioV = a.video.style.getPropertyPriority('pointer-events');
1599
+ let covers = false;
1600
+ try {
1601
+ a.layer.style.setProperty('pointer-events', 'auto', 'important');
1602
+ a.video.style.setProperty('pointer-events', 'auto', 'important');
1603
+ const hits = doc.elementsFromPoint(x, y);
1604
+ const li = hits.indexOf(a.layer), vi = hits.indexOf(a.video);
1605
+ covers = li !== -1 && vi !== -1 && li < vi;
1606
+ } catch (_) { }
1607
+ if (keepL) a.layer.style.setProperty('pointer-events', keepL, prioL); else a.layer.style.removeProperty('pointer-events');
1608
+ if (keepV) a.video.style.setProperty('pointer-events', keepV, prioV); else a.video.style.removeProperty('pointer-events');
1609
+ return covers;
1610
+ },
1611
+ // Checked shortly after the glow starts and while cinema is on: first it is put below
1612
+ // everything; if the page still draws it over the picture, it is switched off here.
1613
+ _guardGlow() {
1614
+ const a = this._ambient;
1615
+ if (!a || !this._glowCoversVideo(a)) return;
1616
+ if (!this._layerBelow) {
1617
+ this._layerBelow = true;
1618
+ this._matchLayerZ(a.layer, a.root);
1619
+ if (!this._glowCoversVideo(a)) { logDebug('Ambient light moved below the page (it was drawn over the picture).', 'info'); return; }
1620
+ }
1621
+ logDebug('Ambient light off for this player: the page draws it over the picture.', 'warn');
1622
+ this._stopAmbient();
1623
+ this._ambientBlocked = true;
1624
+ },
1581
1625
  _ambientMisplaced(a) {
1582
1626
  return !a.layer.isConnected || !a.root.classList.contains('nxu-ambient-on') ||
1583
1627
  (a.root.parentNode && a.root.parentNode.nodeType === 1 && a.layer.nextSibling !== a.root);
@@ -1796,7 +1840,7 @@ async function handle(m) {
1796
1840
  // The site may fade or blur its video later (e.g. once it starts playing).
1797
1841
  const why = this._seeThrough(a.video, a.root);
1798
1842
  if (why) { logDebug('Ambient light off for this player: ' + why, 'info'); this._stopAmbient(); this._ambientPaused = true; }
1799
- else { this._matchLayerZ(a.layer, a.root); this._clearBackdrops(a.video, a.root, a.cleared); }
1843
+ else { this._matchLayerZ(a.layer, a.root); this._clearBackdrops(a.video, a.root, a.cleared); this._guardGlow(); }
1800
1844
  } else if (this._ambientPaused && this.ambientEnabled() && this.applied.video && this.applied.chain[0]?.root && Date.now() - (this._ambientTry || 0) > 2000) {
1801
1845
  this._ambientTry = Date.now();
1802
1846
  // Turned off only while the site faded or covered its picture (loading,
@@ -10895,7 +10939,7 @@ async function handle(m) {
10895
10939
  const root = STATE.isCinema && CINEMA.nexusControls() && CINEMA.applied?.chain?.[0]?.root;
10896
10940
  const v = CINEMA.applied?.video;
10897
10941
  if (!root || !v || root === v || root.ownerDocument !== document) { this.stop(); return; }
10898
- if (this._root === root) return;
10942
+ if (this._root === root) { this.scan(); return; } // (also once a second: silence and moves are noticed without a redraw)
10899
10943
  this.stop();
10900
10944
  this._root = root;
10901
10945
  // Scanned again a little later too: the list of the player's text layers is refreshed
@@ -10912,39 +10956,78 @@ async function handle(m) {
10912
10956
  clearTimeout(this._timer); this._timer = 0; clearTimeout(this._late);
10913
10957
  document.querySelectorAll('.nxu-dsub-src').forEach(n => n.classList.remove('nxu-dsub-src'));
10914
10958
  if (this._src && !SUBS.active()) SUBS._render('');
10915
- this._src = null; this._srcSig = null; this._cands.clear();
10959
+ this._src = null; this._srcSig = null; this._srcParent = null; this._otherAt = 0; clearTimeout(this._otherTimer); this._cands.clear();
10960
+ },
10961
+ // The text the site is showing in it right now. Lines the site keeps in the page but
10962
+ // hides (earlier cues left with display:none) are not read: innerText is what is
10963
+ // rendered. Only inside something this script hid itself is the raw text used.
10964
+ _text(el) {
10965
+ const mine = el.closest('.nxu-site-hide');
10966
+ // (An element the site took out of the layout reports all its text as innerText.)
10967
+ if (!mine && !el.getClientRects().length) return '';
10968
+ const raw = mine ? el.textContent : el.innerText ?? el.textContent;
10969
+ return String(raw || '').replace(/[ \t]+/g, ' ').replace(/\n{2,}/g, '\n').trim().slice(0, 300);
10916
10970
  },
10917
- _text(el) { return String(el.innerText || el.textContent || '').replace(/[ \t]+/g, ' ').replace(/\n{2,}/g, '\n').trim().slice(0, 300); },
10918
10971
  scan() {
10919
10972
  const root = this._root;
10920
10973
  if (!root || !root.isConnected) { this.stop(); return; }
10921
- if (this._src && this._src.isConnected) { this._show(); return; }
10922
10974
  const v = CINEMA.applied?.video;
10923
10975
  const cands = new Set();
10924
10976
  try { root.querySelectorAll(this.SEL).forEach(el => cands.add(el)); } catch (_) { }
10925
10977
  (CINEMA._textLayers || []).forEach(el => cands.add(el));
10978
+ const ok = (el) => el.isConnected && !el.contains(v) && !el.closest('.nxu-cue-mirror') && !el.querySelector('button, input, svg, [role="slider"]');
10926
10979
  // Many players (React and the like) draw each line as a new element: candidates are
10927
10980
  // followed by their place and look (tag, classes, parent), not by the element itself.
10928
- const sigOf = (el) => `${el.tagName}|${el.className}|${el.parentElement?.className || ''}|${el.parentElement?.tagName || ''}`;
10929
- if (this._srcSig) {
10930
- const tag = this._srcSig.split('|')[0];
10931
- const again = [...cands, ...root.getElementsByTagName(tag)].find(el => el.isConnected && !el.contains(v) && sigOf(el) === this._srcSig);
10932
- if (again) { this._src = again; again.classList.add('nxu-dsub-src'); this._show(); return; }
10933
- if (this._src && !this._src.isConnected) { this._src = null; if (!SUBS.active()) SUBS._render(''); }
10934
- return;
10935
- }
10981
+ const sigOf = (el) => `${el.tagName}|${String(el.className).replace(/\s*nxu-[\w-]+/g, '')}|${el.parentElement?.className || ''}|${el.parentElement?.tagName || ''}`;
10936
10982
  const now = Date.now();
10983
+ // Every candidate's text changes are noted (subtitles change, titles and watermarks do not).
10984
+ const live = [];
10937
10985
  for (const el of cands) {
10938
- if (!el.isConnected || el.contains(v) || el.closest('.nxu-cue-mirror') || el.querySelector('button, input, svg, [role="slider"]')) continue;
10939
- const txt = this._text(el);
10940
- const key = sigOf(el);
10941
- const c = this._cands.get(key) || { last: null, changes: [], };
10986
+ if (!ok(el)) continue;
10987
+ const key = sigOf(el), txt = this._text(el);
10988
+ const c = this._cands.get(key) || { last: null, changes: [] };
10942
10989
  if (txt !== c.last) { if (c.last !== null) c.changes.push(now); c.last = txt; }
10943
10990
  c.changes = c.changes.filter(ts => now - ts < 30000);
10944
10991
  this._cands.set(key, c);
10945
- // Two changes of its text within half a minute: subtitles, not a title.
10946
- 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; }
10992
+ live.push({ el, key, txt, c });
10993
+ }
10994
+ const claim = (el, key) => {
10995
+ if (this._src && this._src !== el) this._src.classList?.remove('nxu-dsub-src');
10996
+ this._src = el; this._srcSig = key; this._srcParent = el.parentElement;
10997
+ el.classList.add('nxu-dsub-src');
10998
+ };
10999
+ // 1. The source found before: the same element, one that looks the same, or the new
11000
+ // child of the same parent (a line redrawn with other class names).
11001
+ let src = this._src && this._src.isConnected ? this._src : null;
11002
+ if (!src && this._srcSig) {
11003
+ const tag = this._srcSig.split('|')[0];
11004
+ src = [...cands, ...root.getElementsByTagName(tag)].find(el => ok(el) && sigOf(el) === this._srcSig)
11005
+ || (this._srcParent?.isConnected ? [...this._srcParent.children].find(el => el.tagName === tag && ok(el) && this._text(el)) : null) || null;
11006
+ if (src) claim(src, this._srcSig);
11007
+ else if (this._src) { this._src = null; }
11008
+ }
11009
+ if (src && !src.classList.contains('nxu-dsub-src')) src.classList.add('nxu-dsub-src'); // a redraw reset its classes
11010
+ if (src && this._text(src)) { this._otherAt = 0; this._show(); return; }
11011
+ // 2. Found before but silent now. If the site meanwhile shows changing text somewhere
11012
+ // else (it redrew its subtitles into another element — after fullscreen, a quality
11013
+ // switch…), follow it there: its subtitles are never left hidden and unshown.
11014
+ if (this._srcSig) {
11015
+ const other = live.find(x => x.el !== src && !(src && (src.contains(x.el) || x.el.contains(src))) && x.txt && x.c.changes.length && now - x.c.changes[x.c.changes.length - 1] < 15000);
11016
+ if (!other) this._otherAt = 0;
11017
+ else if (!this._otherAt) { this._otherAt = now; clearTimeout(this._otherTimer); this._otherTimer = setTimeout(() => this.scan(), 1300); }
11018
+ else if (now - this._otherAt >= 1200) {
11019
+ this._otherAt = 0;
11020
+ claim(other.el, other.key);
11021
+ logDebug('Site subtitles moved to another element; following them.', 'info');
11022
+ this._show();
11023
+ return;
11024
+ }
11025
+ if (!SUBS.active()) SUBS._render('');
11026
+ return;
10947
11027
  }
11028
+ // 3. Nothing found yet: two changes of a text within half a minute are subtitles, not a title.
11029
+ const hit = live.find(x => x.c.changes.length >= 2);
11030
+ if (hit) { claim(hit.el, hit.key); logDebug('Site subtitles shown in the NexusSync layer.', 'info'); this._show(); }
10948
11031
  },
10949
11032
  _show() {
10950
11033
  if (SUBS.active()) return; // the user picked other subtitles
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kangsicj/nexussync",
3
- "version": "1.6.15",
3
+ "version": "1.6.16",
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",