@doitian/dsh-music 0.1.9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/panel.html CHANGED
@@ -13,10 +13,16 @@
13
13
  <meta name="dsh-music-panel-contract" content="2" />
14
14
  <title>Music · music.163.com</title>
15
15
  <style>
16
+ /* DSH's light palette (base background, primary label, scrollbar). The
17
+ page follows the shell's theme while it sits inside DSH, and the
18
+ system's otherwise; see syncShellTheme. Every other colour is mixed
19
+ from these. */
16
20
  :root {
17
- color-scheme: light dark;
18
- --bg: var(--dsh-background, #ffffff);
19
- --fg: var(--dsh-foreground, #1b1c1e);
21
+ color-scheme: light;
22
+ --bg: #ffffff;
23
+ --fg: #0f1115;
24
+ --scrollbar-thumb: #e5e5e5;
25
+ --scrollbar-thumb-hover: #d4d4d4;
20
26
  --muted: color-mix(in srgb, var(--fg) 56%, transparent);
21
27
  --faint: color-mix(in srgb, var(--fg) 38%, transparent);
22
28
  --line: color-mix(in srgb, var(--fg) 12%, transparent);
@@ -27,6 +33,23 @@
27
33
  --radius: 12px;
28
34
  --gap: 16px;
29
35
  }
36
+ /* DSH's dark palette: the system's choice standalone, the shell's inside DSH. */
37
+ @media (prefers-color-scheme: dark) {
38
+ :root:not([data-theme="light"]) {
39
+ color-scheme: dark;
40
+ --bg: #151517;
41
+ --fg: #f9fafb;
42
+ --scrollbar-thumb: #3c3c3d;
43
+ --scrollbar-thumb-hover: #545557;
44
+ }
45
+ }
46
+ :root[data-theme="dark"] {
47
+ color-scheme: dark;
48
+ --bg: #151517;
49
+ --fg: #f9fafb;
50
+ --scrollbar-thumb: #3c3c3d;
51
+ --scrollbar-thumb-hover: #545557;
52
+ }
30
53
  * { box-sizing: border-box; }
31
54
  html, body { margin: 0; height: 100%; }
32
55
  body {
@@ -54,6 +77,20 @@
54
77
  svg.i.filled { fill: currentColor; }
55
78
  svg.i.small { width: 14px; height: 14px; }
56
79
 
80
+ /* Scrollbars as DSH draws them in its conversation and everywhere else
81
+ (dsh-client-ui-theme's scrollbar.css): a 5px rounded thumb on no
82
+ track, darker under the pointer. */
83
+ @supports not selector(::-webkit-scrollbar) {
84
+ * { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }
85
+ }
86
+ ::-webkit-scrollbar { width: 5px; height: 5px; }
87
+ ::-webkit-scrollbar-track { background: none; }
88
+ ::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); background-clip: content-box; border-radius: 999px; }
89
+ ::-webkit-scrollbar-thumb:hover { background-color: var(--scrollbar-thumb-hover); }
90
+ ::-webkit-scrollbar-corner { background: none; }
91
+ /* Inside a card, the thumb keeps clear of the rounded corners, as DSH's own cards do. */
92
+ .card ::-webkit-scrollbar-track { margin-block: 6px; }
93
+
57
94
  /* ------------------------------------------------------------ layout
58
95
  Wide: the stage (what is playing) on the left, what comes next — the
59
96
  DJ and the queue — on the right, each column scrolling on its own.
@@ -82,9 +119,11 @@
82
119
  .side { overflow: hidden; border-left: 1px solid var(--line); }
83
120
  .side .queue-card { flex: 1; min-height: 0; }
84
121
  .side #queue { overflow: auto; }
85
- /* With a column of its own, the lyrics fill what the stage leaves. */
86
- .stage .lyrics-card { flex: 1; min-height: 160px; }
87
- .stage .lyrics { flex: 1; max-height: none; }
122
+ /* With a column of its own, the details or lyrics fill what the stage
123
+ leaves. The floor is the header and two lines: any higher and a short
124
+ window scrolls the whole column as well as the card. */
125
+ .stage .info-card { flex: 1; min-height: 72px; }
126
+ .stage .lyrics, .stage .details { flex: 1; max-height: none; }
88
127
  }
89
128
 
90
129
  .card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
@@ -147,7 +186,15 @@
147
186
  #mute:hover:not(:disabled) { color: var(--fg); }
148
187
  #volume { flex: 0 0 96px; }
149
188
 
150
- .lyrics-card { display: flex; flex-direction: column; min-height: 0; }
189
+ .info-card { display: flex; flex-direction: column; min-height: 0; }
190
+ .tabs { display: flex; gap: 14px; }
191
+ .tab {
192
+ background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 0 0 2px;
193
+ color: var(--muted); font: inherit; text-transform: inherit; letter-spacing: inherit;
194
+ }
195
+ .tab:hover:not(:disabled) { background: none; color: var(--fg); }
196
+ .tab.on { color: var(--fg); border-bottom-color: var(--accent); }
197
+ .lyrics[hidden], .details[hidden] { display: none; }
151
198
  /* The pane is a glance at the current line, not a page: a few lines of
152
199
  synced text, scrolled for the rest. `--lyrics-lines` is the single knob. */
