diff --git a/README.md b/README.md index 5a84cf9..a8d0e4c 100644 --- a/README.md +++ b/README.md @@ -258,20 +258,21 @@ There are a few optional environment variables available for customizing a Whoog ### Config Environment Variables These environment variables allow setting default config values, but can be overwritten manually by using the home page config menu. These allow a shortcut for destroying/rebuilding an instance to the same config state every time. -| Variable | Description | -| ----------------------- | --------------------------------------------------------------- | -| WHOOGLE_CONFIG_COUNTRY | Filter results by hosting country | -| WHOOGLE_CONFIG_LANGUAGE | Set interface and search result language | -| WHOOGLE_CONFIG_DARK | Enable dark theme | -| WHOOGLE_CONFIG_SAFE | Enable safe searches | -| WHOOGLE_CONFIG_ALTS | Use social media site alternatives (nitter, invidious, etc) | -| WHOOGLE_CONFIG_TOR | Use Tor routing (if available) | -| WHOOGLE_CONFIG_NEW_TAB | Always open results in new tab | -| WHOOGLE_CONFIG_VIEW_IMAGE | Enable View Image option | -| WHOOGLE_CONFIG_GET_ONLY | Search using GET requests only | -| WHOOGLE_CONFIG_URL | The root url of the instance (`https:///`) | -| WHOOGLE_CONFIG_STYLE | The custom CSS to use for styling (must be single line) | - +| Variable | Description | +| ------------------------------ | --------------------------------------------------------------- | +| WHOOGLE_CONFIG_COUNTRY | Filter results by hosting country | +| WHOOGLE_CONFIG_LANGUAGE | Set interface language | +| WHOOGLE_CONFIG_SEARCH_LANGUAGE | Set search result language | +| WHOOGLE_CONFIG_BLOCK | Block websites from search results (use comma-separated list) | +| WHOOGLE_CONFIG_DARK | Enable dark theme | +| WHOOGLE_CONFIG_SAFE | Enable safe searches | +| WHOOGLE_CONFIG_ALTS | Use social media site alternatives (nitter, invidious, etc) | +| WHOOGLE_CONFIG_TOR | Use Tor routing (if available) | +| WHOOGLE_CONFIG_NEW_TAB | Always open results in new tab | +| WHOOGLE_CONFIG_VIEW_IMAGE | Enable View Image option | +| WHOOGLE_CONFIG_GET_ONLY | Search using GET requests only | +| WHOOGLE_CONFIG_URL | The root url of the instance (`https:///`) | +| WHOOGLE_CONFIG_STYLE | The custom CSS to use for styling (should be single line) | ## Usage Same as most search engines, with the exception of filtering by time range. diff --git a/app.json b/app.json index 7a3e384..47f4ca0 100644 --- a/app.json +++ b/app.json @@ -71,7 +71,22 @@ "required": false }, "WHOOGLE_CONFIG_LANGUAGE": { - "description": "[CONFIG] The language to use for search results and interface (use values from https://raw.githubusercontent.com/benbusby/whoogle-search/develop/app/static/settings/languages.json)", + "description": "[CONFIG] The language to use for the interface (use values from https://raw.githubusercontent.com/benbusby/whoogle-search/develop/app/static/settings/languages.json)", + "value": "", + "required": false + }, + "WHOOGLE_CONFIG_SEARCH_LANGUAGE": { + "description": "[CONFIG] The language to use for search results (use values from https://raw.githubusercontent.com/benbusby/whoogle-search/develop/app/static/settings/languages.json)", + "value": "", + "required": false + }, + "WHOOGLE_CONFIG_DISABLE": { + "description": "[CONFIG] Disable ability for client to change config (set to 1 or leave blank)", + "value": "", + "required": false + }, + "WHOOGLE_CONFIG_BLOCK": { + "description": "[CONFIG] Block websites from search results (comma-separated list)", "value": "", "required": false }, diff --git a/app/__init__.py b/app/__init__.py index 164b8e9..7147019 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -50,7 +50,7 @@ app.config['BANG_FILE'] = os.path.join( 'bangs.json') app.config['CSP'] = 'default-src \'none\';' \ 'manifest-src \'self\';' \ - 'img-src \'self\';' \ + 'img-src \'self\' data:;' \ 'style-src \'self\' \'unsafe-inline\';' \ 'script-src \'self\';' \ 'media-src \'self\';' \ diff --git a/app/models/config.py b/app/models/config.py index 5a7082b..5b2f192 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -12,12 +12,13 @@ class Config: app_config = current_app.config self.url = os.getenv('WHOOGLE_CONFIG_URL', '') - self.lang_search = os.getenv('WHOOGLE_CONFIG_LANGUAGE', '') + self.lang_search = os.getenv('WHOOGLE_CONFIG_SEARCH_LANGUAGE', '') self.lang_interface = os.getenv('WHOOGLE_CONFIG_LANGUAGE', '') self.style = os.getenv( 'WHOOGLE_CONFIG_STYLE', open(os.path.join(app_config['STATIC_FOLDER'], 'css/variables.css')).read()) + self.block = os.getenv('WHOOGLE_CONFIG_BLOCK', '') self.ctry = os.getenv('WHOOGLE_CONFIG_COUNTRY', '') self.safe = read_config_bool('WHOOGLE_CONFIG_SAFE') self.dark = read_config_bool('WHOOGLE_CONFIG_DARK') @@ -38,11 +39,12 @@ class Config: # Skip setting custom config if there isn't one if kwargs: - for attr in self.get_mutable_attrs(): - if attr not in kwargs.keys(): - setattr(self, attr, '') - else: + mutable_attrs = self.get_mutable_attrs() + for attr in mutable_attrs: + if attr in kwargs.keys(): setattr(self, attr, kwargs[attr]) + elif attr not in kwargs.keys() and mutable_attrs[attr] == bool: + setattr(self, attr, False) def __getitem__(self, name): return getattr(self, name) @@ -57,7 +59,7 @@ class Config: return hasattr(self, name) def get_mutable_attrs(self): - return {name: attr for name, attr in self.__dict__.items() + return {name: type(attr) for name, attr in self.__dict__.items() if not name.startswith("__") and (type(attr) is bool or type(attr) is str)} diff --git a/app/request.py b/app/request.py index 91abdc0..c93aa96 100644 --- a/app/request.py +++ b/app/request.py @@ -120,6 +120,10 @@ def gen_query(query, args, config, near_city=None) -> str: ) if config.lang_interface else '' param_dict['safe'] = '&safe=' + ('active' if config.safe else 'off') + # Block all sites specified in the user config + for blocked in config.block.split(','): + query += (' -site:' + blocked) if blocked else '' + for val in param_dict.values(): if not val: continue diff --git a/app/routes.py b/app/routes.py index ff915ca..71a927c 100644 --- a/app/routes.py +++ b/app/routes.py @@ -2,7 +2,6 @@ import argparse import base64 import io import json -import os import pickle import urllib.parse as urlparse import uuid @@ -17,7 +16,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.session import valid_user_session +from app.utils.session import generate_user_key, valid_user_session from app.utils.search import * # Load DDG bang json files only on init diff --git a/app/static/css/dark-theme.css b/app/static/css/dark-theme.css index 1994869..e8ef1f5 100644 --- a/app/static/css/dark-theme.css +++ b/app/static/css/dark-theme.css @@ -66,7 +66,7 @@ select { } #search-bar { - border: 2px solid var(--whoogle-dark-element-bg) !important; + border-color: var(--whoogle-dark-element-bg) !important; color: var(--whoogle-dark-text) !important; } diff --git a/app/static/css/header.css b/app/static/css/header.css index a7c8461..61f6479 100644 --- a/app/static/css/header.css +++ b/app/static/css/header.css @@ -27,6 +27,11 @@ header { font-smoothing: antialiased; } +.search-bar-desktop { + border-radius: 8px 8px 0 0; + height: 40px !important; +} + .search-div { border-radius: 8px 8px 0 0; box-shadow: 0 1px 6px rgba(32, 33, 36, 0.18); @@ -37,6 +42,7 @@ header { height: 39px; display: flex; width: 100%; + margin: 0px; } .search-input { @@ -61,7 +67,6 @@ header { display: block; } - #main>div:focus-within { border-radius: 8px; box-shadow: 0 0 6px 1px #2375e8; diff --git a/app/static/css/input.css b/app/static/css/input.css new file mode 100644 index 0000000..96cc108 --- /dev/null +++ b/app/static/css/input.css @@ -0,0 +1,14 @@ +#search-bar { + background: transparent !important; + padding-right: 50px; +} + +#search-reset { + all: unset; + margin-left: -50px; + text-align: center; + background-color: transparent !important; + cursor: pointer; + height: 40px; + width: 50px; +} diff --git a/app/static/css/light-theme.css b/app/static/css/light-theme.css index de76eb6..9221b02 100644 --- a/app/static/css/light-theme.css +++ b/app/static/css/light-theme.css @@ -122,6 +122,7 @@ input { .autocomplete-items div:hover { background-color: var(--whoogle-element-bg); + color: var(--whoogle-contrast-text) !important; } .autocomplete-active { diff --git a/app/static/js/utils.js b/app/static/js/utils.js index 56e052f..d13bac9 100644 --- a/app/static/js/utils.js +++ b/app/static/js/utils.js @@ -57,4 +57,13 @@ const checkForTracking = () => { document.addEventListener("DOMContentLoaded", function() { checkForTracking(); + + // Clear input if reset button tapped + const search = document.getElementById("search-bar"); + const resetBtn = document.getElementById("search-reset"); + resetBtn.addEventListener("click", event => { + event.preventDefault(); + search.value = ""; + search.focus(); + }); }); diff --git a/app/templates/display.html b/app/templates/display.html index d21bd6b..398e276 100644 --- a/app/templates/display.html +++ b/app/templates/display.html @@ -5,6 +5,7 @@ + diff --git a/app/templates/header.html b/app/templates/header.html index 5973274..b353d92 100644 --- a/app/templates/header.html +++ b/app/templates/header.html @@ -1,7 +1,7 @@ {% if mobile %}
-
-
+
+
- + +
@@ -37,11 +45,19 @@
- +
diff --git a/app/templates/index.html b/app/templates/index.html index ee7cd2b..37f753c 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -42,113 +42,137 @@
- +
-
- -
-
-
-
- - -
— Note: If enabled, a website will only appear in the results if it is *hosted* in the selected country.
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
— Replaces Twitter/YouTube/Instagram/Reddit links - with Nitter/Invidious/Bibliogram/Libreddit links.
-
-
- - -
-
- - -
— Adds the "View Image" option to image search results. - Note: This will cause image result thumbnails to be lower resolution.
-
-
- - -
-
- - -
-
- - -
-
- - -
-
-   -   - -
-
+ {% if not config_disabled %} +
+ +
+
+
+
+ + +
— Note: If enabled, a website will only appear in the results if it is *hosted* in the selected country.
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
-
-
+
+ + +
+
+ + +
+
+ + +
+
+ + +
— Replaces Twitter/YouTube/Instagram/Reddit links + with Nitter/Invidious/Bibliogram/Libreddit links.
+
+
+ + +
+
+ + +
— Adds the "View Image" option to image search results. + Note: This will cause image result thumbnails to be lower resolution.
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+   +   + +
+ +
+
+ {% endif %} +