1
+ import { CommandName } from "../Core/Command" ;
2
+ import { Hostname } from "../Core/Hostname" ;
3
+ import { NativeVideo } from "../Core/NativeVideo" ;
4
+ import { PlayerContext } from "../Core/PlayerContext" ;
5
+ import { Video } from "../Core/Video" ;
6
+
7
+ export class NiVodPlayerContext implements PlayerContext {
8
+ name : string = "NiVod" ;
9
+
10
+ hosts : Hostname [ ] = [
11
+ { match : "www.nivod.tv" } ,
12
+ ] ;
13
+
14
+ allowedCommands : CommandName [ ] = [
15
+ "play" , "speed" , "skip" , "skip2x" , "skip4x" , "seek" , "mute" , "volume" , "episode" , "fullscreen" , "miniplayer" , "fullwebpage" , "danmu" ,
16
+ ] ;
17
+
18
+ video : Video = new NativeVideo ( [
19
+ { element : "#dplayer > div.dplayer-video-wrap > video" } ,
20
+ ] ) ;
21
+
22
+ getFullscreenButton ( ) : HTMLElement | null {
23
+ return this . video . $ ( ".dplayer-full-icon" ) ;
24
+ }
25
+
26
+ getFullwebpageButton ( ) : HTMLElement | null {
27
+ return this . video . $ ( ".dplayer-full-in-icon" ) ;
28
+ }
29
+
30
+ getMiniplayerButton ( ) : HTMLElement | null {
31
+ return this . video . $ ( "#pip > button" ) ;
32
+ }
33
+
34
+ getDanmuButton ( ) : HTMLElement | null {
35
+ return document . querySelector ( "#danmu-c > .func-danmu span:not([style]) img, #danmu-c > .func-danmu span[style=''] img" ) ;
36
+ }
37
+
38
+ getDanmuStatus ( elem : HTMLElement ) : boolean | null {
39
+ return ( < HTMLImageElement > elem ) . src . endsWith ( "open.png" ) ;
40
+ }
41
+
42
+ isEpisodeMenuItem ( elem : HTMLElement ) : boolean {
43
+ return elem . classList . contains ( "select-item" ) ;
44
+ }
45
+
46
+ reverseSpeedControl ( ) : boolean {
47
+ return true ;
48
+ }
49
+
50
+ getActiveSpeedMenuItem ( ) : HTMLElement | null {
51
+ let speed = parseFloat ( this . video . $ ( "#speed_icon > span" ) ?. textContent ?? "1" ) ;
52
+ if ( isNaN ( speed ) )
53
+ speed = 1 ;
54
+ return this . video . $ ( `#dplayer div.dplayer-setting-speed-panel > div[data-speed='${ speed } ']` ) ;
55
+ }
56
+
57
+ getSpeed ( elem : HTMLElement ) : number | null {
58
+ let speed = parseFloat ( elem . textContent ?? "1" ) ;
59
+ if ( isNaN ( speed ) )
60
+ speed = 1 ;
61
+ return speed ;
62
+ }
63
+
64
+ isEpisodeListPaged ( ) : boolean {
65
+ return true ;
66
+ }
67
+
68
+ getActiveEpisodeMenuItem ( ) : HTMLElement | null {
69
+ return document . querySelector ( "#play-list li.select-item.selected" ) ;
70
+ }
71
+
72
+ reverseEpisodeControl ( ) : boolean {
73
+ return this . video . $ ( "#play_info_group > ul > li:nth-child(1) > a" ) ?. textContent ?. trim ( ) == "顺序" ;
74
+ }
75
+ }
0 commit comments