@@ -10,41 +10,32 @@ const COLOR_KEY = '--ytmusic-album-color';
1010const DARK_COLOR_KEY = '--ytmusic-album-color-dark' ;
1111const RATIO_KEY = '--ytmusic-album-color-ratio' ;
1212
13- export default createPlugin <
14- unknown ,
15- unknown ,
16- {
17- color ?: ColorInstance ;
18- darkColor ?: ColorInstance ;
19-
20- playerPage : HTMLElement | null ;
21- navBarBackground : HTMLElement | null ;
22- ytmusicPlayerBar : HTMLElement | null ;
23- playerBarBackground : HTMLElement | null ;
24- sidebarBig : HTMLElement | null ;
25- sidebarSmall : HTMLElement | null ;
26- ytmusicAppLayout : HTMLElement | null ;
27-
28- getMixedColor (
29- color : string ,
30- key : string ,
31- alpha ?: number ,
32- ratioMultiply ?: number ,
33- ) : string ;
34- updateColor ( alpha : number ) : void ;
35- } ,
36- {
37- enabled : boolean ;
38- ratio : number ;
39- }
40- > ( {
13+ type Config = {
14+ enabled : boolean ;
15+ ratio : number ;
16+ enableSeekbar : boolean ;
17+ } ;
18+
19+ type Renderer = {
20+ getMixedColor (
21+ color : string ,
22+ key : string ,
23+ alpha ?: number ,
24+ ratioMultiply ?: number ,
25+ ) : string ;
26+ updateColor ( alpha : number ) : void ;
27+ onConfigChange ( newConfig : Config ) : void ;
28+ } ;
29+
30+ export default createPlugin ( {
4131 name : ( ) => t ( 'plugins.album-color-theme.name' ) ,
4232 description : ( ) => t ( 'plugins.album-color-theme.description' ) ,
4333 restartNeeded : false ,
4434 config : {
4535 enabled : false ,
4636 ratio : 0.5 ,
47- } ,
37+ enableSeekbar : true ,
38+ } satisfies Config as Config ,
4839 stylesheets : [ style ] ,
4940 menu : async ( { getConfig, setConfig } ) => {
5041 const ratioList = [ 0 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.6 , 0.7 , 0.8 , 0.9 , 1 ] ;
@@ -68,18 +59,28 @@ export default createPlugin<
6859 } ,
6960 } ) ) ,
7061 } ,
62+ {
63+ label : t ( 'plugins.album-color-theme.menu.enable-seekbar' ) ,
64+ type : 'checkbox' ,
65+ checked : config . enableSeekbar ,
66+ click ( item ) {
67+ setConfig ( { enableSeekbar : item . checked } ) ;
68+ } ,
69+ } ,
7170 ] ;
7271 } ,
7372 renderer : {
74- playerPage : null ,
75- navBarBackground : null ,
76- ytmusicPlayerBar : null ,
77- playerBarBackground : null ,
78- sidebarBig : null ,
79- sidebarSmall : null ,
80- ytmusicAppLayout : null ,
81-
82- async start ( { getConfig } ) {
73+ playerPage : null as HTMLElement | null ,
74+ navBarBackground : null as HTMLElement | null ,
75+ ytmusicPlayerBar : null as HTMLElement | null ,
76+ playerBarBackground : null as HTMLElement | null ,
77+ sidebarBig : null as HTMLElement | null ,
78+ sidebarSmall : null as HTMLElement | null ,
79+ ytmusicAppLayout : null as HTMLElement | null ,
80+ color : null as ColorInstance | null ,
81+ darkColor : null as ColorInstance | null ,
82+
83+ start ( ) {
8384 this . playerPage = document . querySelector < HTMLElement > ( '#player-page' ) ;
8485 this . navBarBackground = document . querySelector < HTMLElement > (
8586 '#nav-bar-background' ,
@@ -94,14 +95,11 @@ export default createPlugin<
9495 '#mini-guide-background' ,
9596 ) ;
9697 this . ytmusicAppLayout = document . querySelector < HTMLElement > ( '#layout' ) ;
97-
98- const config = await getConfig ( ) ;
99- document . documentElement . style . setProperty (
100- RATIO_KEY ,
101- `${ ~ ~ ( config . ratio * 100 ) } %` ,
102- ) ;
10398 } ,
104- onPlayerApiReady ( playerApi ) {
99+ async onPlayerApiReady ( playerApi , { getConfig } ) {
100+ const config = await getConfig ( ) ;
101+ ( this as Renderer ) . onConfigChange ( config ) ;
102+
105103 const fastAverageColor = new FastAverageColor ( ) ;
106104
107105 document . addEventListener ( 'videodatachange' , async ( event ) => {
@@ -152,16 +150,23 @@ export default createPlugin<
152150 alpha = value ;
153151 }
154152 }
155- this . updateColor ( alpha ?? 1 ) ;
153+ ( this as Renderer ) . updateColor ( alpha ?? 1 ) ;
156154 } ) ;
157155 } ,
158156 onConfigChange ( config ) {
159157 document . documentElement . style . setProperty (
160158 RATIO_KEY ,
161159 `${ ~ ~ ( config . ratio * 100 ) } %` ,
162160 ) ;
161+ if ( config . enableSeekbar ) document . body . classList . add ( 'seekbar-theme' ) ;
162+ else document . body . classList . remove ( 'seekbar-theme' ) ;
163163 } ,
164- getMixedColor ( color : string , key : string , alpha = 1 , ratioMultiply ) {
164+ getMixedColor (
165+ color : string ,
166+ key : string ,
167+ alpha = 1 ,
168+ ratioMultiply ?: number ,
169+ ) {
165170 const keyColor = `rgba(var(${ key } ), ${ alpha } )` ;
166171
167172 let colorRatio = `var(${ RATIO_KEY } , 50%)` ;
@@ -207,26 +212,39 @@ export default createPlugin<
207212 '--yt-spec-black-pure-alpha-80' : 'rgba(0,0,0,0.8)' ,
208213 '--yt-spec-black-1-alpha-98' : 'rgba(40,40,40,0.98)' ,
209214 '--yt-spec-black-1-alpha-95' : 'rgba(40,40,40,0.95)' ,
215+ '--paper-toast-background-color' : '#323232' ,
216+ '--ytmusic-search-background' : '#030303' ,
217+ '--paper-slider-knob-color' : '#f03' ,
218+ '--paper-dialog-background-color' : '#212121' ,
219+ '--paper-progress-active-color-1' : '#f03' ,
220+ '--paper-progress-active-color-2' : '#ff2791' ,
221+ '--yt-spec-inverted-background' : '#f3f3f3' ,
222+ 'background' : 'rgba(3, 3, 3)' ,
223+ '--ytmusic-background' : 'rgba(3, 3, 3)' ,
224+ } ;
225+
226+ const colorKeyMap : Record < string , string > = {
227+ 'background' : DARK_COLOR_KEY ,
228+ '--ytmusic-background' : DARK_COLOR_KEY ,
210229 } ;
230+
231+ const ratioMap : Record < string , number > = {
232+ '--paper-progress-active-color-1' : 1.75 ,
233+ '--paper-progress-active-color-2' : 1.75 ,
234+ '--yt-spec-inverted-background' : 1.75 ,
235+ } ;
236+
237+ const getMixedColor = ( this as Renderer ) . getMixedColor . bind ( this ) ;
211238 Object . entries ( variableMap ) . map ( ( [ variable , color ] ) => {
239+ const key = colorKeyMap [ variable ] ?? COLOR_KEY ;
240+ const ratio = ratioMap [ variable ] ?? undefined ;
241+
212242 document . documentElement . style . setProperty (
213243 variable ,
214- this . getMixedColor ( color , COLOR_KEY , alpha ) ,
244+ getMixedColor ( color , key , alpha , ratio ) ,
215245 'important' ,
216246 ) ;
217247 } ) ;
218-
219- document . body . style . setProperty (
220- 'background' ,
221- this . getMixedColor ( 'rgba(3, 3, 3)' , DARK_COLOR_KEY , alpha ) ,
222- 'important' ,
223- ) ;
224- document . documentElement . style . setProperty (
225- '--ytmusic-background' ,
226- // #030303
227- this . getMixedColor ( 'rgba(3, 3, 3)' , DARK_COLOR_KEY , alpha ) ,
228- 'important' ,
229- ) ;
230248 } ,
231249 } ,
232250} ) ;
0 commit comments