Add front end for enabling anonymous view

Still WIP. The method for appending anonymous view links creates a
pretty ugly layout for result cards with more than one link. May need to
consider only having one anonymous view / nojs link per result, and only
use the main link from the result card.
This commit is contained in:
Ben Busby 2022-03-21 09:58:25 -06:00
parent 7b8a8525d5
commit 02b9cabe90
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
5 changed files with 31 additions and 3 deletions

View File

@ -386,10 +386,13 @@ class Filter:
# Strip unneeded arguments
link['href'] = filter_link_args(q)
# Add no-js option
# Add alternate viewing options for results
if self.config.nojs:
append_nojs(link)
if self.config.anon_view:
append_anon_view(link)
if self.config.new_tab:
link['target'] = '_blank'
else:

View File

@ -28,6 +28,7 @@ class Config:
self.new_tab = read_config_bool('WHOOGLE_CONFIG_NEW_TAB')
self.view_image = read_config_bool('WHOOGLE_CONFIG_VIEW_IMAGE')
self.get_only = read_config_bool('WHOOGLE_CONFIG_GET_ONLY')
self.anon_view = read_config_bool('WHOOGLE_CONFIG_ANON_VIEW')
self.accept_language = False
self.safe_keys = [
@ -39,7 +40,9 @@ class Config:
'new_tab',
'view_image',
'block',
'safe'
'safe',
'nojs',
'anon_view'
]
# Skip setting custom config if there isn't one

View File

@ -15,6 +15,7 @@
"config-block-url-help": "Use regex",
"config-theme": "Theme",
"config-nojs": "Show NoJS Links",
"config-anon-view": "Show \"Anonymous View\" Links",
"config-dark": "Dark Mode",
"config-safe": "Safe Search",
"config-alts": "Replace Social Media Links",

View File

@ -148,6 +148,10 @@
<input type="text" name="block_url" id="config-block"
placeholder="{{ translation['config-block-url-help'] }}" value="{{ config.block_url }}">
</div>
<div class="config-div config-div-anon-view">
<label for="config-anon-view">{{ translation['config-anon-view'] }}: </label>
<input type="checkbox" name="anon_view" id="config-anon-view" {{ 'checked' if config.anon_view else '' }}>
</div>
<div class="config-div config-div-nojs">
<label for="config-nojs">{{ translation['config-nojs'] }}: </label>
<input type="checkbox" name="nojs" id="config-nojs" {{ 'checked' if config.nojs else '' }}>

View File

@ -183,11 +183,28 @@ def append_nojs(result: BeautifulSoup) -> None:
"""
nojs_link = BeautifulSoup(features='html.parser').new_tag('a')
nojs_link['href'] = f'/{Endpoint.window}?location=' + result['href']
nojs_link['href'] = f'/{Endpoint.window}?nojs=1&location=' + result['href']
nojs_link.string = ' NoJS Link'
result.append(nojs_link)
def append_anon_view(result: BeautifulSoup) -> None:
"""Appends an 'anonymous view' for a search result, where all site
contents are viewed through Whoogle as a proxy.
Args:
result: The search result to append an anon view link to
Returns:
None
"""
av_link = BeautifulSoup(features='html.parser').new_tag('a')
av_link['href'] = f'/{Endpoint.window}?location=' + result['href']
av_link.string = ' Anonymous View'
result.append(av_link)
def add_ip_card(html_soup: BeautifulSoup, ip: str) -> BeautifulSoup:
"""Adds the client's IP address to the search results
if query contains keywords