MCPcopy
hub / github.com/iChochy/NCE / updateLyricHighlight

Method updateLyricHighlight

js/ReadingSystem.js:478–520  ·  view source on GitHub ↗

* 更新歌词高亮

()

Source from the content-addressed store, hash-verified

476 * 更新歌词高亮
477 */
478 updateLyricHighlight() {
479 if (!this.lyricLineEls.length || !this.dom.audioPlayer || this.state.sentence) {
480 return;
481 }
482
483 if (this.state.loopMode !== 'list') {
484 this.state.sentence = true;
485 }
486
487 const currentTime = this.dom.audioPlayer.currentTime;
488 let newIndex = -1;
489
490 for (let i = this.state.currentLyrics.length - 1; i >= 0; i--) {
491 if (currentTime >= this.state.currentLyrics[i].time) {
492 newIndex = i;
493 break;
494 }
495 }
496
497 if (newIndex === this.state.currentLyricIndex) return;
498
499 // 移除旧高亮
500 if (
501 this.state.currentLyricIndex >= 0 &&
502 this.lyricLineEls[this.state.currentLyricIndex]
503 ) {
504 removeClass(this.lyricLineEls[this.state.currentLyricIndex], 'active');
505 removeClass(this.lyricLineEls[this.state.currentLyricIndex], 'pulse');
506 }
507
508 // 应用新高亮
509 if (newIndex >= 0) {
510 const activeLine = this.lyricLineEls[newIndex];
511 if (activeLine) {
512 addClass(activeLine, 'active');
513 addClass(activeLine, 'pulse');
514 if (this.shouldScrollLyricIntoView(activeLine)) {
515 activeLine.scrollIntoView({ behavior: 'smooth', block: 'center' });
516 }
517 }
518 }
519 this.state.currentLyricIndex = newIndex;
520 }
521
522 /**
523 * 判断歌词是否需要滚动到可视区域

Callers 1

bindPlayerControlsMethod · 0.95

Calls 3

removeClassFunction · 0.90
addClassFunction · 0.90

Tested by

no test coverage detected