153
200
  .lyrics {
@@ -156,13 +203,58 @@
156
203
  overflow: auto; padding: 2px 12px 14px; font-size: 14px; line-height: 1.6; scrollbar-width: none;
157
204
  }
158
205
  .lyrics::-webkit-scrollbar { display: none; }
159
- .lyrics.collapsed { display: none; }
160
206
  .lyrics p { margin: 0; padding: 2px 0; color: var(--faint); transition: color 0.15s; }
161
207
  .lyrics p.on { color: var(--fg); font-weight: 600; }
162
208
 
209
+ /* The song's facts first, then prose about the song, its artists and its
210
+ album, each clamped to a few lines until clicked. */
211
+ .details {
212
+ max-height: 320px; overflow: auto; padding: 2px 12px 14px;
213
+ display: flex; flex-direction: column; gap: 12px;
214
+ }
215
+ .details .alias { color: var(--muted); margin: 0; }
216
+ .facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 5px 14px; margin: 0; }
217
+ .facts dt { color: var(--muted); }
218
+ .facts dd { margin: 0; overflow-wrap: anywhere; }
219
+ .chips { display: flex; flex-wrap: wrap; gap: 4px; }
220
+ .chip { padding: 0 8px; border-radius: 999px; background: var(--hover); font-size: 12px; }
221
+ .chip.genre { background: var(--accent-soft); }
222
+ .about h4 {
223
+ margin: 0 0 3px; color: var(--muted); font-size: 11px; font-weight: 600;
224
+ text-transform: uppercase; letter-spacing: 0.6px;
225
+ }
226
+ .about .prose {
227
+ cursor: pointer;
228
+ display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden;
229
+ }
230
+ .about .prose.open { display: block; }
231
+ .about .prose p { margin: 0; }
232
+ .about .prose p + p { margin-top: 8px; }
233
+ .about .by { color: var(--muted); font-size: 12px; margin-top: 2px; }
234
+ .about .badge {
235
+ margin-left: 6px; padding: 0 5px; border-radius: 4px; background: var(--accent-soft); color: var(--accent);
236
+ font-size: 10px; letter-spacing: 0.4px;
237
+ }
238
+ .about .written { cursor: pointer; }
239
+ .about .written p { margin: 0; }
240
+ .about .written p + p { margin-top: 8px; }
241
+ .about .writing { color: var(--muted); margin: 0; }
242
+ .details .source { align-self: flex-start; font-size: 12px; }
243
+
244
+ /* Notices float over the page just below the header instead of taking
245
+ a place in it: one that comes and goes, such as the autoplay banner,
246
+ must not move what the listener is about to click. */
247
+ header { position: relative; }
248
+ #notices {
249
+ position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 30;
250
+ width: max-content; max-width: calc(100% - 2 * var(--gap));
251
+ display: flex; flex-direction: column; gap: 6px; pointer-events: none;
252
+ }
253
+ #notices > * { pointer-events: auto; }
163
254
  .need-gesture {
164
- background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
255
+ background: color-mix(in srgb, var(--accent) 13%, var(--bg)); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
165
256
  border-radius: var(--radius); padding: 8px 12px; font-size: 12px;
257
+ box-shadow: 0 6px 20px color-mix(in srgb, #000 18%, transparent);
166
258
  }
167
259
 
168
260
  /* -------------------------------------------------------------- side */
@@ -247,7 +339,7 @@
247
339
 
248
340
  .toast {
249
341
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
250
- background: #1b1c1e; color: #fff; padding: 8px 14px; border-radius: 9px; font-size: 12px;
342
+ background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 9px; font-size: 12px;
251
343
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 40; max-width: 80%;
252
344
  }
253
345
  .toast.on { opacity: 0.94; }
@@ -258,7 +350,7 @@
258
350
  dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
259
351
  #qr { display: block; margin: 12px auto; width: 220px; height: 220px; image-rendering: pixelated; border-radius: 8px; background: #fff; padding: 8px; }
260
352
  .hint { color: var(--muted); font-size: 12px; text-align: center; }
261
- .lyrics .hint { text-align: left; }
353
+ .lyrics .hint, .details .hint { text-align: left; margin: 0; }
262
354
  .row-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 14px; }
263
355
  </style>
264
356
  </head>
@@ -272,11 +364,11 @@
272
364
  <button id="scrobble-toggle" class="switch" role="switch" aria-labelledby="history-label"></button>
273
365
  </div>
274
366
  <div id="account"></div>
367
+ <div id="notices" aria-live="polite"></div>
275
368
  </header>
276
369
 
277
370
  <main>
278
371
  <section class="stage">
279
- <div id="notices"></div>
280
372
  <div class="np">
281
373
  <div class="cover"><span id="cover-icon"></span><img id="cover" alt="" /></div>
