File tree 1 file changed +20
-1
lines changed
1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 10
10
let end_timestamp: string = " " ;
11
11
let lyric: string = " " ;
12
12
13
+ function kanji_detect() {
14
+ // 4e00 to 9faf
15
+ const is_kanji = (char ) => char .charCodeAt (0 ) >= 19968 && char .charCodeAt (0 ) <= 40879 ;
16
+ let new_lyric: string = " " ;
17
+ let prev_was_kanji: boolean = false ;
18
+ for (const char of lyric .split (" " )) {
19
+ if (is_kanji (char )) {
20
+ if (! prev_was_kanji ) new_lyric += " [" ;
21
+ prev_was_kanji = true ;
22
+ } else {
23
+ if (prev_was_kanji ) new_lyric += " ]()" ;
24
+ prev_was_kanji = false ;
25
+ }
26
+ new_lyric += char ;
27
+ }
28
+ if (prev_was_kanji ) new_lyric += " ]()" ;
29
+ lyric = new_lyric ;
30
+ }
31
+
13
32
function add_lyric() {
14
- console .log (lyric )
15
33
start_timestamp = normalize_timestamp (start_timestamp );
16
34
end_timestamp = normalize_timestamp (end_timestamp );
17
35
if (lyric .length === 0 ) return ;
45
63
<input id ="lyric" type ="text" bind:value ={lyric } placeholder =" [今日](きょう)も[照](て)らし[続](つづ)けるよ" />
46
64
</div >
47
65
<button class ="default-button" on:click ={add_lyric }>Add Lyric</button >
66
+ <button class ="default-button" on:click ={kanji_detect }>Kanji Detect</button >
48
67
</div >
49
68
50
69
<style >
You can’t perform that action at this time.
0 commit comments