@ -30,9 +30,11 @@ class Filter:
return page
def clean ( self , soup ) :
# Remove all ads
def remove_ads ( ) :
main_divs = soup . find ( ' div ' , { ' id ' : ' main ' } )
if main_divs is not None :
if main_divs is None :
return
result_divs = main_divs . findAll ( ' div ' , recursive = False )
# Only ads/sponsored content use classes in the list of result divs
@ -40,6 +42,14 @@ class Filter:
for div in ad_divs :
div . decompose ( )
def sync_images ( ) :
for img in soup . find_all ( ' img ' ) :
if img [ ' src ' ] . startswith ( ' // ' ) :
img [ ' src ' ] = ' https: ' + img [ ' src ' ]
img [ ' src ' ] = ' /tmp?image_url= ' + img [ ' src ' ]
def update_styling ( ) :
# Remove unnecessary button(s)
for button in soup . find_all ( ' button ' ) :
button . decompose ( )
@ -51,7 +61,8 @@ class Filter:
# Update logo
logo = soup . find ( ' a ' , { ' class ' : ' l ' } )
if logo and self . mobile :
logo [ ' style ' ] = ' display:flex; justify-content:center; align-items:center; color:#685e79; font-size:18px; '
logo [ ' style ' ] = ' display:flex; justify-content:center; align-items:center; color:#685e79; ' \
' font-size:18px; '
# Fix search bar length on mobile
try :
@ -60,6 +71,13 @@ class Filter:
except AttributeError :
pass
# Set up dark mode if active
if self . dark :
soup . find ( ' html ' ) [ ' style ' ] = ' scrollbar-color: #333 #111; '
for input_element in soup . findAll ( ' input ' ) :
input_element [ ' style ' ] = ' color:#fff; '
def update_links ( ) :
# Replace hrefs with only the intended destination (no "utm" type tags)
for a in soup . find_all ( ' a ' , href = True ) :
href = a [ ' href ' ]
@ -100,12 +118,6 @@ class Filter:
a . append ( BeautifulSoup ( ' <br><hr><br> ' , ' html.parser ' ) )
a . append ( nojs_link )
# Set up dark mode if active
if self . dark :
soup . find ( ' html ' ) [ ' style ' ] = ' scrollbar-color: #333 #111; '
for input_element in soup . findAll ( ' input ' ) :
input_element [ ' style ' ] = ' color:#fff; '
# Ensure no extra scripts passed through
try :
for script in soup ( ' script ' ) :
@ -114,4 +126,8 @@ class Filter:
except Exception :
pass
remove_ads ( )
sync_images ( )
update_styling ( )
update_links ( )
return soup