Skip to content

Commit

Permalink
fix(google): fix positioning of control header on Google desktop (#478)
Browse files Browse the repository at this point in the history
* Fix spacing issue on #slim_appbar control (Google Desktop)

* Fix control overlap on Google Desktop

* Remove margin from control when there is no blocked entries

* Fix small issue with spacing

* Remove unnecessary code repetition on Control Handlers (Google Desktop)

* Fix rule using :not() selector

* Fix controls when there is an additional label bar

* Remove additional :scope pseudo-class
  • Loading branch information
aug-dev committed Jun 6, 2024
1 parent b6273ad commit 7b03799
Showing 1 changed file with 63 additions and 26 deletions.
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 @@ -548,11 +597,7 @@ const desktopSerpHandlers: Record<string, SerpHandler> = {
// Books
bks: handleSerp({
globalStyle: desktopGlobalStyle,
controlHandlers: [
{
target: "#result-stats",
},
],
controlHandlers: [...regularControlHandlers],
entryHandlers: [
{
target: ".Yr5TG",
Expand Down Expand Up @@ -631,11 +676,7 @@ const desktopSerpHandlers: Record<string, SerpHandler> = {
whiteSpace: "nowrap",
},
},
controlHandlers: [
{
target: "#result-stats",
},
],
controlHandlers: [...regularControlHandlers],
entryHandlers: [
// Regular
{
Expand Down Expand Up @@ -684,11 +725,7 @@ const desktopSerpHandlers: Record<string, SerpHandler> = {
// Videos
vid: handleSerp({
globalStyle: desktopGlobalStyle,
controlHandlers: [
{
target: "#result-stats",
},
],
controlHandlers: [...regularControlHandlers],
entryHandlers: [
{
target: ".g, .iHxmLe",
Expand Down

0 comments on commit 7b03799

Please sign in to comment.