From efd505f1921b6831954698853e8b35b28c88f49f Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Wed, 6 Apr 2022 14:33:30 -0600 Subject: [PATCH] Condense NoJS feature into Anonymous View Enabling NoJS now removes Javascript from the Anonymous View, rather than creating a separate option. --- app/filter.py | 14 ++++++-------- app/static/css/dark-theme.css | 5 +++++ app/static/css/light-theme.css | 5 +++++ app/static/settings/translations.json | 2 +- app/utils/results.py | 6 ++++-- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/filter.py b/app/filter.py index 65cc0f8..52c6459 100644 --- a/app/filter.py +++ b/app/filter.py @@ -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' diff --git a/app/static/css/dark-theme.css b/app/static/css/dark-theme.css index 5b71edd..d02999c 100644 --- a/app/static/css/dark-theme.css +++ b/app/static/css/dark-theme.css @@ -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; diff --git a/app/static/css/light-theme.css b/app/static/css/light-theme.css index 76dd155..387b6d6 100644 --- a/app/static/css/light-theme.css +++ b/app/static/css/light-theme.css @@ -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; diff --git a/app/static/settings/translations.json b/app/static/settings/translations.json index 9828a55..8914b48 100644 --- a/app/static/settings/translations.json +++ b/app/static/settings/translations.json @@ -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", diff --git a/app/utils/results.py b/app/utils/results.py index 7ea8cf9..c04cd36 100644 --- a/app/utils/results.py +++ b/app/utils/results.py @@ -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)