diff --git a/app/filter.py b/app/filter.py index 98360e5..630401d 100644 --- a/app/filter.py +++ b/app/filter.py @@ -1,18 +1,13 @@ -from app.models.config import Config -from app.models.endpoint import Endpoint +import cssutils +from bs4 import BeautifulSoup +from bs4.element import ResultSet, Tag +from cryptography.fernet import Fernet +from flask import render_template + from app.models.g_classes import GClasses from app.request import VALID_PARAMS, MAPS_URL from app.utils.misc import get_abs_url, read_config_bool from app.utils.results import * -from bs4 import BeautifulSoup -from bs4.element import ResultSet, Tag -from cryptography.fernet import Fernet -import cssutils -from flask import render_template -import re -import urllib.parse as urlparse -from urllib.parse import parse_qs -import os minimal_mode_sections = ['Top stories', 'Images', 'People also ask'] unsupported_g_pages = [ @@ -359,6 +354,9 @@ class Filter: # print(link) def update_styling(self, soup) -> None: + # Update CSS classes for result divs + soup = GClasses.replace_css_classes(soup) + # Remove unnecessary button(s) for button in soup.find_all('button'): button.decompose() diff --git a/app/models/g_classes.py b/app/models/g_classes.py index 9f394ce..0c32f41 100644 --- a/app/models/g_classes.py +++ b/app/models/g_classes.py @@ -1,7 +1,7 @@ -from enum import Enum +from bs4 import BeautifulSoup -class GClasses(Enum): +class GClasses: """A class for tracking obfuscated class names used in Google results that are directly referenced in Whoogle's filtering code. @@ -12,6 +12,35 @@ class GClasses(Enum): main_tbm_tab = 'KP7LCb' images_tbm_tab = 'n692Zd' footer = 'TuS8Ad' + result_class_a = 'ZINbbc' + result_class_b = 'luh4td' + + result_classes = { + result_class_a: ['Gx5Zad'], + result_class_b: ['fP1Qef'] + } + + @classmethod + def replace_css_classes(cls, soup: BeautifulSoup) -> BeautifulSoup: + """Replace updated Google classes with the original class names that + Whoogle relies on for styling. + + Args: + soup: The result page as a BeautifulSoup object + + Returns: + BeautifulSoup: The new BeautifulSoup + """ + result_divs = soup.find_all('div', { + 'class': [_ for c in cls.result_classes.values() for _ in c] + }) + + for div in result_divs: + new_class = ' '.join(div['class']) + for key, val in cls.result_classes.items(): + new_class = ' '.join(new_class.replace(_, key) for _ in val) + div['class'] = new_class.split(' ') + return soup def __str__(self): return self.value diff --git a/app/static/css/dark-theme.css b/app/static/css/dark-theme.css index d02999c..f1f51cc 100644 --- a/app/static/css/dark-theme.css +++ b/app/static/css/dark-theme.css @@ -66,6 +66,8 @@ select { overflow: hidden; box-shadow: 0 0 0 0 !important; background-color: var(--whoogle-dark-result-bg) !important; + margin-bottom: 10px !important; + border-radius: 8px !important; } .KP7LCb { diff --git a/app/static/css/light-theme.css b/app/static/css/light-theme.css index 387b6d6..99bb31f 100644 --- a/app/static/css/light-theme.css +++ b/app/static/css/light-theme.css @@ -40,6 +40,8 @@ select { .ZINbbc { overflow: hidden; background-color: var(--whoogle-result-bg) !important; + margin-bottom: 10px !important; + border-radius: 8px !important; } .BVG0Nb {