1
- export default class Page {
2
- public get isOnSupportedPage ( ) {
3
- return this . videoKind !== null ;
1
+ export default class ChannelPage {
2
+ public static get isOnSupportedPage ( ) {
3
+ return ! ! this . videoKind ;
4
4
}
5
5
6
- public get videoKind ( ) : VideoKind {
6
+ public static get videoKind ( ) : VideoKindNullable {
7
7
const videoKind = window . location . pathname . split ( "/" ) . at ( - 1 ) ! . split ( "?" ) [ 0 ] ;
8
8
switch ( videoKind ) {
9
9
case "videos" :
@@ -17,7 +17,7 @@ export default class Page {
17
17
}
18
18
}
19
19
20
- public get sortKind ( ) : SortKind {
20
+ public static get sortKind ( ) : SortKindNullable {
21
21
const selectedButton = document . querySelector ( "#primary #header #chips>[selected]" ) ;
22
22
const index = selectedButton
23
23
? Array . from ( selectedButton . parentNode ?. children ?? [ ] ) . indexOf ( selectedButton )
@@ -34,63 +34,29 @@ export default class Page {
34
34
}
35
35
}
36
36
37
- public get hasPlayAllButton ( ) {
37
+ public static get hasPlayAllButton ( ) {
38
38
return ! ! document . querySelector ( ".play-all-btn" ) ;
39
39
}
40
40
41
41
public channelId : string ;
42
+
42
43
public constructor ( channelId : string ) {
43
44
this . channelId = channelId ;
44
45
}
45
46
46
- public static applyStyleForPlayAllButton ( ) {
47
- const style = document . createElement ( "style" ) ;
48
- style . textContent = `
49
- .play-all-btn {
50
- background-color: #8000FF;
51
- color: #F1F1F1;
52
-
53
- height: 32px;
54
- min-width: 12px;
55
-
56
- display: inline-flex;
57
- flex-direction: row;
58
- align-items: center;
59
- justify-content: center;
60
- margin-left: 12px;
61
-
62
- border-radius: 8px;
63
- padding: 0 12px;
64
-
65
- font-family: 'Roboto', 'Arial', sans-serif;
66
- font-size: 1.4rem;
67
- font-weight: 500;
68
- text-decoration: none;
69
-
70
- cursor: pointer;
71
- }
72
-
73
- .play-all-btn:hover,
74
- .play-all-btn:focus {
75
- background-color:#9B33FF;
76
- }
77
- ` ;
78
- document . head . appendChild ( style ) ;
79
- }
80
-
81
- public ensurePlayAllButton ( channelId : string ) {
82
- if ( ! this . hasPlayAllButton ) {
83
- this . addPlayAllButton ( channelId ) ;
47
+ public ensurePlayAllButton ( ) {
48
+ if ( ! ChannelPage . hasPlayAllButton ) {
49
+ this . addPlayAllButton ( ChannelPage . videoKind , ChannelPage . sortKind ) ;
84
50
}
85
51
}
86
52
87
- public addPlayAllButton ( channelId : string ) {
53
+ public addPlayAllButton ( videoKind : VideoKindNullable , sortKind : SortKindNullable ) {
88
54
const playAllButton = document . createElement ( "a" ) ;
89
- const playListPath = this . _getPlayListPath ( channelId ) ;
90
55
playAllButton . classList . add ( "play-all-btn" ) ;
91
- if ( playListPath ) {
56
+ if ( videoKind && sortKind ) {
57
+ const playListPath = this . _getPlayListPath ( videoKind , sortKind ) ;
92
58
playAllButton . href = playListPath ;
93
- playAllButton . textContent = `Play All (${ this . sortKind } )` ;
59
+ playAllButton . textContent = `Play All (${ sortKind } )` ;
94
60
} else {
95
61
playAllButton . textContent = `Play All (Not Available)` ;
96
62
}
@@ -99,17 +65,17 @@ export default class Page {
99
65
buttonHolder ?. appendChild ( playAllButton ) ;
100
66
}
101
67
102
- private _getPlayListPath ( channelId : string ) : string {
103
- if ( this . sortKind === "Oldest" ) {
68
+ private _getPlayListPath ( videoKind : VideoKind , sortKind : SortKind ) : string {
69
+ if ( sortKind === "Oldest" ) {
104
70
const oldestVideoHref = document . querySelector < HTMLLinkElement > (
105
71
"ytd-browse [href^='/watch?v='],ytd-browse [href^='/shorts/']" ,
106
72
) ?. href ;
107
73
const videoId = oldestVideoHref ?. match ( / (?: w a t c h \? v = | s h o r t s \/ ) ( [ ^ & ] * ) / ) ?. at ( 1 ) ;
108
74
return videoId ? `/watch?v=${ videoId } &list=UL01234567890` : "" ;
109
75
} else {
110
- if ( channelId && this . videoKind && this . sortKind ) {
111
- const playlistPrefix = this . _getPlayListPrefix ( this . videoKind , this . sortKind ) ;
112
- return `/playlist?list=${ playlistPrefix } ${ channelId } &playnext=1` ;
76
+ if ( videoKind && sortKind ) {
77
+ const playlistPrefix = this . _getPlayListPrefix ( videoKind , sortKind ) ;
78
+ return `/playlist?list=${ playlistPrefix } ${ this . channelId } &playnext=1` ;
113
79
} else {
114
80
return "" ;
115
81
}
@@ -136,5 +102,8 @@ export default class Page {
136
102
}
137
103
}
138
104
139
- type VideoKind = "Videos" | "Shorts" | "Streams" | null ;
140
- type SortKind = "Latest" | "Popular" | "Oldest" | null ;
105
+ type VideoKind = "Videos" | "Shorts" | "Streams" ;
106
+ type SortKind = "Latest" | "Popular" | "Oldest" ;
107
+
108
+ type VideoKindNullable = VideoKind | null ;
109
+ type SortKindNullable = SortKind | null ;
0 commit comments