Skip to content

Commit

Permalink
Merge pull request #391 from ikemo3/fix/news-tab-top
Browse files Browse the repository at this point in the history
fix: Google News tab(Top News) not working.
  • Loading branch information
ikemo3 authored Aug 14, 2022
2 parents 30e2c98 + 1b68a11 commit 5e6a962
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 9 additions & 5 deletions apps/block/google_news_tab_top.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SearchResultToBlock } from "./block";
import DocumentURL from "../values/document_url";
import { Options } from "../repository/options";
import { Logger } from '../common';

class GoogleNewsTabTop extends SearchResultToBlock {
private readonly valid: boolean;
Expand All @@ -22,7 +23,7 @@ class GoogleNewsTabTop extends SearchResultToBlock {
}

static isCandidate(element: Element, documentURL: DocumentURL): boolean {
return element.matches("div.nChh6e") && documentURL.isGoogleSearchNewsTab();
return element.matches("div.Cq2QEe") && documentURL.isGoogleSearchNewsTab();
}

// noinspection DuplicatedCode
Expand All @@ -32,6 +33,7 @@ class GoogleNewsTabTop extends SearchResultToBlock {

const anchor = element.querySelector("a");
if (anchor === null) {
Logger.debug("news top: anchor not found", element);
this.valid = false;
this._canRetry = true;
return;
Expand All @@ -47,19 +49,21 @@ class GoogleNewsTabTop extends SearchResultToBlock {
}
}

const h3 = element.querySelector("h3");
const titleElement = element.querySelector("[role='heading']");

// ignore if no h3(ex. Google Translate)
if (h3 === null) {
// ignore if no titleElement(ex. Google Translate)
if (titleElement === null) {
Logger.debug("news top: no title element(ex. Google Translate)", element);
this.valid = false;
this._canRetry = false;
return;
}

const title = h3.textContent ? h3.textContent : "";
const title = titleElement.textContent ? titleElement.textContent : "";
const st: HTMLSpanElement | null = element.querySelector(".st");
const contents = st ? st.textContent! : "";

element.setAttribute("data-gsb-element-type", "google-news-tab-top");
this.valid = true;
this._canRetry = true;
this.url = href;
Expand Down
7 changes: 7 additions & 0 deletions apps/styles/google.css
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ div[role="listitem"] {
margin-bottom: 0 !important;
}

[data-gsb-element-type="google-news-tab-top"] + .block-anchor {
margin-top: 0 !important;
margin-bottom: 0 !important;
margin-left: 0 !important;
white-space: normal !important;
}

[data-gsb-element-type="google-news-card"][data-gsb-menu-position="compact"] {
height: auto;
}

0 comments on commit 5e6a962

Please sign in to comment.