From 1e1bb4a55a4c382ea900e80db11c3f1ea71754ac Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Tue, 21 Jan 2020 18:07:08 -0700 Subject: [PATCH] Added tbm (images/news/etc) handling, updated front page and search controls --- app/routes.py | 6 +++++- app/static/js/controller.js | 4 ++++ app/templates/index.html | 10 +++++++--- app/templates/search.html | 2 -- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/routes.py b/app/routes.py index 610bda9..6ac5175 100644 --- a/app/routes.py +++ b/app/routes.py @@ -17,9 +17,13 @@ def search(): if q is None or len(q) <= 0: return render_template('error.html') + tbm = '' + if 'tbm' in request.args: + tbm = '&tbm=' + request.args.get('tbm') + b_obj = BytesIO() crl = pycurl.Curl() - crl.setopt(crl.URL, 'https://www.google.com/search?q=' + url_parse(q)) + crl.setopt(crl.URL, 'https://www.google.com/search?q=' + url_parse(q) + tbm) crl.setopt(crl.USERAGENT, 'Brozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 LizzieMcGuirefox/59.0') crl.setopt(crl.WRITEDATA, b_obj) crl.perform() diff --git a/app/static/js/controller.js b/app/static/js/controller.js index 1e06935..38b10a7 100644 --- a/app/static/js/controller.js +++ b/app/static/js/controller.js @@ -2,6 +2,10 @@ document.addEventListener("DOMContentLoaded", function() { const searchBar = document.getElementById("search-bar"); const searchBtn = document.getElementById("search-submit"); + // Automatically focus on search field + searchBar.focus(); + searchBar.select(); + searchBar.addEventListener("keyup", function(event) { if (event.keyCode === 13) { event.preventDefault(); diff --git a/app/templates/index.html b/app/templates/index.html index 1ade0b1..7343f77 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -1,5 +1,9 @@ + - - - +
+

No-AMP Search

+ + + +
diff --git a/app/templates/search.html b/app/templates/search.html index 2974faa..5d6b14e 100644 --- a/app/templates/search.html +++ b/app/templates/search.html @@ -1,3 +1 @@ -

Search

- {{ response|safe }}