282
374
  <div class="np-text">
@@ -313,15 +405,15 @@
313
405
  <input type="range" id="volume" min="0" max="1" step="0.01" value="0.8" />
314
406
  </div>
315
407
 
316
- <div class="card lyrics-card">
408
+ <div class="card info-card">
317
409
  <div class="card-head">
318
- <span data-i18n="lyrics">Lyrics</span>
319
- <span class="grow"></span>
320
- <!-- Label and title are state-dependent, so the script owns them
321
- (applyStaticStrings cannot know which way the pane is now). -->
322
- <button id="lyrics-toggle" class="link" type="button" aria-expanded="true">Hide</button>
410
+ <div class="tabs" role="tablist">
411
+ <button id="tab-details" class="tab" type="button" role="tab" data-i18n="details">Details</button>
412
+ <button id="tab-lyrics" class="tab" type="button" role="tab" data-i18n="lyrics">Lyrics</button>
413
+ </div>
323
414
  </div>
324
- <div class="lyrics" id="lyrics"><p class="hint">—</p></div>
415
+ <div class="details" id="details" role="tabpanel"><p class="hint">—</p></div>
416
+ <div class="lyrics" id="lyrics" role="tabpanel" hidden><p class="hint">—</p></div>
325
417
  </div>
326
418
  </section>
327
419
 
@@ -365,7 +457,11 @@
365
457
  </div>
366
458
 
367
459
  <div class="card queue-card">
368
- <div class="card-head"><span data-i18n="queue">Queue</span> <span id="counts"></span></div>
460
+ <div class="card-head">
461
+ <span data-i18n="queue">Queue</span> <span id="counts"></span>
462
+ <span class="grow"></span>
463
+ <button id="queue-clear" class="link" type="button" data-i18n="clearQueue" data-i18n-title="clearQueueTitle">Clear</button>
464
+ </div>
369
465
  <div id="queue"></div>
370
466
  </div>
371
467
  </aside>
@@ -423,10 +519,24 @@
423
519
  likeNeedsSignIn: '登录后才能在网易云标记喜欢',
424
520
  mute: '静音',
425
521
  lyrics: '歌词',
426
- lyricsHide: '收起',
427
- lyricsShow: '展开',
428
- lyricsToggleHide: '收起歌词面板',
429
- lyricsToggleShow: '展开歌词面板',
522
+ details: '详情',
523
+ noDetails: '暂无这首歌的信息',
524
+ album: '专辑',
525
+ albumTracks: '{n} 首',
526
+ genre: '曲风',
527
+ tags: '标签',
528
+ language: '语种',
529
+ featuredIn: '影视节目',
530
+ awards: '获奖',
531
+ aboutSong: '关于这首歌',
532
+ aboutAlbum: '关于专辑',
533
+ reviewBy: '乐评来自 {name}',
534
+ intro: '简介',
535
+ introWriting: '正在撰写简介…',
536
+ introFromNetease: '查看网易云音乐的介绍',
537
+ introFromAi: '查看 AI 简介',
538
+ introToNetease: '点击查看网易云音乐的介绍',
539
+ expand: '点击展开或收起',
430
540
  queue: '播放队列',
431
541
  djModel: 'AI DJ 模型',
432
542
  djModelToggleShow: '展开模型设置',
@@ -458,6 +568,8 @@
458
568
  queueEmpty: '队列为空,用 AI DJ 或让助手补歌',
459
569
  remove: '移除',
460
570
  removed: '已移除',
571
+ clearQueue: '清空',
572
+ clearQueueTitle: '清空队列,保留正在播放的歌曲;不会给歌曲打分',
461
573
  loading: '加载中…',
462
574
  instrumental: '纯音乐,无歌词',
463
575
  other: '其他…',
@@ -525,10 +637,24 @@
525
637
  likeNeedsSignIn: 'Sign in to NetEase to like tracks',
526
638
  mute: 'Mute',
527
639
  lyrics: 'Lyrics',
528
- lyricsHide: 'Hide',
529
- lyricsShow: 'Show',
530
- lyricsToggleHide: 'Collapse the lyrics pane',
531
- lyricsToggleShow: 'Expand the lyrics pane',
640
+ details: 'Details',
641
+ noDetails: 'No details for this song',
642
+ album: 'Album',
643
+ albumTracks: '{n} tracks',
644
+ genre: 'Genre',
645
+ tags: 'Tags',
646
+ language: 'Language',
647
+ featuredIn: 'Featured in',
648
+ awards: 'Awards',
649
+ aboutSong: 'About the song',
650
+ aboutAlbum: 'About the album',
651
+ reviewBy: 'Review by {name}',
652
+ intro: 'Introduction',
653
+ introWriting: 'Writing an introduction…',
654
+ introFromNetease: 'Show what NetEase says',
655
+ introFromAi: 'Show the AI introduction',
656
+ introToNetease: 'Click to show what NetEase says',
657
+ expand: 'Click to expand or collapse',
532
658
  queue: 'Queue',
