diff --git a/app/request.py b/app/request.py index 0c80f9b..71f4e9b 100644 --- a/app/request.py +++ b/app/request.py @@ -9,8 +9,6 @@ import os from stem import Signal, SocketError from stem.control import Controller -SEARCH_URL = 'https://www.google.com/search?gbv=1&num=' + str( - os.getenv('WHOOGLE_RESULTS_PER_PAGE', 10)) + '&q=' MAPS_URL = 'https://maps.google.com/maps' AUTOCOMPLETE_URL = ('https://suggestqueries.google.com/' 'complete/search?client=toolbar&') @@ -151,6 +149,8 @@ class Request: """ def __init__(self, normal_ua, root_path, config: Config): + self.search_url = 'https://www.google.com/search?gbv=1&num=' + str( + os.getenv('WHOOGLE_RESULTS_PER_PAGE', 10)) + '&q=' # Send heartbeat to Tor, used in determining if the user can or cannot # enable Tor for future requests send_tor_signal(Signal.HEARTBEAT) @@ -224,7 +224,7 @@ class Request: return [_.attrib['data'] for _ in root.findall('.//suggestion/[@data]')] - def send(self, base_url=SEARCH_URL, query='', attempt=0, + def send(self, base_url='', query='', attempt=0, force_mobile=False) -> Response: """Sends an outbound request to a URL. Optionally sends the request using Tor, if enabled by the user. @@ -285,7 +285,7 @@ class Request: disable=True) response = requests.get( - base_url + query, + (base_url or self.search_url) + query, proxies=self.proxies, headers=headers, cookies=cookies) @@ -295,6 +295,6 @@ class Request: attempt += 1 if attempt > 10: raise TorError("Tor query failed -- max attempts exceeded 10") - return self.send(base_url, query, attempt) + return self.send((base_url or self.search_url), query, attempt) return response diff --git a/app/routes.py b/app/routes.py index 92f445c..87c6f1e 100644 --- a/app/routes.py +++ b/app/routes.py @@ -14,7 +14,7 @@ from app import app from app.models.config import Config from app.request import Request, TorError from app.utils.bangs import resolve_bang -from app.utils.misc import read_config_bool +from app.utils.misc import read_config_bool, get_client_ip from app.utils.results import add_ip_card from app.utils.results import bold_search_terms from app.utils.search import * @@ -301,10 +301,11 @@ def search(): # Return 503 if temporarily blocked by captcha resp_code = 503 if has_captcha(str(response)) else 200 response = bold_search_terms(response, query) + # Feature to display IP address if search_util.check_kw_ip(): - html_soup = bsoup(response, "html.parser") - response = add_ip_card(html_soup, request.remote_addr) + html_soup = bsoup(str(response), 'html.parser') + response = add_ip_card(html_soup, get_client_ip(request)) return render_template( 'display.html', @@ -322,7 +323,7 @@ def search(): is_translation=any( _ in query.lower() for _ in [translation['translate'], 'translate'] ) and not search_util.search_type, # Standard search queries only - response=html.unescape(str(response)), + response=response, version_number=app.config['VERSION_NUMBER'], search_header=(render_template( 'header.html', @@ -434,7 +435,13 @@ def window(): for script in results('script'): script.decompose() - return render_template('display.html', response=results) + return render_template( + 'display.html', + response=results, + translation=app.config['TRANSLATIONS'][ + g.user_config.get_localization_lang() + ] + ) def run_app() -> None: diff --git a/app/static/css/main.css b/app/static/css/main.css index 1dd2374..c937ee2 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -102,6 +102,7 @@ button::-moz-focus-inner { } .open { + overflow-y: scroll; padding-bottom: 20px; } diff --git a/app/static/js/controller.js b/app/static/js/controller.js index 9dc88a2..05b68ec 100644 --- a/app/static/js/controller.js +++ b/app/static/js/controller.js @@ -26,7 +26,7 @@ const setupConfigLayout = () => { if (content.style.maxHeight) { content.style.maxHeight = null; } else { - content.style.maxHeight = content.scrollHeight + "px"; + content.style.maxHeight = "400px"; } content.classList.toggle("open"); diff --git a/app/templates/display.html b/app/templates/display.html index e9ec20b..4f2c109 100644 --- a/app/templates/display.html +++ b/app/templates/display.html @@ -1,45 +1,45 @@ - - - - - - - - - - {% if config.theme %} - {% if config.theme == 'system' %} + + + + + + + + + + {% if config.theme %} + {% if config.theme == 'system' %} - {% else %} - - {% endif %} {% else %} - + {% endif %} - - {{ clean_query(query) }} - Whoogle Search - - - {{ search_header|safe }} - {% if is_translation %} - + {% else %} + {% endif %} - {{ response|safe }} - - - - - + + {{ clean_query(query) }} - Whoogle Search + + +{{ search_header|safe }} +{% if is_translation %} + +{% endif %} +{{ response|safe }} + + + + + diff --git a/app/templates/header.html b/app/templates/header.html index 0ba701c..e9c04e2 100644 --- a/app/templates/header.html +++ b/app/templates/header.html @@ -2,8 +2,8 @@
+ id="search-form" + method="{{ 'GET' if config.get_only else 'POST' }}">