Skip to content

Commit 93c1e70

Browse files
committed
Add support for NiVod
1 parent a194698 commit 93c1e70

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

src/Contexts/NiVodPlayerContext.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
}

src/Core/PlayerContextManager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { YouTubePlayerContext } from "../Contexts/YouTubePlayerContext";
1414
import { HaokanPlayerContext } from "../Contexts/HaokanPlayerContext";
1515
import { SportsNetPlayerContext } from "../Contexts/SportsNetPlayerContext";
1616
import { AmazonVideoPlayerContext } from "../Contexts/AmazonVideoPlayerContext";
17+
import { NiVodPlayerContext } from "../Contexts/NiVodPlayerContext";
1718
import { Settings } from "../Settings";
1819
import { PlayerContext } from "./PlayerContext";
1920

@@ -36,6 +37,7 @@ export class PlayerContextManager {
3637
new HaokanPlayerContext(),
3738
new SportsNetPlayerContext(),
3839
new AmazonVideoPlayerContext(),
40+
new NiVodPlayerContext(),
3941
];
4042

4143
// Match a known player context

src/Main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ Log.context = "contentscript";
4646
// https://www.bilibili.com/bangumi/play/ep422437
4747
// https://www.bilibili.com/festival/2021bnj
4848
// https://www.bilibili.com/video/BV1BU4y1X71R
49-
49+
// https://www.nivod.tv/0Mxuuplo25wGoKuSV9uJ9wQRJZ6Oj1AQ-0-0-0-0-play.html
50+
// https://www.nivod.tv/oXAnCMr2ZMPt0zJQPLkvZ14RI3F70NWn-sngcjFxhC2YVLUhki9GYoCXJrnoy8DdW-1080-0-0-play.html
5051

5152
let onTopDocumentFoundCalled = false;
5253
let onInnerDocumentFoundCalled = false;

0 commit comments

Comments
 (0)