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.
main
Ben Busby 2020-05-13 00:19:51 -06:00 committed by GitHub
parent db7cf7381b
commit f4bd3df2bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 15 deletions

View File

@ -57,6 +57,7 @@ class Config:
self.dark = False self.dark = False
self.nojs = False self.nojs = False
self.near = '' self.near = ''
self.get_only = False
for key, value in kwargs.items(): for key, value in kwargs.items():
setattr(self, key, value) setattr(self, key, value)

View File

@ -42,7 +42,8 @@ def index():
bg=bg, bg=bg,
ua=g.user_request.modified_user_agent, ua=g.user_request.modified_user_agent,
languages=Config.LANGUAGES, 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']) @app.route('/opensearch.xml', methods=['GET'])
@ -51,7 +52,9 @@ def opensearch():
if opensearch_url.endswith('/'): if opensearch_url.endswith('/'):
opensearch_url = opensearch_url[:-1] 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 = make_response(template)
response.headers['Content-Type'] = 'application/xml' response.headers['Content-Type'] = 'application/xml'
return response return response

View File

@ -13,9 +13,16 @@ const setupSearchLayout = () => {
searchBtn.click(); 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 // Request existing config info
let xhrGET = new XMLHttpRequest(); let xhrGET = new XMLHttpRequest();
xhrGET.open("GET", "/config"); xhrGET.open("GET", "/config");
@ -29,15 +36,16 @@ const fillConfigValues = (near, nojs, dark, url) => {
let configSettings = JSON.parse(xhrGET.responseText); let configSettings = JSON.parse(xhrGET.responseText);
near.value = configSettings["near"] ? configSettings["near"] : ""; near.value = configSettings["near"] ? configSettings["near"] : "";
nojs.checked = !!configSettings["nojs"]; noJS.checked = !!configSettings["nojs"];
dark.checked = !!configSettings["dark"]; dark.checked = !!configSettings["dark"];
getOnly.checked = !!configSettings["get_only"];
// Addresses the issue of incorrect URL being used behind reverse proxy // Addresses the issue of incorrect URL being used behind reverse proxy
url.value = configSettings["url"] ? configSettings["url"] : ""; url.value = configSettings["url"] ? configSettings["url"] : "";
}; };
xhrGET.send(); xhrGET.send();
} };
const setupConfigLayout = () => { const setupConfigLayout = () => {
// Setup whoogle config // Setup whoogle config
@ -54,13 +62,8 @@ const setupConfigLayout = () => {
content.classList.toggle("open"); content.classList.toggle("open");
}); });
const near = document.getElementById("config-near"); fillConfigValues();
const noJS = document.getElementById("config-nojs"); };
const dark = document.getElementById("config-dark");
const url = document.getElementById("config-url");
fillConfigValues(near, noJS, dark, url);
}
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() { setTimeout(function() {

View File

@ -26,7 +26,7 @@
<body id="main" style="display: none; background-color: {{ bg }}"> <body id="main" style="display: none; background-color: {{ bg }}">
<div class="search-container"> <div class="search-container">
<img class="logo" src="/static/img/logo.png"> <img class="logo" src="/static/img/logo.png">
<form action="/search" method="post"> <form action="/search" method="{{ request_type }}">
<div class="search-fields"> <div class="search-fields">
<input type="text" name="q" id="search-bar" autofocus="autofocus"> <input type="text" name="q" id="search-bar" autofocus="autofocus">
<input type="submit" id="search-submit" value="Search"> <input type="submit" id="search-submit" value="Search">
@ -66,6 +66,10 @@
<label for="config-dark">Dark Mode: </label> <label for="config-dark">Dark Mode: </label>
<input type="checkbox" name="dark" id="config-dark"> <input type="checkbox" name="dark" id="config-dark">
</div> </div>
<div class="config-div">
<label for="config-get-only">GET Requests Only: </label>
<input type="checkbox" name="get_only" id="config-get-only">
</div>
<div class="config-div"> <div class="config-div">
<label for="config-url">Root URL: </label> <label for="config-url">Root URL: </label>
<input type="text" name="url" id="config-url" value=""> <input type="text" name="url" id="config-url" value="">

View File

@ -4,7 +4,7 @@
<Description>Whoogle: A lightweight, deployable Google search proxy for desktop/mobile that removes Javascript, AMP links, and ads</Description> <Description>Whoogle: A lightweight, deployable Google search proxy for desktop/mobile that removes Javascript, AMP links, and ads</Description>
<InputEncoding>UTF-8</InputEncoding> <InputEncoding>UTF-8</InputEncoding>
<Image width="32" height="32" type="image/x-icon">/static/img/favicon/favicon-32x32.png</Image> <Image width="32" height="32" type="image/x-icon">/static/img/favicon/favicon-32x32.png</Image>
<Url type="text/html" method="post" template="{{ main_url }}/search"> <Url type="text/html" method="{{ request_type }}" template="{{ main_url }}/search">
<Param name="q" value="{searchTerms}"/> <Param name="q" value="{searchTerms}"/>
</Url> </Url>
<Url type="application/x-suggestions+json" template="{{ main_url }}/search"/> <Url type="application/x-suggestions+json" template="{{ main_url }}/search"/>