@@ -50,6 +50,61 @@ function createElement(tag, styles = {}, textContent = "") {
5050 return element ;
5151}
5252
53+ function isDarkYouTubeTheme ( ) {
54+ const root = document . documentElement ;
55+ const app = document . querySelector ( "ytd-app" ) ;
56+ const colorScheme = window . getComputedStyle ( root ) . colorScheme || "" ;
57+
58+ return (
59+ root . hasAttribute ( "dark" ) ||
60+ Boolean ( app ?. hasAttribute ( "dark" ) ) ||
61+ colorScheme . includes ( "dark" ) ||
62+ ( window . matchMedia ?. ( "(prefers-color-scheme: dark)" ) . matches ?? false )
63+ ) ;
64+ }
65+
66+ function getOverlayTheme ( ) {
67+ if ( isDarkYouTubeTheme ( ) ) {
68+ return {
69+ buttonBackground : "rgba(255, 255, 255, 0.1)" ,
70+ buttonHoverBackground : "rgba(255, 255, 255, 0.16)" ,
71+ buttonBorder : "1px solid rgba(255, 255, 255, 0.14)" ,
72+ buttonColor : "#f8fafc" ,
73+ cardBackground : "#18181b" ,
74+ cardBorder : "1px solid rgba(255, 255, 255, 0.08)" ,
75+ cardShadow : "0 20px 48px rgba(0, 0, 0, 0.52)" ,
76+ titleColor : "#f3f4f6" ,
77+ sectionTitleColor : "#a1a1aa" ,
78+ dividerColor : "#27272a" ,
79+ rowTextColor : "#f3f4f6" ,
80+ rowSubtextColor : "#a1a1aa" ,
81+ rowHoverBackground : "rgba(255, 255, 255, 0.06)" ,
82+ rowDefaultAccent : "#f3f4f6" ,
83+ rowSubtitlesAccent : "#60a5fa" ,
84+ radioBorderColor : "#d4d4d8" ,
85+ } ;
86+ }
87+
88+ return {
89+ buttonBackground : "rgba(15, 15, 15, 0.08)" ,
90+ buttonHoverBackground : "rgba(15, 15, 15, 0.14)" ,
91+ buttonBorder : "1px solid rgba(15, 23, 42, 0.08)" ,
92+ buttonColor : "#0f0f0f" ,
93+ cardBackground : "#ffffff" ,
94+ cardBorder : "1px solid rgba(148, 163, 184, 0.25)" ,
95+ cardShadow : "0 20px 48px rgba(15, 23, 42, 0.24)" ,
96+ titleColor : "#111827" ,
97+ sectionTitleColor : "#94a3b8" ,
98+ dividerColor : "#e5e7eb" ,
99+ rowTextColor : "#111827" ,
100+ rowSubtextColor : "#64748b" ,
101+ rowHoverBackground : "rgba(239, 246, 255, 0.98)" ,
102+ rowDefaultAccent : "#111827" ,
103+ rowSubtitlesAccent : "#2563eb" ,
104+ radioBorderColor : "#0f172a" ,
105+ } ;
106+ }
107+
53108function createToastHost ( ) {
54109 let host = document . getElementById ( "dlpgui-toast-host" ) ;
55110 if ( host ) {
@@ -221,6 +276,7 @@ function positionCard(card, anchorButton) {
221276}
222277
223278function buildChoiceRow ( meta , button , choice , source ) {
279+ const theme = getOverlayTheme ( ) ;
224280 const row = createElement ( "button" , {
225281 width : "100%" ,
226282 display : "flex" ,
@@ -231,7 +287,7 @@ function buildChoiceRow(meta, button, choice, source) {
231287 border : "0" ,
232288 borderLeft : "3px solid transparent" ,
233289 background : "transparent" ,
234- color : "#111827" ,
290+ color : theme . rowTextColor ,
235291 textAlign : "left" ,
236292 cursor : "pointer" ,
237293 transform : "translateX(0)" ,
@@ -247,7 +303,11 @@ function buildChoiceRow(meta, button, choice, source) {
247303 titleWrap . appendChild ( createElement ( "span" , { fontSize : "13px" , fontWeight : "500" } , choice . label ) ) ;
248304 if ( choice . subtitles ) {
249305 titleWrap . appendChild (
250- createElement ( "span" , { fontSize : "11px" , color : "#64748b" , marginTop : "2px" } , "With embedded subtitles" ) ,
306+ createElement (
307+ "span" ,
308+ { fontSize : "11px" , color : theme . rowSubtextColor , marginTop : "2px" } ,
309+ "With embedded subtitles" ,
310+ ) ,
251311 ) ;
252312 }
253313
@@ -261,7 +321,7 @@ function buildChoiceRow(meta, button, choice, source) {
261321 width : "14px" ,
262322 height : "14px" ,
263323 borderRadius : "999px" ,
264- border : " 1.5px solid #0f172a" ,
324+ border : ` 1.5px solid ${ theme . radioBorderColor } ` ,
265325 display : "inline-flex" ,
266326 alignItems : "center" ,
267327 justifyContent : "center" ,
@@ -272,7 +332,7 @@ function buildChoiceRow(meta, button, choice, source) {
272332 width : "6px" ,
273333 height : "6px" ,
274334 borderRadius : "999px" ,
275- background : choice . subtitles ? "#2563eb" : "#111827" ,
335+ background : choice . subtitles ? theme . rowSubtitlesAccent : theme . rowDefaultAccent ,
276336 } ) ,
277337 ) ;
278338 left . appendChild ( radio ) ;
@@ -283,7 +343,7 @@ function buildChoiceRow(meta, button, choice, source) {
283343 {
284344 fontSize : "11px" ,
285345 fontWeight : "600" ,
286- color : "#64748b" ,
346+ color : theme . rowSubtextColor ,
287347 flex : "0 0 auto" ,
288348 transition : "color 120ms ease" ,
289349 } ,
@@ -294,16 +354,20 @@ function buildChoiceRow(meta, button, choice, source) {
294354 row . appendChild ( note ) ;
295355
296356 row . addEventListener ( "mouseenter" , ( ) => {
297- row . style . background = "rgba(239, 246, 255, 0.98)" ;
298- row . style . borderLeftColor = choice . subtitles ? "#2563eb" : "#111827" ;
357+ row . style . background = theme . rowHoverBackground ;
358+ row . style . borderLeftColor = choice . subtitles
359+ ? theme . rowSubtitlesAccent
360+ : theme . rowDefaultAccent ;
299361 row . style . transform = "translateX(2px)" ;
300- note . style . color = choice . subtitles ? "#2563eb" : "#111827" ;
362+ note . style . color = choice . subtitles
363+ ? theme . rowSubtitlesAccent
364+ : theme . rowDefaultAccent ;
301365 } ) ;
302366 row . addEventListener ( "mouseleave" , ( ) => {
303367 row . style . background = "transparent" ;
304368 row . style . borderLeftColor = "transparent" ;
305369 row . style . transform = "translateX(0)" ;
306- note . style . color = "#64748b" ;
370+ note . style . color = theme . rowSubtextColor ;
307371 } ) ;
308372 row . addEventListener ( "click" , ( event ) => {
309373 event . preventDefault ( ) ;
@@ -316,6 +380,7 @@ function buildChoiceRow(meta, button, choice, source) {
316380}
317381
318382function buildSection ( meta , button , titleText , withSubtitles , source ) {
383+ const theme = getOverlayTheme ( ) ;
319384 const section = document . createElement ( "div" ) ;
320385 section . appendChild (
321386 createElement (
@@ -326,7 +391,7 @@ function buildSection(meta, button, titleText, withSubtitles, source) {
326391 fontWeight : "700" ,
327392 letterSpacing : "0.08em" ,
328393 textTransform : "uppercase" ,
329- color : "#94a3b8" ,
394+ color : theme . sectionTitleColor ,
330395 } ,
331396 titleText ,
332397 ) ,
@@ -345,16 +410,17 @@ function buildSection(meta, button, titleText, withSubtitles, source) {
345410}
346411
347412function openQualityPicker ( meta , anchorButton , source ) {
413+ const theme = getOverlayTheme ( ) ;
348414 closeActivePicker ( ) ;
349415
350416 const card = createElement ( "div" , {
351417 position : "fixed" ,
352418 zIndex : "999998" ,
353419 width : "272px" ,
354- background : "#ffffff" ,
355- border : "1px solid rgba(148, 163, 184, 0.25)" ,
420+ background : theme . cardBackground ,
421+ border : theme . cardBorder ,
356422 borderRadius : "14px" ,
357- boxShadow : "0 20px 48px rgba(15, 23, 42, 0.24)" ,
423+ boxShadow : theme . cardShadow ,
358424 overflow : "hidden" ,
359425 fontFamily : "Roboto, Arial, sans-serif" ,
360426 } ) ;
@@ -367,7 +433,7 @@ function openQualityPicker(meta, anchorButton, source) {
367433 padding : "14px 16px 10px" ,
368434 fontSize : "15px" ,
369435 fontWeight : "500" ,
370- color : "#111827" ,
436+ color : theme . titleColor ,
371437 } ,
372438 "Download Quality" ,
373439 ) ,
@@ -376,7 +442,7 @@ function openQualityPicker(meta, anchorButton, source) {
376442
377443 const divider = createElement ( "div" , {
378444 height : "1px" ,
379- background : "#e5e7eb" ,
445+ background : theme . dividerColor ,
380446 margin : "4px 14px" ,
381447 } ) ;
382448 card . appendChild ( divider ) ;
@@ -422,6 +488,7 @@ function openQualityPicker(meta, anchorButton, source) {
422488}
423489
424490function createWatchReplacementButton ( watchRoot , nativeTarget = null ) {
491+ const theme = getOverlayTheme ( ) ;
425492 const defaultLabel =
426493 normalizeLabel ( nativeTarget ?. textContent || "" ) ||
427494 normalizeLabel ( nativeTarget ?. getAttribute ?. ( "aria-label" ) || "" ) ||
@@ -434,10 +501,10 @@ function createWatchReplacementButton(watchRoot, nativeTarget = null) {
434501 flex : "0 0 auto" ,
435502 height : "36px" ,
436503 padding : "0 16px" ,
437- border : "0" ,
504+ border : theme . buttonBorder ,
438505 borderRadius : "18px" ,
439- background : "rgba(15, 15, 15, 0.08)" ,
440- color : "#0f0f0f" ,
506+ background : theme . buttonBackground ,
507+ color : theme . buttonColor ,
441508 font : "500 14px Roboto, Arial, sans-serif" ,
442509 whiteSpace : "nowrap" ,
443510 cursor : "pointer" ,
@@ -449,10 +516,10 @@ function createWatchReplacementButton(watchRoot, nativeTarget = null) {
449516 button . title = "Choose quality and send this video to dlp-gui" ;
450517
451518 button . addEventListener ( "mouseenter" , ( ) => {
452- button . style . background = "rgba(15, 15, 15, 0.14)" ;
519+ button . style . background = getOverlayTheme ( ) . buttonHoverBackground ;
453520 } ) ;
454521 button . addEventListener ( "mouseleave" , ( ) => {
455- button . style . background = "rgba(15, 15, 15, 0.08)" ;
522+ button . style . background = getOverlayTheme ( ) . buttonBackground ;
456523 } ) ;
457524 button . addEventListener ( "click" , ( event ) => {
458525 event . preventDefault ( ) ;
@@ -475,7 +542,16 @@ function createWatchReplacementButton(watchRoot, nativeTarget = null) {
475542
476543function injectWatchButton ( ) {
477544 const watchRoot = document . querySelector ( "ytd-watch-metadata" ) ;
478- if ( ! watchRoot || watchRoot . querySelector ( WATCH_BUTTON_SELECTOR ) ) {
545+ if ( ! watchRoot ) {
546+ return ;
547+ }
548+
549+ const existingButton = watchRoot . querySelector ( WATCH_BUTTON_SELECTOR ) ;
550+ if ( existingButton instanceof HTMLButtonElement ) {
551+ const theme = getOverlayTheme ( ) ;
552+ existingButton . style . background = theme . buttonBackground ;
553+ existingButton . style . border = theme . buttonBorder ;
554+ existingButton . style . color = theme . buttonColor ;
479555 return ;
480556 }
481557
0 commit comments