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
parent
a9e1f0d1bc
commit
65796fd1a5
|
@ -1,18 +1,13 @@
|
||||||
from app.models.config import Config
|
import cssutils
|
||||||
from app.models.endpoint import Endpoint
|
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.models.g_classes import GClasses
|
||||||
from app.request import VALID_PARAMS, MAPS_URL
|
from app.request import VALID_PARAMS, MAPS_URL
|
||||||
from app.utils.misc import get_abs_url, read_config_bool
|
from app.utils.misc import get_abs_url, read_config_bool
|
||||||
from app.utils.results import *
|
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']
|
minimal_mode_sections = ['Top stories', 'Images', 'People also ask']
|
||||||
unsupported_g_pages = [
|
unsupported_g_pages = [
|
||||||
|
@ -359,6 +354,9 @@ class Filter:
|
||||||
# print(link)
|
# print(link)
|
||||||
|
|
||||||
def update_styling(self, soup) -> None:
|
def update_styling(self, soup) -> None:
|
||||||
|
# Update CSS classes for result divs
|
||||||
|
soup = GClasses.replace_css_classes(soup)
|
||||||
|
|
||||||
# Remove unnecessary button(s)
|
# Remove unnecessary button(s)
|
||||||
for button in soup.find_all('button'):
|
for button in soup.find_all('button'):
|
||||||
button.decompose()
|
button.decompose()
|
||||||
|
|
|
@ -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
|
"""A class for tracking obfuscated class names used in Google results that
|
||||||
are directly referenced in Whoogle's filtering code.
|
are directly referenced in Whoogle's filtering code.
|
||||||
|
|
||||||
|
@ -12,6 +12,35 @@ class GClasses(Enum):
|
||||||
main_tbm_tab = 'KP7LCb'
|
main_tbm_tab = 'KP7LCb'
|
||||||
images_tbm_tab = 'n692Zd'
|
images_tbm_tab = 'n692Zd'
|
||||||
footer = 'TuS8Ad'
|
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):
|
def __str__(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
|
@ -66,6 +66,8 @@ select {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
box-shadow: 0 0 0 0 !important;
|
box-shadow: 0 0 0 0 !important;
|
||||||
background-color: var(--whoogle-dark-result-bg) !important;
|
background-color: var(--whoogle-dark-result-bg) !important;
|
||||||
|
margin-bottom: 10px !important;
|
||||||
|
border-radius: 8px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.KP7LCb {
|
.KP7LCb {
|
||||||
|
|
|
@ -40,6 +40,8 @@ select {
|
||||||
.ZINbbc {
|
.ZINbbc {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background-color: var(--whoogle-result-bg) !important;
|
background-color: var(--whoogle-result-bg) !important;
|
||||||
|
margin-bottom: 10px !important;
|
||||||
|
border-radius: 8px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.BVG0Nb {
|
.BVG0Nb {
|
||||||
|
|
Loading…
Reference in New Issue