Counter latest result page style changes

Google updated their styling of the result page, which broke some
components of Whoogle's result page styling (namely the result div
backgrounds for dark mode).

The GClasses class has been updated to keep track of what class names
have been updated to, and roll them back to a value that works for
Whoogle. A function was added that loops through new class names and
replaces them with their older counterparts.
main
Ben Busby 2022-06-09 16:30:55 -06:00
parent a9e1f0d1bc
commit 65796fd1a5
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
4 changed files with 44 additions and 13 deletions

View File

@ -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()

View File

@ -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

View File

@ -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 {

View File

@ -40,6 +40,8 @@ select {
.ZINbbc {
overflow: hidden;
background-color: var(--whoogle-result-bg) !important;
margin-bottom: 10px !important;
border-radius: 8px !important;
}
.BVG0Nb {