Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Positioning of Control Header on Google Desktop #478

Merged
merged 8 commits into from
Jun 6, 2024
89 changes: 63 additions & 26 deletions src/scripts/search-engines/google-desktop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type CSSAttribute, css } from "../styles.ts";
import type { SerpHandler } from "../types.ts";
import {
type ControlHandler,
type EntryHandler,
handleSerp,
hasDarkBackground,
Expand Down Expand Up @@ -100,6 +101,64 @@ const regularEntryHandler: Pick<
},
};

const regularControlHandlers: ControlHandler[] = [
{
target: "#result-stats",
style: {
// Displays on the next line when part of the "Tools" bar
"#hdtbMenus :is(.BfdGL.ZkEmPc + div) &": {
display: "block",
},
"&:not(#hdtbMenus &)": {
paddingLeft: "8px",
},
},
},
{
target: "#slim_appbar:empty",
style: (controlRoot) => {
controlRoot.className = css({
"#slim_appbar > &:not(:only-child)": {
display: "none",
},
});
// Set appropriate margin when "Tools" bar is present:
controlRoot.closest("#appbar")?.classList.add(
css({
// Not present
"&:not(.hdtb-ab-o)": {
margin: "16px 0",
},
// Present
"&:is(.hdtb-ab-o)": {
margin: "42px 0 -12px",
},
// Remove margin when no entry has been blocked
"&:has(.ub-hidden)": {
margin: "0 !important",
},
}),
);
// Set appropriate margin when there is an additional labels bar
if (controlRoot.matches(":is(:is(div + #tU52Vb) :scope)")) {
controlRoot.closest("#appbar")?.classList.add(
css({
margin: "0 0 24px 0 !important",
}),
);
controlRoot.closest("#slim_appbar")?.classList.add(
css({
".hdtb-ab-o &": {
padding: "48px 0 0 0",
},
padding: "24px 0 0 0",
}),
);
}
},
},
];

const desktopSerpHandlers: Record<string, SerpHandler> = {
// All
"": handleSerp({
Expand All @@ -124,17 +183,7 @@ const desktopSerpHandlers: Record<string, SerpHandler> = {
},
},
controlHandlers: [
{
target: "#result-stats",
},
{
target: "#slim_appbar:empty",
style: {
"#slim_appbar > &:not(:only-child)": {
display: "none",
},
},
},
...regularControlHandlers,
{
target: "#botabar",
position: "afterend",
Expand Down Expand Up @@ -502,11 +551,7 @@ const desktopSerpHandlers: Record<string, SerpHandler> = {
// Books
bks: handleSerp({
globalStyle: desktopGlobalStyle,
controlHandlers: [
{
target: "#result-stats",
},
],
controlHandlers: [...regularControlHandlers],
entryHandlers: [
{
target: ".Yr5TG",
Expand Down Expand Up @@ -585,11 +630,7 @@ const desktopSerpHandlers: Record<string, SerpHandler> = {
whiteSpace: "nowrap",
},
},
controlHandlers: [
{
target: "#result-stats",
},
],
controlHandlers: [...regularControlHandlers],
entryHandlers: [
// Regular
{
Expand Down Expand Up @@ -638,11 +679,7 @@ const desktopSerpHandlers: Record<string, SerpHandler> = {
// Videos
vid: handleSerp({
globalStyle: desktopGlobalStyle,
controlHandlers: [
{
target: "#result-stats",
},
],
controlHandlers: [...regularControlHandlers],
entryHandlers: [
{
target: ".g, .iHxmLe",
Expand Down