Skip to content

Commit 44ea156

Browse files
committed
updates for new scrollbar spec
1 parent e8f91ba commit 44ea156

File tree

1 file changed

+44
-30
lines changed

1 file changed

+44
-30
lines changed

Chromium (.crx)/includes/modern_scroll.js

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ function add_or_remove_ms(){
219219
else add_ms();
220220
}
221221

222-
function get_page_scrollbar_style()
222+
function get_colors_from_page() {
223+
return get_colors_from_page_scrollbar() || get_colors_from_page_themecolor();
224+
}
225+
function get_colors_from_page_scrollbar()
223226
{
224227
const pageColorValue = getComputedStyle(document.body).scrollbarColor;
225228
if (!pageColorValue || pageColorValue === "auto") return "";
@@ -231,25 +234,25 @@ function get_page_scrollbar_style()
231234
}
232235
if (pageColors.length !== 2) return "";
233236

234-
return ":host .pagetheme {\n\
235-
--color: "+ pageColors[0] +";\n\
236-
--color_bg: "+ pageColors[1] +";\n\
237-
--border_color: "+ pageColors[0] +";\n\
238-
--bookmark_text_color: "+ pageColors[1] +";\n\
239-
}\n";
237+
return "--color: "+ pageColors[0] +";\n\
238+
--color_bg: "+ pageColors[1] +";\n\
239+
--border_color: "+ pageColors[0] +";\n\
240+
--bookmark_text_color: "+ pageColors[1] +";\n";
240241
}
241-
function get_themecolor_style()
242+
function get_colors_from_page_themecolor()
242243
{
243244
const themecolor = document.querySelector("meta[name='theme-color']");
244245
if (!themecolor) return "";
245246

246-
return ":host .pagetheme {\n\
247-
--color: "+themecolor.content+";\n\
248-
--color_bg: "+ themecolor.content +";\n\
249-
--border_color: "+ (is_white(themecolor.content) ? "rgb(0,0,0)" : w.border_color_rgba) +";\n\
250-
--bookmark_text_color: "+ (is_white(themecolor.content) ? "rgb(0,0,0)" : w.bookmark_text_color) +";\n\
251-
}\n";
247+
return "--color: "+themecolor.content+";\n\
248+
--color_bg: "+ themecolor.content +";\n\
249+
--border_color: "+ (is_white(themecolor.content) ? "rgb(0,0,0)" : w.border_color_rgba) +";\n\
250+
--bookmark_text_color: "+ (is_white(themecolor.content) ? "rgb(0,0,0)" : w.bookmark_text_color) +";\n";
251+
}
252+
function get_internal_style(css_colors) {
253+
return css_colors ? ":host .pagetheme {\n"+css_colors+"}\n" : "";
252254
}
255+
253256
function is_white(color)
254257
{
255258
const c = color.toLowerCase().replaceAll(" ", "");
@@ -265,7 +268,7 @@ function inject_css()
265268
--border_color: "+ w.border_color_rgba +";\n\
266269
--bookmark_text_color: "+ w.bookmark_text_color +";\n\
267270
}\n\
268-
"+(get_page_scrollbar_style() || get_themecolor_style())+"\
271+
"+get_internal_style(get_colors_from_page())+"\
269272
:host, #ms_v_container, #ms_h_container, #ms_vbar_bg, #ms_hbar_bg, #ms_vbar, #ms_hbar, #ms_superbar, #ms_page_cover, #ms_upbutton, #ms_downbutton, #ms_middleclick_cursor{ position:fixed; z-index:2147483647; border:none; padding:0; margin:0; display:none; background:none; }\n\n"+
270273

271274
/* set values (most general first - can be overwritten by following rules): */
@@ -366,21 +369,32 @@ function inject_css()
366369
let global_ms_style = "#modern_scroll { all: initial !important; }\n\n";
367370

