Skip to content

Commit 127f569

Browse files
Sunkist18최민우
andauthored
fix(album-color-theme): improve theming consistency across UI elements (#4109)
Co-authored-by: 최민우 <[email protected]>
1 parent 8d448c6 commit 127f569

File tree

4 files changed

+93
-62
lines changed

4 files changed

+93
-62
lines changed

src/i18n/resources/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@
237237
"submenu": {
238238
"percent": "{{ratio}}%"
239239
}
240-
}
240+
},
241+
"enable-seekbar": "Enable seekbar theming"
241242
},
242243
"name": "Album Color Theme"
243244
},

src/i18n/resources/ko.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@
237237
"submenu": {
238238
"percent": "{{ratio}}%"
239239
}
240-
}
240+
},
241+
"enable-seekbar": "재생바 색조 변경 활성화"
241242
},
242243
"name": "앨범 컬러 기반 테마"
243244
},

src/plugins/album-color-theme/index.ts

Lines changed: 78 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,32 @@ const COLOR_KEY = '--ytmusic-album-color';
1010
const DARK_COLOR_KEY = '--ytmusic-album-color-dark';
1111
const 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
});

src/plugins/album-color-theme/style.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,14 @@ ytmusic-browse-response[has-background]:not([disable-gradient]) .background-grad
8181
#background.immersive-background.style-scope.ytmusic-browse-response {
8282
opacity: 0.6;
8383
}
84+
85+
ytmusic-search-box[is-bauhaus-sidenav-enabled] {
86+
--ytmusic-search-background: var(--ytmusic-color-black3) !important;
87+
}
88+
89+
.seekbar-theme #progress-bar.ytmusic-player-bar {
90+
--paper-slider-active-color: linear-gradient(to right, var(--paper-progress-active-color-1) 80%, var(--paper-progress-active-color-2) 100%) !important;
91+
--paper-slider-knob-color: var(--paper-progress-active-color-1) !important;
92+
--paper-slider-knob-start-color: var(--paper-progress-active-color-2) !important;
93+
}
94+

0 commit comments

Comments
 (0)