533
659
  djModel: 'DJ model',
534
660
  djModelToggleShow: 'Show the model settings',
@@ -560,6 +686,8 @@
560
686
  queueEmpty: 'Queue empty — use the AI DJ or ask the assistant to add songs',
561
687
  remove: 'Remove',
562
688
  removed: 'Removed',
689
+ clearQueue: 'Clear',
690
+ clearQueueTitle: 'Clear the queue, keeping the song playing; no song is rated',
563
691
  loading: 'Loading…',
564
692
  instrumental: 'Instrumental',
565
693
  other: 'Other…',
@@ -703,10 +831,11 @@
703
831
  document.documentElement.lang = LANG === 'zh' ? 'zh-CN' : 'en';
704
832
  } catch { /* headless */ }
705
833
  applyStaticStrings();
706
- // The toggles' labels and titles depend on the collapse state, not on a
707
- // fixed key, so they are painted rather than carried as data-i18n.
708
- paintLyricsToggle();
834
+ // The model toggle's label depends on its fold, not on a fixed key, so
835
+ // it is painted rather than carried as data-i18n.
709
836
  paintDjModelToggle();
837
+ // The details carry translated labels around NetEase's own text.
838
+ if (infoView === 'details') repaintDetails();
710
839
  // The gesture hint carries markup; drop it so render() rebuilds it in
711
840
  // the new language.
712
841
  $('gesture')?.remove();
@@ -722,6 +851,42 @@
722
851
  }
723
852
 
724
853
  /** Follow the shell's language while this page lives inside it. */