368371
/* hide page's default scroll bars: */
369-
if(w.fullscreen_only === "0") global_ms_style += "html, body { scrollbar-width: none !important; scroll-behavior: auto !important; }\n\
370-
html::-webkit-scrollbar, body::-webkit-scrollbar{ display:none !important; width:0 !important; height:0 !important; }\n";
371-
372-
if(w.style_element_bars === "1"){ global_ms_style +=
373-
(w.autohide_element_bars === "1" ? "body *:not(:hover):not(:focus)::-webkit-scrollbar{ display:none !important; width:0 !important; height:0 !important; }\n" : "")+
374-
"body *::-webkit-scrollbar{ width:"+w.size+"px; height:"+w.size+"px; }\n\
375-
body *::-webkit-scrollbar-button{ display:none; }\n\
376-
body *::-webkit-scrollbar-track { background:none; box-shadow:inset 0 0 "+w.border_blur+"px "+w.border_width+"px var(--border_color) !important; border-radius:"+w.border_radius+"px; }\n\
377-
body *::-webkit-scrollbar-thumb { background:var(--color, "+w.color+"); box-shadow:inset 0 0 "+w.border_blur+"px "+w.border_width+"px var(--border_color) !important; border-radius:"+w.border_radius+"px; }\n\
378-
body *::-webkit-scrollbar-thumb:hover { background:var(--color, "+w.color+"); }";
379-
380-
const themecolor = get_page_scrollbar_style() || get_themecolor_style();
381-
if (themecolor) {
382-
global_ms_style += "\n"+themecolor+"\n";
383-
}
372+
if(w.fullscreen_only === "0") global_ms_style += "html, body { scroll-behavior: auto !important; }\n" +
373+
(CSS.supports("scrollbar-width: none") ?
374+
"html, body { scrollbar-width: none !important; }\n" :
375+
"html::-webkit-scrollbar, body::-webkit-scrollbar{ display:none !important; width:0 !important; height:0 !important; }\n");
376+
377+
if(w.style_element_bars === "1"){
378+
if(w.auto_coloring === "1"){
379+
const page_colors = get_colors_from_page();
380+
if (page_colors) {
381+
global_ms_style += "body {\n" + page_colors + "}\n";
382+
}
383+
}
384+
385+
global_ms_style += CSS.supports("scrollbar-color: auto") ?
386+
(w.autohide_element_bars === "1" ? "body *:not(:hover):not(:focus-within) { scrollbar-color: transparent transparent !important; }\n" : "")+
387+
"body *{ scrollbar-color: var(--color, "+w.color+") var(--color_bg, "+w.color_bg+") !important; }\n\
388+
body *::-webkit-scrollbar-button{ display:none; }\n\
389+
body *::-webkit-scrollbar-track { background:none; box-shadow:inset 0 0 "+w.border_blur+"px "+w.border_width+"px var(--border_color) !important; border-radius:"+w.border_radius+"px; }\n\
390+
body *::-webkit-scrollbar-thumb { background:var(--color, "+w.color+"); box-shadow:inset 0 0 "+w.border_blur+"px "+w.border_width+"px var(--border_color) !important; border-radius:"+w.border_radius+"px; }\n\
391+
body *::-webkit-scrollbar-thumb:hover { background:var(--color, "+w.color+"); }" :
392+
(w.autohide_element_bars === "1" ? "body *:not(:hover):not(:focus-within)::-webkit-scrollbar{ display:none !important; width:0 !important; height:0 !important; }\n" : "")+
393+
"body *::-webkit-scrollbar{ width:"+w.size+"px; height:"+w.size+"px; }\n\
394+
body *::-webkit-scrollbar-button{ display:none; }\n\
395+
body *::-webkit-scrollbar-track { background:none; box-shadow:inset 0 0 "+w.border_blur+"px "+w.border_width+"px var(--border_color) !important; border-radius:"+w.border_radius+"px; }\n\
396+
body *::-webkit-scrollbar-thumb { background:var(--color, "+w.color+"); box-shadow:inset 0 0 "+w.border_blur+"px "+w.border_width+"px var(--border_color) !important; border-radius:"+w.border_radius+"px; }\n\
397+
body *::-webkit-scrollbar-thumb:hover { background:var(--color, "+w.color+"); }";
384398
}
385399

386400
if(document.getElementById("ms_style")){ // switched tabs -> update style (settings may have changed)

0 commit comments

Comments
 (0)