diff --git a/Dockerfile b/Dockerfile index d06c675..2d89e16 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,6 +26,7 @@ RUN mkdir -p $config_dir RUN chmod a+w $config_dir VOLUME $config_dir +ARG url_prefix='' ARG username='' ARG password='' ARG proxyuser='' @@ -45,6 +46,7 @@ ARG imgur_alt='farside.link/rimgo' ARG wikipedia_alt='farside.link/wikiless' ENV CONFIG_VOLUME=$config_dir \ + WHOOGLE_URL_PREFIX=$url_prefix \ WHOOGLE_USER=$username \ WHOOGLE_PASS=$password \ WHOOGLE_PROXY_USER=$proxyuser \ diff --git a/README.md b/README.md index b69cbf0..1e620a0 100644 --- a/README.md +++ b/README.md @@ -321,6 +321,7 @@ There are a few optional environment variables available for customizing a Whoog | Variable | Description | | -------------------- | ----------------------------------------------------------------------------------------- | +| WHOOGLE_URL_PREFIX | The URL prefix to use for the whoogle instance (i.e. "/whoogle") | | WHOOGLE_DOTENV | Load environment variables in `whoogle.env` | | WHOOGLE_USER | The username for basic auth. WHOOGLE_PASS must also be set if used. | | WHOOGLE_PASS | The password for basic auth. WHOOGLE_USER must also be set if used. | diff --git a/app/filter.py b/app/filter.py index 8931ffb..f721fb1 100644 --- a/app/filter.py +++ b/app/filter.py @@ -139,6 +139,8 @@ class Filter: input_form = soup.find('form') if input_form is not None: input_form['method'] = 'GET' if self.config.get_only else 'POST' + # Use a relative URI for submissions + input_form['action'] = 'search' # Ensure no extra scripts passed through for script in soup('script'): @@ -320,6 +322,11 @@ class Filter: render_template('logo.html'), features='html.parser')) return + elif src.startswith(G_M_LOGO_URL): + # Re-brand with single-letter Whoogle logo + element['src'] = 'static/img/favicon/apple-icon.png' + element.parent['href'] = 'home' + return elif src.startswith(GOOG_IMG) or GOOG_STATIC in src: element['src'] = BLANK_B64 return @@ -423,6 +430,10 @@ class Filter: # Internal google links (i.e. mail, maps, etc) should still # be forwarded to Google link['href'] = 'https://google.com' + q + elif q.startswith('https://accounts.google.com'): + # Remove Sign-in link + link.decompose() + return elif '/search?q=' in href: # "li:1" implies the query should be interpreted verbatim, # which is accomplished by wrapping the query in double quotes @@ -454,6 +465,16 @@ class Filter: if href.startswith(MAPS_URL): # Maps links don't work if a site filter is applied link['href'] = MAPS_URL + "?q=" + clean_query(q) + elif href.startswith('/?') or href.startswith('/search?'): + # make sure that tags can be clicked as relative URLs + link['href'] = href[1:] + elif href.startswith('/intl/'): + # do nothing, keep original URL for ToS + pass + elif href.startswith('/preferences'): + # there is no config specific URL, remove this + link.decompose() + return else: link['href'] = href diff --git a/app/routes.py b/app/routes.py index fde13fe..378af6a 100644 --- a/app/routes.py +++ b/app/routes.py @@ -625,4 +625,7 @@ def run_app() -> None: elif args.unix_socket: waitress.serve(app, unix_socket=args.unix_socket) else: - waitress.serve(app, listen="{}:{}".format(args.host, args.port)) + waitress.serve( + app, + listen="{}:{}".format(args.host, args.port), + url_prefix=os.environ.get('WHOOGLE_URL_PREFIX', '')) diff --git a/app/static/js/utils.js b/app/static/js/utils.js index d13bac9..6a8f2ce 100644 --- a/app/static/js/utils.js +++ b/app/static/js/utils.js @@ -1,6 +1,10 @@ const checkForTracking = () => { const mainDiv = document.getElementById("main"); - const query = document.getElementById("search-bar").value.replace(/\s+/g, ''); + const searchBar = document.getElementById("search-bar"); + // some pages (e.g. images) do not have these + if (!mainDiv || !searchBar) + return; + const query = searchBar.value.replace(/\s+/g, ''); // Note: regex functions for checking for tracking queries were derived // from here -- https://stackoverflow.com/questions/619977 @@ -59,11 +63,14 @@ document.addEventListener("DOMContentLoaded", function() { checkForTracking(); // Clear input if reset button tapped - const search = document.getElementById("search-bar"); + const searchBar = document.getElementById("search-bar"); const resetBtn = document.getElementById("search-reset"); + // some pages (e.g. images) do not have these + if (!searchBar || !resetBtn) + return; resetBtn.addEventListener("click", event => { event.preventDefault(); - search.value = ""; - search.focus(); + searchBar.value = ""; + searchBar.focus(); }); }); diff --git a/app/templates/search.html b/app/templates/search.html index 4695291..073b7ed 100644 --- a/app/templates/search.html +++ b/app/templates/search.html @@ -1,4 +1,4 @@ -
+