From 04d8c4304cd670d74e1aa93f618c03d754bce7d6 Mon Sep 17 00:00:00 2001 From: Monty Date: Sun, 27 Mar 2022 15:05:57 +0200 Subject: [PATCH 1/3] Check if query is math --- searx/webapp.py | 4 +++- searx/webutils.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/searx/webapp.py b/searx/webapp.py index 2f27d0f64..cc0624437 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -81,6 +81,7 @@ from searx.webutils import ( is_hmac_of, is_flask_run_cmdline, group_engines_in_tab, + is_math, ) from searx.webadapter import ( get_search_query_from_webapp, @@ -851,7 +852,8 @@ def search(): ), theme = get_current_theme_name(), favicons = global_favicons[themes.index(get_current_theme_name())], - timeout_limit = request.form.get('timeout_limit', None) + timeout_limit = request.form.get('timeout_limit', None), + is_math = is_math(search_query.query) # fmt: on ) diff --git a/searx/webutils.py b/searx/webutils.py index 5be721eec..e281f1a43 100644 --- a/searx/webutils.py +++ b/searx/webutils.py @@ -179,3 +179,16 @@ def group_engines_in_tab(engines: Iterable[Engine]) -> List[Tuple[str, Iterable[ return (engine.about.get('language', ''), engine.name) return [(groupname, sorted(engines, key=engine_sort_key)) for groupname, engines in sorted_groups] + +def is_math(query): + is_math = False + characters = set(['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '*', '/', '^', '%', '.', '+', '-', ',']) + numbers = 0 + + for i in query: + if i in characters: + numbers +=1 + + if len(query) < numbers+1: + is_math = True + return is_math \ No newline at end of file From 43773774ed33cc355c0444fca5ad7b6326355ddb Mon Sep 17 00:00:00 2001 From: Monty Date: Sun, 27 Mar 2022 19:27:01 +0200 Subject: [PATCH 2/3] Add calculator --- searx/static/themes/simple/gruntfile.js | 1 + .../static/themes/simple/src/less/style.less | 40 +++++++++++++ searx/templates/simple/results.html | 56 +++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/searx/static/themes/simple/gruntfile.js b/searx/static/themes/simple/gruntfile.js index 25883e384..c9794c94d 100644 --- a/searx/static/themes/simple/gruntfile.js +++ b/searx/static/themes/simple/gruntfile.js @@ -172,6 +172,7 @@ module.exports = function (grunt) { all: { src: { 'warning': 'node_modules/ionicons/dist/svg/alert-outline.svg', + 'calculator-outline': 'node_modules/ionicons/dist/svg/calculator-outline.svg', 'close': 'node_modules/ionicons/dist/svg/close-outline.svg', 'chevron-up-outline': 'node_modules/ionicons/dist/svg/chevron-up-outline.svg', 'chevron-right': 'node_modules/ionicons/dist/svg/chevron-forward-outline.svg', diff --git a/searx/static/themes/simple/src/less/style.less b/searx/static/themes/simple/src/less/style.less index 50e377995..23bc73fda 100644 --- a/searx/static/themes/simple/src/less/style.less +++ b/searx/static/themes/simple/src/less/style.less @@ -448,6 +448,7 @@ article[data-vim-selected].category-social { grid-template-rows: min-content min-content 1fr min-content; gap: 0 @results-gap; grid-template-areas: + "calculator sidebar" "corrections sidebar" "answers sidebar" "urls sidebar" @@ -459,6 +460,45 @@ article[data-vim-selected].category-social { margin-top: 0; } +#calculator { + grid-area: calculator; + padding: 1rem; + margin-bottom: 1em; + border-radius: 1em; + + #calc_header { + display: flex; + justify-content: space-between; + align-items: center; + + #calc_title { + display: flex; + align-items: center; + + #calc_icon { + display: inline-flex; + align-items: center; + margin-right: 0.3em; + } + } + } + + #calc_input { + font-size: 2rem; + padding: 1.7rem 1rem 1rem; + margin-bottom: 0.5rem; + text-align: end; + } + + #calc_keypad { + display: flex; + + #keypad_group { + display: grid; + } + } +} + #urls { padding: 0; grid-area: urls; diff --git a/searx/templates/simple/results.html b/searx/templates/simple/results.html index b05841bbb..87db8308f 100644 --- a/searx/templates/simple/results.html +++ b/searx/templates/simple/results.html @@ -19,6 +19,62 @@ {% endif %}
+ {% if is_math == True %} +
+
+
+
{{ icon_big('calculator-outline') }}
+ {{ _('Calculator') }} +
+
{{ q }} =
+
+ +
+
+
+
+ +
+
+ + + + + + + + + + + + + + + +
+
+ + + + + +
+
+ + + + + + + + + + +
+
+
+ {% endif %} + {% if answers -%}