From f4bd3df2bb65e76d7eabe0e53a6798c9e4dba89e Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Wed, 13 May 2020 00:19:51 -0600 Subject: [PATCH] Added option to search only via GET request (#36) This addresses #18, which brought up the issue of searching with Whoogle with the search instance set to always use a specific container in Firefox Container Tabs. Could also be useful if you want to share your search results or something, I guess. Though nobody likes when people do that. --- app/models/config.py | 1 + app/routes.py | 7 +++++-- app/static/js/controller.js | 25 ++++++++++++++----------- app/templates/index.html | 6 +++++- app/templates/opensearch.xml | 2 +- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/models/config.py b/app/models/config.py index ee3c4ac..1c866d7 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -57,6 +57,7 @@ class Config: self.dark = False self.nojs = False self.near = '' + self.get_only = False for key, value in kwargs.items(): setattr(self, key, value) diff --git a/app/routes.py b/app/routes.py index ba2394c..6b48473 100644 --- a/app/routes.py +++ b/app/routes.py @@ -42,7 +42,8 @@ def index(): bg=bg, ua=g.user_request.modified_user_agent, languages=Config.LANGUAGES, - current_lang=g.user_config.lang) + current_lang=g.user_config.lang, + request_type='get' if g.user_config.get_only else 'post') @app.route('/opensearch.xml', methods=['GET']) @@ -51,7 +52,9 @@ def opensearch(): if opensearch_url.endswith('/'): opensearch_url = opensearch_url[:-1] - template = render_template('opensearch.xml', main_url=opensearch_url) + template = render_template('opensearch.xml', + main_url=opensearch_url, + request_type='get' if g.user_config.get_only else 'post') response = make_response(template) response.headers['Content-Type'] = 'application/xml' return response diff --git a/app/static/js/controller.js b/app/static/js/controller.js index acf16af..e950eb5 100644 --- a/app/static/js/controller.js +++ b/app/static/js/controller.js @@ -13,9 +13,16 @@ const setupSearchLayout = () => { searchBtn.click(); } }); -} +}; + +const fillConfigValues = () => { + // Establish all config value elements + const near = document.getElementById("config-near"); + const noJS = document.getElementById("config-nojs"); + const dark = document.getElementById("config-dark"); + const url = document.getElementById("config-url"); + const getOnly = document.getElementById("config-get-only"); -const fillConfigValues = (near, nojs, dark, url) => { // Request existing config info let xhrGET = new XMLHttpRequest(); xhrGET.open("GET", "/config"); @@ -29,15 +36,16 @@ const fillConfigValues = (near, nojs, dark, url) => { let configSettings = JSON.parse(xhrGET.responseText); near.value = configSettings["near"] ? configSettings["near"] : ""; - nojs.checked = !!configSettings["nojs"]; + noJS.checked = !!configSettings["nojs"]; dark.checked = !!configSettings["dark"]; + getOnly.checked = !!configSettings["get_only"]; // Addresses the issue of incorrect URL being used behind reverse proxy url.value = configSettings["url"] ? configSettings["url"] : ""; }; xhrGET.send(); -} +}; const setupConfigLayout = () => { // Setup whoogle config @@ -54,13 +62,8 @@ const setupConfigLayout = () => { content.classList.toggle("open"); }); - const near = document.getElementById("config-near"); - const noJS = document.getElementById("config-nojs"); - const dark = document.getElementById("config-dark"); - const url = document.getElementById("config-url"); - - fillConfigValues(near, noJS, dark, url); -} + fillConfigValues(); +}; document.addEventListener("DOMContentLoaded", function() { setTimeout(function() { diff --git a/app/templates/index.html b/app/templates/index.html index 89c38d3..222fa17 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -26,7 +26,7 @@
-
+
@@ -66,6 +66,10 @@
+
+ + +
diff --git a/app/templates/opensearch.xml b/app/templates/opensearch.xml index 82254b2..bf44b00 100644 --- a/app/templates/opensearch.xml +++ b/app/templates/opensearch.xml @@ -4,7 +4,7 @@ Whoogle: A lightweight, deployable Google search proxy for desktop/mobile that removes Javascript, AMP links, and ads UTF-8 /static/img/favicon/favicon-32x32.png - +