Skip to content

Commit

Permalink
fix(google): update handler of image search
Browse files Browse the repository at this point in the history
fix #406
  • Loading branch information
iorate committed Feb 27, 2024
1 parent bc2106f commit 3fe8ac1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
31 changes: 28 additions & 3 deletions src/scripts/search-engines/google-desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,31 @@ const desktopSerpHandlers: Record<string, SerpHandler> = {
],
}),
// Images
'udm=2': handleSerp({
globalStyle: desktopGlobalStyle,
controlHandlers: [
{
target: '#appbar',
position: 'afterbegin',
style: {
display: 'block',
margin: '10px 0',
},
},
],
entryHandlers: [
{
target: '.ivg-i',
url: 'a[href]',
title: '.OSrXXb',
actionTarget: '',
actionStyle: {
display: 'block',
fontSize: '11px',
},
},
],
}),
isch: handleSerp({
globalStyle: desktopGlobalStyle,
controlHandlers: [
Expand Down Expand Up @@ -509,9 +534,9 @@ function updateDarkMode(): void {
}
}

export function getDesktopSerpHandler(tbm: string): SerpHandler | null {
const serpHandler = desktopSerpHandlers[tbm];
if (!desktopSerpHandlers[tbm]) {
export function getDesktopSerpHandler(tbm: string, udm: string): SerpHandler | null {
const serpHandler = desktopSerpHandlers[udm ? `udm=${udm}` : tbm];
if (!serpHandler) {
return null;
}
return {
Expand Down
6 changes: 4 additions & 2 deletions src/scripts/search-engines/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { getMobileSerpHandler } from './google-mobile';
export const google: Readonly<SearchEngine> = {
...SEARCH_ENGINES.google,
getSerpHandler() {
const tbm = new URL(window.location.href).searchParams.get('tbm') ?? '';
return mobile({ tablet: true }) ? getMobileSerpHandler(tbm) : getDesktopSerpHandler(tbm);
const params = new URL(window.location.href).searchParams;
const tbm = params.get('tbm') ?? '';
const udm = params.get('udm') ?? '';
return mobile({ tablet: true }) ? getMobileSerpHandler(tbm) : getDesktopSerpHandler(tbm, udm);
},
};

0 comments on commit 3fe8ac1

Please sign in to comment.