854
+ /** The shell's colours this page takes on, by the shell's variable name. */
855
+ const SHELL_COLORS = [
856
+ ['--dsw-alias-bg-base', '--bg'],
857
+ ['--dsw-alias-label-primary', '--fg'],
858
+ ['--dsh-scrollbar-thumb', '--scrollbar-thumb'],
859
+ ['--dsh-scrollbar-thumb-hover', '--scrollbar-thumb-hover'],
860
+ ];
861
+
862
+ /**
863
+ * Follow the shell's theme. DSH marks dark with `data-ds-dark-theme` on
864
+ * its body and paints from token variables there; this page takes the
865
+ * mark, then the live colours, so a custom DSH theme carries over too.
866
+ * A theme switch rewrites those attributes and styles, so watching them
867
+ * catches every switch. Standalone, the system's preference decides.
868
+ */
869
+ function syncShellTheme() {
870
+ try {
871
+ const shell = window.parent?.document;
872
+ if (!shell?.body || shell === document) return;
873
+ const copy = () => {
874
+ const root = document.documentElement;
875
+ root.dataset.theme = shell.body.hasAttribute('data-ds-dark-theme') ? 'dark' : 'light';
876
+ const computed = getComputedStyle(shell.body);
877
+ for (const [from, to] of SHELL_COLORS) {
878
+ const value = computed.getPropertyValue(from).trim();
879
+ if (value) root.style.setProperty(to, value);
880
+ else root.style.removeProperty(to);
881
+ }
882
+ };
883
+ copy();
884
+ if (typeof MutationObserver !== 'function') return;
885
+ const observer = new MutationObserver(copy);
886
+ for (const node of [shell.documentElement, shell.body]) observer.observe(node, { attributes: true, attributeFilter: ['style', 'class', 'data-ds-dark-theme'] });
887
+ } catch { /* standalone, or the shell is out of reach */ }
888
+ }
889
+
725
890
  function watchShellLocale() {
726
891
  try {
727
892
  const root = window.parent?.document?.documentElement;
@@ -738,9 +903,25 @@
738
903
  let lyricTrackId = null;
739
904
  /** Bumped per request so a slow reply for a skipped track is discarded. */
740
905
  let lyricRequest = 0;
741
- /** Local-storage key for whether the lyrics pane is collapsed. */
742
- const LYRICS_PREF = 'dsh-music.lyrics.collapsed';
743
- let lyricsCollapsed = readLyricsPref();
906
+ /** Local-storage key for which pane the info card shows: `details` or `lyrics`. */
907
+ const INFO_VIEW_PREF = 'dsh-music.info.view';
908
+ let infoView = readInfoViewPref();
909
+ /** Track whose details belong in the pane, as `lyricTrackId` is for lyrics. */
910
+ let detailsTrackId = null;
911
+ let detailsRequest = 0;
912
+ /** Details already fetched, by track id, so switching back is instant. */
913
+ const detailsCache = new Map();
914
+ /** Details being fetched, by track id, so a prefetch and a load share one request. */
915
+ const detailsLoads = new Map();
916
+ /**
917
+ * Model-written introductions by `<track id>:<language>`: `'pending'`
918
+ * while one is being written, then `{text}`, empty when none could be.
919
+ */
920
+ const intros = new Map();
921
+ /** Whether the last introduction came back empty, so the next track shows NetEase's prose while it waits. */
922
+ let introsUnavailable = false;
923
+ /** Which introduction the details show: `ai`, or NetEase's own (`netease`). Back to `ai` per track. */
924
+ let introSource = 'ai';
744
925
  /** Local-storage key for whether the DJ model form is unfolded. */
745
926
  const DJ_MODEL_PREF = 'dsh-music.djmodel.expanded';
746
927
  let djModelExpanded = readDjModelPref();
@@ -857,11 +1038,20 @@
857
1038
  let busy = false;
858
1039
  let disposed = false;
859
1040
 
1041
+ /** Start audio, and report a refusal by the autoplay policy as the engine does. */
860
1042
  function attemptPlay() {
861
1043
  if (busy || disposed) return;
862
1044
  busy = true;
863
- const done = () => { busy = false; };
864
- audio.play().then(done, done);
1045
+ audio.play().then(
1046
+ () => {
1047
+ busy = false;
1048
+ report({ blocked: false });
1049
+ },
1050
+ (error) => {
1051
+ busy = false;
1052
+ if (error?.name === 'NotAllowedError') report({ blocked: true });
1053
+ },
1054
+ );
865
1055
  }
866
1056
 
867
1057
  function reconcile(next) {
@@ -1007,19 +1197,16 @@
1007
1197
  }
1008
1198
 
1009
1199
  /**
1010
- * The host wants playback, and the transport's own report for *this*
1011
- * track says it is not playing. In practice that means the browser
1012
- * refused to start audio until the page has been interacted with.
1200
+ * The host wants playback, and the transport reported that the browser
1201
+ * refused to start it until the page is interacted with.
1202
+ *
1203
+ * Only the refusal counts. "Wanted but not playing" alone is also true
1204
+ * for the half second after any Play click, before the transport has
1205
+ * caught up — which flashed this hint on every press.
1013
1206
  */
1014
1207
  function autoplayBlocked() {
1015
1208
  const reported = state?.reported;
1016
- return Boolean(
1017
- state?.playing &&
1018
- state?.current &&
1019
- reported?.playing === false &&
1020
- Number(reported.at) > 0 &&
1021
- reported.trackId === state.current.id,
1022
- );
1209
+ return Boolean(state?.playing && state?.current && reported?.blocked === true && reported.playing === false);
1023
1210
  }
1024
1211
 
1025
1212
  /**
@@ -1051,24 +1238,18 @@
1051
1238
  $('np-title').textContent = track ? track.name : t('nothingPlaying');
1052
1239
  $('np-artists').textContent = track ? (track.artists || []).join(' / ') : '';
1053
1240
  $('np-album').textContent = track ? track.album || '' : '';
1054
- // Lyrics belong to the track, and this page fetches them itself on
1055
- // every poll — not from the local transport's `applySource`, which
1056
- // only ever runs when this page owns the audio element. In the normal
1057
- // case the shell engine plays, so that path is dead and the pane
1058
- // stayed empty forever.
1059
- const trackId = track?.id ?? null;
1060
- if (trackId !== lyricTrackId) {
1061
- lyricTrackId = trackId;
1062
- if (trackId) loadLyrics(trackId);
1063
- else {
1064
- lyric = null;
1065
- lyricLine = -1;
1066
- $('lyrics').innerHTML = '<p class="hint">—</p>';
1067
- }
1068
- }
1241
+ // Details and lyrics belong to the track, and this page fetches them
1242
+ // itself on every poll — not from the local transport's `applySource`,
1243
+ // which only ever runs when this page owns the audio element. In the
1244
+ // normal case the shell engine plays, so that path is dead and the
1245
+ // pane stayed empty forever.
1246
+ syncInfo(track?.id ?? null);
1247
+ loadIntro();
1248
+ prefetchNextDetails();
1069
1249
  setIcon($('play'), state.playing ? 'pause' : 'play', { filled: true });
1070
1250
  $('mode').textContent = { list: t('modeList'), single: t('modeSingle'), shuffle: t('modeShuffle') }[state.mode] || t('modeList');
1071
1251
  $('counts').textContent = state.counts ? `(${state.counts.queued})` : '';
1252
+ $('queue-clear').disabled = (state.queue?.length ?? 0) <= (state.current ? 1 : 0);
1072
1253
  $('dj-toggle').classList.toggle('on', Boolean(state.dj?.enabled));
1073
1254
  paintHistory();
1074
1255
  // The mood brief is persisted player setting, not part of the DJ status
@@ -1301,38 +1482,239 @@
1301
1482
  $('t-dur').textContent = fmt(duration);
1302
1483
  }
1303
1484
 
1304
- // ---------------------------------------------------------------- lyrics
1305
- /** Collapsed preference, remembered across reloads when storage is open. */
1306
- function readLyricsPref() {
1307
- try { return localStorage.getItem(LYRICS_PREF) === '1'; } catch { return false; }
1485
+ // ------------------------------------------------------ details + lyrics
1486
+ /** The pane shown, remembered across reloads when storage is open; details by default. */
1487
+ function readInfoViewPref() {
1488
+ try { return localStorage.getItem(INFO_VIEW_PREF) === 'lyrics' ? 'lyrics' : 'details'; } catch { return 'details'; }
1308
1489
  }
1309
1490
 
1310
- function saveLyricsPref(collapsed) {
1311
- try { localStorage.setItem(LYRICS_PREF, collapsed ? '1' : '0'); } catch { /* storage denied */ }
1491
+ function saveInfoViewPref(view) {
1492
+ try { localStorage.setItem(INFO_VIEW_PREF, view); } catch { /* storage denied */ }
1312
1493
  }
1313
1494
 
1314
- /** Reflect `lyricsCollapsed` in the pane and in the header button. */
1315
- function paintLyricsToggle() {
1316
- $('lyrics').classList.toggle('collapsed', lyricsCollapsed);
1317
- const button = $('lyrics-toggle');
1318
- button.textContent = t(lyricsCollapsed ? 'lyricsShow' : 'lyricsHide');
1319
- button.title = t(lyricsCollapsed ? 'lyricsToggleShow' : 'lyricsToggleHide');
1320
- button.setAttribute('aria-expanded', lyricsCollapsed ? 'false' : 'true');
1495
+ /** Reflect `infoView` in the tabs and the panes. */
1496
+ function paintInfoTabs() {
1497
+ for (const view of ['details', 'lyrics']) {
1498
+ const on = infoView === view;
1499
+ $('tab-' + view).classList.toggle('on', on);
1500
+ $('tab-' + view).setAttribute('aria-selected', on ? 'true' : 'false');
1501
+ $(view).hidden = !on;
1502
+ }
1321
1503
  }
1322
1504
 
1323
- $('lyrics-toggle').onclick = () => {
1324
- lyricsCollapsed = !lyricsCollapsed;
1325
- saveLyricsPref(lyricsCollapsed);
1326
- paintLyricsToggle();
1327
- // A hidden pane has no scroll position to keep, so re-expanding puts
1328
- // the highlighted line back in view instead of waiting for the next
1329
- // line change to scroll there.
1330
- if (!lyricsCollapsed) {
1505
+ /**
1506
+ * Bring the visible pane up to the track. Only the visible one: a hidden
1507
+ * pane is neither fetched nor painted, and catches up when it is shown.
1508
+ */
1509
+ function syncInfo(trackId) {
1510
+ if (infoView === 'details') {
1511
+ if (trackId === detailsTrackId) return;
1512
+ detailsTrackId = trackId;
1513
+ if (trackId) loadDetails(trackId);
1514
+ else $('details').innerHTML = '<p class="hint">—</p>';
1515
+ return;
1516
+ }
1517
+ if (trackId === lyricTrackId) return;
1518
+ lyricTrackId = trackId;
1519
+ if (trackId) loadLyrics(trackId);
1520
+ else {
1521
+ lyric = null;
1522
+ lyricLine = -1;
1523
+ $('lyrics').innerHTML = '<p class="hint">—</p>';
1524
+ }
1525
+ }
1526
+
1527
+ function showInfo(view) {
1528
+ if (view === infoView) return;
1529
+ infoView = view;
1530
+ saveInfoViewPref(view);
1531
+ paintInfoTabs();
1532
+ syncInfo(state?.current?.id ?? null);
1533
+ // A hidden pane kept no scroll position, so showing the lyrics puts the
1534
+ // current line back in view instead of waiting for the next line.
1535
+ if (view === 'lyrics') {
1331
1536
  lyricLine = -1;
1332
1537
  paintLyrics();
1333
1538
  }
1539
+ }
1540
+
1541
+ $('tab-details').onclick = () => showInfo('details');
1542
+ $('tab-lyrics').onclick = () => showInfo('lyrics');
1543
+ paintInfoTabs();
1544
+
1545
+ // The introduction's switch, or the written one itself, swaps it with
1546
+ // NetEase's prose; clamped prose opens in place.
1547
+ $('details').onclick = (event) => {
1548
+ const source = event.target.closest?.('[data-source]')?.dataset.source ?? (event.target.closest?.('.written') ? 'netease' : null);
1549
+ if (source) {
1550
+ introSource = source;
1551
+ repaintDetails({ keepScroll: true });
1552
+ return;
1553
+ }
1554
+ const prose = event.target.closest?.('.about .prose');
1555
+ if (prose) prose.classList.toggle('open');
1334
1556
  };
1335
1557
 
1558
+ /** One track's details, fetched once however many ask, and kept. */
1559
+ function fetchDetails(id) {
1560
+ if (!detailsLoads.has(id)) {
1561
+ const load = api('/info/' + id)
1562
+ .then((info) => {
1563
+ detailsCache.set(id, info);
1564
+ if (detailsCache.size > 30) detailsCache.delete(detailsCache.keys().next().value);
1565
+ return info;
1566
+ })
1567
+ .finally(() => detailsLoads.delete(id));
1568
+ detailsLoads.set(id, load);
1569
+ }
1570
+ return detailsLoads.get(id);
1571
+ }
1572
+
1573
+ /**
1574
+ * Fetch the next track's details ahead, so they show the moment it
1575
+ * starts. Lazy like the introduction: only on a poll after the shown
1576
+ * track's details have landed, and only while the details are shown.
1577
+ * Shuffle has no known next track, and repeat-one's next is this one.
1578
+ */
1579
+ function prefetchNextDetails() {
1580
+ if (infoView !== 'details' || !detailsTrackId || !detailsCache.has(detailsTrackId)) return;
1581
+ if (!state || state.mode !== 'list') return;
1582
+ const next = state.queue?.[state.index + 1];
1583
+ if (!next?.id || detailsCache.has(next.id) || detailsLoads.has(next.id)) return;
1584
+ fetchDetails(next.id).catch(() => { /* the track's own load retries */ });
1585
+ }
1586
+
1587
+ async function loadDetails(id) {
1588
+ const request = ++detailsRequest;
1589
+ introSource = 'ai';
1590
+ const cached = detailsCache.get(id);
1591
+ if (cached) {
1592
+ paintDetails(cached);
1593
+ return;
1594
+ }
1595
+ $('details').innerHTML = `<p class="hint">${esc(t('loading'))}</p>`;
1596
+ try {
1597
+ const info = await fetchDetails(id);
1598
+ if (request !== detailsRequest) return;
1599
+ paintDetails(info);
1600
+ } catch (error) {
1601
+ if (request !== detailsRequest) return;
1602
+ $('details').innerHTML = `<p class="hint">${esc(error.message)}</p>`;
1603
+ }
1604
+ }
1605
+
1606
+ /** Paint the shown track's details again: a language switch, an introduction, the switch. */
1607
+ function repaintDetails(options) {
1608
+ const info = detailsCache.get(detailsTrackId);
1609
+ if (info) paintDetails(info, options);
1610
+ }
1611
+
1612
+ /**
1613
+ * Ask for the shown track's introduction, once its details are painted.
1614
+ *
1615
+ * Lazy on purpose: a model call takes seconds, so it waits for the poll
1616
+ * after the details land — playback and the NetEase facts never wait on
1617
+ * it — and it is asked only for the track the visible pane shows.
1618
+ */
1619
+ async function loadIntro() {
1620
+ if (infoView !== 'details' || !detailsTrackId || !detailsCache.has(detailsTrackId)) return;
1621
+ const id = detailsTrackId;
1622
+ const key = `${id}:${LANG}`;
1623
+ if (intros.has(key)) return;
1624
+ intros.set(key, 'pending');
1625
+ if (intros.size > 60) intros.delete(intros.keys().next().value);
1626
+ let text = '';
1627
+ try {
1628
+ const answer = await api(`/intro/${id}?lang=${LANG}`);
1629
+ text = typeof answer?.text === 'string' ? answer.text : '';
1630
+ } catch { /* NetEase's prose stands in */ }
1631
+ intros.set(key, { text });
1632
+ introsUnavailable = !text;
1633
+ if (infoView === 'details' && detailsTrackId === id) repaintDetails({ keepScroll: true });
1634
+ }
1635
+
1636
+ /** NetEase dates are midnight in China; read them there, as YYYY-MM-DD. */
1637
+ function chinaDate(ms) {
1638
+ try {
1639
+ return new Date(ms).toLocaleDateString('sv-SE', { timeZone: 'Asia/Shanghai' });
1640
+ } catch {
1641
+ return new Date(ms).toISOString().slice(0, 10);
1642
+ }
1643
+ }
1644
+
1645
+ function paintDetails(info, { keepScroll = false } = {}) {
1646
+ const facts = [];
1647
+ const fact = (label, html) => facts.push(`<dt>${esc(t(label))}</dt><dd>${html}</dd>`);
1648
+ const chips = (list, kind = '') =>
1649
+ `<span class="chips">${list.map((item) => `<span class="chip ${kind}">${esc(item)}</span>`).join('')}</span>`;
1650
+
1651
+ const album = info.album ?? {};
1652
+ if (album.name) {
1653
+ const notes = [
1654
+ album.subType || album.type,
1655
+ album.publishTime ? chinaDate(album.publishTime) : '',
1656
+ album.company,
1657
+ album.size > 1 ? t('albumTracks', { n: album.size }) : '',
1658
+ ].filter(Boolean);
1659
+ fact('album', esc(album.name) + (notes.length ? ` <span class="muted">· ${esc(notes.join(' · '))}</span>` : ''));
1660
+ }
1661
+ // A genre is a path such as 流行-华语流行; its leaf names it.
1662
+ if (info.genres?.length) fact('genre', chips(info.genres.map((genre) => genre.split('-').pop()), 'genre'));
1663
+ if (info.tags?.length) fact('tags', chips(info.tags));
1664
+ const spoken = [info.language, info.bpm ? `${info.bpm} BPM` : ''].filter(Boolean);
1665
+ if (spoken.length) fact('language', esc(spoken.join(' · ')));
1666
+ if (info.featuredIn?.length) fact('featuredIn', esc(info.featuredIn.join(';')));
1667
+ if (info.awards?.length) fact('awards', esc(info.awards.join(';')));
1668
+
1669
+ const netease = [];
1670
+ // NetEase separates paragraphs with a line break, often indented with
1671
+ // full-width spaces; each becomes its own paragraph, spaced apart.
1672
+ const paragraphs = (text) =>
1673
+ String(text)
1674
+ .split(/\n+/)
1675
+ .map((line) => line.trim())
1676
+ .filter(Boolean)
1677
+ .map((line) => `<p>${esc(line)}</p>`)
1678
+ .join('');
1679
+ const section = (title, text, by = '') =>
1680
+ netease.push(
1681
+ `<section class="about"><h4>${esc(title)}</h4><div class="prose" title="${esc(t('expand'))}">${paragraphs(text)}</div>` +
1682
+ (by ? `<div class="by">${esc(by)}</div>` : '') +
1683
+ '</section>',
1684
+ );
1685
+ if (info.review?.text) section(t('aboutSong'), info.review.text, info.review.by ? t('reviewBy', { name: info.review.by }) : '');
1686
+ for (const artist of info.artists ?? []) if (artist.intro) section(artist.name, artist.intro);
1687
+ if (album.intro) section(t('aboutAlbum'), album.intro);
1688
+
1689
+ // The model's introduction leads; NetEase's prose is a click away. While
1690
+ // it is written, NetEase's prose shows if the model was last unavailable.
1691
+ const intro = intros.get(`${info.id}:${LANG}`);
1692
+ const written = typeof intro === 'object' && intro.text ? intro.text : '';
1693
+ const waiting = intro === undefined || intro === 'pending';
1694
+ const head = `<h4>${esc(t('intro'))}<span class="badge">AI</span></h4>`;
1695
+ const swap = (to, label) => `<button class="link source" type="button" data-source="${to}">${esc(t(label))}</button>`;
1696
+ let about;
1697
+ if (introSource === 'ai' && written) {
1698
+ about =
1699
+ `<section class="about">${head}<div class="written" title="${esc(t('introToNetease'))}">${paragraphs(written)}</div></section>` +
1700
+ (netease.length ? swap('netease', 'introFromNetease') : '');
1701
+ } else if (introSource === 'ai' && waiting && !introsUnavailable) {
1702
+ about =
1703
+ `<section class="about">${head}<p class="writing">${esc(t('introWriting'))}</p></section>` +
1704
+ (netease.length ? swap('netease', 'introFromNetease') : '');
1705
+ } else {
1706
+ about = (written ? swap('ai', 'introFromAi') : '') + netease.join('');
1707
+ }
1708
+
1709
+ const alias = info.alias?.length ? `<p class="alias">${esc(info.alias.join(' / '))}</p>` : '';
1710
+ const scrolled = $('details').scrollTop;
1711
+ $('details').innerHTML =
1712
+ facts.length || about || alias
1713
+ ? alias + (facts.length ? `<dl class="facts">${facts.join('')}</dl>` : '') + about
1714
+ : `<p class="hint">${esc(t('noDetails'))}</p>`;
1715
+ $('details').scrollTop = keepScroll ? scrolled : 0;
1716
+ }
1717
+
1336
1718
  async function loadLyrics(id) {
1337
1719
  const request = ++lyricRequest;
1338
1720
  lyric = null;
@@ -1367,7 +1749,7 @@
1367
1749
  }
1368
1750
 
1369
1751
  function paintLyrics() {
1370
- if (!lyric) return;
1752
+ if (!lyric || infoView !== 'lyrics') return;
1371
1753
  const at = positionMs();
1372
1754
  let active = -1;
1373
1755
  for (let index = 0; index < lyric.length; index++) {
@@ -1834,6 +2216,15 @@
1834
2216
  };
1835
2217
  $('dj-prompt').onchange = () => api('/dj', { method: 'POST', body: { prompt: $('dj-prompt').value, enabled: state?.dj?.enabled } }).then((data) => { state = data; render(); }).catch((error) => toast(error.message));
1836
2218
 
2219
+ // Not row-by-row removal, which reads each row as a dislike.
2220
+ $('queue-clear').onclick = async () => {
2221
+ try {
2222
+ state = await api('/queue', { method: 'POST', body: { action: 'clear', keepCurrent: true } });
2223
+ render();
2224
+ pokeEngine();
2225
+ } catch (error) { toast(failureText(error)); }
2226
+ };
2227
+
1837
2228
  $('queue').onclick = async (event) => {
1838
2229
  const like = event.target.closest('[data-like]');
1839
2230
  const jump = event.target.closest('[data-jump]')?.dataset.jump;
@@ -1873,6 +2264,7 @@
1873
2264
  paintStaticIcons();
1874
2265
  applyLocale();
1875
2266
  watchShellLocale();
2267
+ syncShellTheme();
1876
2268
  refresh();
1877
2269
  setInterval(refresh, 1500);
1878
2270
  void loadModelPicker();