Original PV: Letter to the Black World / Kasane Teto - フロクロ Credit: Frog96
Press Enter to play
https://n3xta.github.io/lyric-displayer/
-
Pass in
lyric
and check theisNew
property- If
isNew
isfalse
, clear all<span>
(or<div>
) elements on the screen - If
isNew
istrue
, skip clearing
- If
-
Process
lyric
by splitting it into<span>
elements- Use a regular expression to find all
<br>
and<span>
tags. Thesplit
function will retain the matched tags after splitting.- Match
<br>
<span[^>]*>.*?<\/span>
matches all<span>
tags<span[^>]*>
matches the opening part of the<span>
tag with all attributes.*?
matches any content within the tag (non-greedy)
- Match
- Use
.map(part => { ... })
to iterate over each split partif (part === '<br>')
: return<br>
directly to keep HTML line breakselse if (part.match(/<span[^>]*>.*?<\/span>/))
: if wrapped in<span>
, retain it as iselse
: for plain text- Use
split('')
to break the text string into individual characters - Wrap each character in
<span class="${spanClass}">
to encapsulate each character in a<span>
tag spanClass
is a variable representing the CSS class to apply
- Use
- Finally, use
.join('')
to concatenate the result returned bymap
into a complete string
- Use a regular expression to find all
-
Decide whether to append the new content based on the value of
isNew
- Use
lyricDiv.html()
to get the current HTML content of thelyricDiv
element- If
isNew
istrue
, append the new contentchars
to the existing content - If
isNew
isfalse
, replace the original content withchars
- If
- Use
-
Animation handling
- Regardless of the value of
isNew
, add theanimate-me
class to new characters (apply animation each time new characters are added tolyricDiv
) - The animation targets all elements with the
animate-me
class, including newly added and appended content. Once the animation completes, remove theanimate-me
class.
- Regardless of the value of
原 PV:黒塗り世界宛て書簡/重音テト(Letter to the Black World / Kasane Teto)- フロクロ
按下 Enter 播放
点这里
-
传入
lyric
,并判断isNew
属性- 如果为
false
,即清空屏幕上所有的<span>
(或<div>
) - 如果为
true
,略过清空
- 如果为
-
对
lyric
进行拆分并包裹在<span>
中- 使用正则表达式找到所有的
<br>
和<span>
标签,split
函数在分割后保留匹配的标签。- 匹配
<br>
<span[^>]*>.*?<\/span>
匹配所有<span>
标签<span[^>]*>
匹配<span>
标签的开头部分及所有属性.*?
匹配标签中的任意内容(非贪婪模式)
- 匹配
- 使用
.map(part => { ... })
遍历每个分割的部分if (part === '<br>')
:直接返回<br>
,保留 HTML 换行else if (part.match(/<span[^>]*>.*?<\/span>/))
:如果是<span>
标签包裹的内容,保留原样else
:处理纯文本- 使用
split('')
将文本字符串拆分成单个字符 - 对每个字符加上
<span class="${spanClass}">
,将每个字符包裹在<span>
标签中 spanClass
变量代表要添加的样式类
- 使用
- 最后用
.join('')
将map
返回的结果拼接成一个完整的字符串
- 使用正则表达式找到所有的
-
根据
isNew
的值决定内容的追加方式- 使用
lyricDiv.html()
获取lyricDiv
元素的当前 HTML 内容- 如果为
true
,将新内容chars
追加到已有内容后 - 如果为
false
,直接用chars
覆盖原有内容
- 如果为
- 使用
-
动画效果处理
- 无论
isNew
的值,都给新字符添加animate-me
类(每次有新字符添加到lyricDiv
时,应用动画) - 动画应用在所有具有
animate-me
类的元素上,包括清空后添加的新内容和追加的内容,动画完成后移除animate-me
类
- 无论