Condense NoJS feature into Anonymous View

Enabling NoJS now removes Javascript from the Anonymous View, rather
than creating a separate option.
This commit is contained in:
Ben Busby 2022-04-06 14:33:30 -06:00
parent e7b70dd34d
commit efd505f192
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
5 changed files with 21 additions and 11 deletions

View File

@ -85,7 +85,7 @@ class Filter:
self,
user_key: str,
config: Config,
root_url: str,
root_url='',
page_url='',
mobile=False) -> None:
self.config = config
@ -340,9 +340,10 @@ class Filter:
for style in soup.find_all('style'):
style.string = clean_css(style.string, self.page_url)
# Convert remote stylesheets to style tags
for link in soup.find_all('link', attrs={'rel': 'stylesheet'}):
print(link)
# TODO: Convert remote stylesheets to style tags and proxy all
# remote requests
# for link in soup.find_all('link', attrs={'rel': 'stylesheet'}):
# print(link)
def update_styling(self, soup) -> None:
# Remove unnecessary button(s)
@ -438,11 +439,8 @@ class Filter:
link['href'] = filter_link_args(q)
# Add alternate viewing options for results
if self.config.nojs:
append_nojs(link)
if self.config.anon_view:
append_anon_view(link)
append_anon_view(link, self.config.nojs)
if self.config.new_tab:
link['target'] = '_blank'

View File

@ -22,6 +22,11 @@ li {
color: var(--whoogle-dark-text) !important;
}
.anon-view {
color: var(--whoogle-dark-text) !important;
text-decoration: underline;
}
textarea {
background: var(--whoogle-dark-page-bg) !important;
color: var(--whoogle-dark-text) !important;

View File

@ -22,6 +22,11 @@ li {
color: var(--whoogle-text) !important;
}
.anon-view {
color: var(--whoogle-text) !important;
text-decoration: underline;
}
textarea {
background: var(--whoogle-page-bg) !important;
color: var(--whoogle-text) !important;

View File

@ -14,7 +14,7 @@
"config-block-url": "Block by URL",
"config-block-url-help": "Use regex",
"config-theme": "Theme",
"config-nojs": "Show NoJS Links",
"config-nojs": "Remove Javascript in \"Anonymous View\"",
"config-anon-view": "Show \"Anonymous View\" Links",
"config-dark": "Dark Mode",
"config-safe": "Safe Search",

View File

@ -188,20 +188,22 @@ def append_nojs(result: BeautifulSoup) -> None:
result.append(nojs_link)
def append_anon_view(result: BeautifulSoup) -> None:
def append_anon_view(result: BeautifulSoup, nojs: bool) -> 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
nojs: Remove Javascript from Anonymous View
Returns:
None
"""
av_link = BeautifulSoup(features='html.parser').new_tag('a')
av_link['href'] = f'/{Endpoint.window}?location=' + result['href']
av_link['href'] = f'/{Endpoint.window}?nojs={1 if nojs else 0}&location={result["href"]}'
av_link.string = ' Anonymous View'
av_link['class'] = 'anon-view'
result.append(av_link)