@@ -21,40 +21,30 @@ function applyOpacity(opacity) {
2121 const bgColor = `rgba(0, 0, 0, ${ opacity } )` ;
2222 const buttonBgColor = opacity > 0.5 ? `rgba(0, 0, 0, ${ opacity * 0.3 } )` : '' ;
2323
24- // Main containers - combined selector for efficiency
24+ // Main containers - use setProperty to preserve layout styles
2525 const mainContainers = '.ytp-chrome-controls, .ytp-chrome-top, .ytp-chrome-bottom, .ytp-gradient-top, .ytp-gradient-bottom' ;
2626 playerContainer . querySelectorAll ( mainContainers ) . forEach ( el => {
27- el . style . cssText = `
28- background: ${ bgColor } !important;
29- background-color: ${ bgColor } !important;
30- background-image: none !important;
31- opacity: 1 !important;
32- ` ;
27+ el . style . setProperty ( 'background' , bgColor , 'important' ) ;
28+ el . style . setProperty ( 'background-color' , bgColor , 'important' ) ;
29+ el . style . setProperty ( 'background-image' , 'none' , 'important' ) ;
30+ el . style . setProperty ( 'opacity' , '1' , 'important' ) ;
3331 } ) ;
3432
35- // Secondary containers - combined selector
33+ // Secondary containers - use setProperty to preserve layout styles
3634 const secondaryContainers = '.ytp-left-controls, .ytp-right-controls, .ytp-time-display, .ytp-chapter-container, .ytp-volume-area, .ytp-volume-panel, .ytp-settings-menu, .ytp-popup, .ytp-panel, .ytp-panel-menu, .ytp-popup-content, .ytp-tooltip, .ytp-tooltip-bg' ;
3735 playerContainer . querySelectorAll ( secondaryContainers ) . forEach ( el => {
38- el . style . cssText = `
39- background: ${ bgColor } !important;
40- background-color: ${ bgColor } !important;
41- opacity: 1 !important;
42- ` ;
36+ el . style . setProperty ( 'background' , bgColor , 'important' ) ;
37+ el . style . setProperty ( 'background-color' , bgColor , 'important' ) ;
38+ el . style . setProperty ( 'opacity' , '1' , 'important' ) ;
4339 } ) ;
4440
45- // Buttons with optional background
46- if ( buttonBgColor ) {
47- playerContainer . querySelectorAll ( '.yt-spec-button-shape-next, .ytp-button' ) . forEach ( el => {
48- el . style . cssText = `
49- opacity: 1 !important;
50- background-color: ${ buttonBgColor } !important;
51- ` ;
52- } ) ;
53- } else {
54- playerContainer . querySelectorAll ( '.yt-spec-button-shape-next, .ytp-button' ) . forEach ( el => {
55- el . style . opacity = '1' ;
56- } ) ;
57- }
41+ // Buttons with optional background - use setProperty to preserve other styles
42+ playerContainer . querySelectorAll ( '.yt-spec-button-shape-next, .ytp-button' ) . forEach ( el => {
43+ el . style . setProperty ( 'opacity' , '1' , 'important' ) ;
44+ if ( buttonBgColor ) {
45+ el . style . setProperty ( 'background-color' , buttonBgColor , 'important' ) ;
46+ }
47+ } ) ;
5848
5949 // Text and icons - make opaque
6050 const opaqueElements = '.ytp-time-current, .ytp-time-duration, .ytp-chapter-title, .ytp-title, .ytp-menuitem, .yt-spec-button-shape-next__icon, .ytIconWrapperHost, .yt-spec-button-shape-next__button-text-content' ;
@@ -67,21 +57,22 @@ function applyOpacity(opacity) {
6757 el . style . opacity = '1' ;
6858 } ) ;
6959
70- // Progress bar z-index fix
60+ // Progress bar z-index fix - use setProperty to preserve existing styles
7161 const scrubberElements = '.ytp-scrubber-container, .ytp-scrubber-button, .ytp-play-progress' ;
7262 playerContainer . querySelectorAll ( scrubberElements ) . forEach ( el => {
73- el . style . cssText = `
74- z-index: 100 !important;
75- position: relative !important;
76- ` ;
63+ el . style . setProperty ( 'z-index' , '100' , 'important' ) ;
64+ // Only set position if not already positioned
65+ if ( ! el . style . position || el . style . position === 'static' ) {
66+ el . style . setProperty ( 'position' , 'relative' , 'important' ) ;
67+ }
7768 } ) ;
7869
7970 const progressBar = playerContainer . querySelector ( '.ytp-progress-bar' ) ;
8071 if ( progressBar ) {
81- progressBar . style . cssText = `
82- position: relative !important;
83- z-index: 50 ! important;
84- ` ;
72+ progressBar . style . setProperty ( 'z-index' , '50' , 'important' ) ;
73+ if ( ! progressBar . style . position || progressBar . style . position === 'static' ) {
74+ progressBar . style . setProperty ( 'position' , 'relative' , ' important' ) ;
75+ }
8576 }
8677}
8778
0 commit comments