diff --git a/README.md b/README.md index 5c8e88b..1848d4a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@
Readme |
Discord |
+ User Showcase |
GitHub |
Documentation
@@ -57,28 +58,19 @@
- **Getting Started** - - [🔭 Preview](#preview-) - - [🚀 Features](#features-) - - [🛠️ Installation and Testing](#installation-and-testing-%EF%B8%8F) - - [🔧 Configuration](#configuration-) + - [🔭 Preview](#preview-) + - [🚀 Features](#features-) + - [🛠️ Installation and Testing](#installation-and-testing-%EF%B8%8F) + - [🔧 Configuration](#configuration-) - **Feature Overview** - - [🎨 Theming](#theming-) - - [🌍 Multi-Language Support](#multi-language-support-) -- **Community** - - [📊 System Requirements](#system-requirements-) - - [🗨️ FAQ (Frequently Asked Questions)](#faq-frequently-asked-questions-) - - [📣 More Contributors Wanted](#more-contributors-wanted-) - - [💖 Supporting Websurfx](#supporting-websurfx-) - - [📘 Documentation](#documentation-) - - [🛣️ Roadmap](#roadmap-) - - [🙋 Contributing](#contributing-) - - [📜 License](#license-) - - [🤝 Credits](#credits-) + - [🎨 Theming](#theming-) + - [🌍 Multi-Language Support](#multi-language-support-) +- **Community** - [📊 System Requirements](#system-requirements-) - [🗨️ FAQ (Frequently Asked Questions)](#faq-frequently-asked-questions-) - [📣 More Contributors Wanted](#more-contributors-wanted-) - [💖 Supporting Websurfx](#supporting-websurfx-) - [📘 Documentation](#documentation-) - [🛣️ Roadmap](#roadmap-) - [🙋 Contributing](#contributing-) - [📜 License](#license-) - [🤝 Credits](#credits-)
-# Preview 🔭 +# Preview 🔭 ## Home Page @@ -94,7 +86,7 @@ **[⬆️ Back to Top](#--)** -# Features 🚀 +# Features 🚀 - 🎨 Make Websurfx uniquely yours with twelve color schemes provided by default. It also supports creation of custom themes and color schemes in a quick and easy way, so unleash your creativity! - 🔐 Fast, private, and secure @@ -104,7 +96,7 @@ **[⬆️ Back to Top](#--)** -# Installation and Testing 🛠️ +# Installation and Testing 🛠️ > For full setup instructions, see: [**Installation**](./docs/installation.md) @@ -112,7 +104,7 @@ Before you can start building `websurfx`, you will need to have `Cargo` installe To get started with Websurfx, clone the repository, edit the config file, which is located in the `websurfx/` directory, and install the Redis server by following the instructions located [here](https://redis.io/docs/getting-started/) and then run the websurfx server and redis server using the following commands: -``` shell +```shell git clone https://github.com/neon-mmd/websurfx.git cd websurfx git checkout stable @@ -128,7 +120,7 @@ Once you have started the server, open your preferred web browser and navigate t **[⬆️ Back to Top](#--)** -# Configuration 🔧 +# Configuration 🔧 > For full configuration instructions, see: [**Configuration**](./docs/configuration.md) @@ -136,7 +128,7 @@ Websurfx is configured through the config.lua file, located at `websurfx/config. **[⬆️ Back to Top](#--)** -# Theming 🎨 +# Theming 🎨 > For full theming and customization instructions, see: [**Theming**](./docs/theming.md) @@ -173,7 +165,7 @@ Websurfx is based on Rust due to its memory safety features, which prevents vuln **[⬆️ Back to Top](#--)** -# More Contributors Wanted 📣 +# More Contributors Wanted 📣 We are looking for more willing contributors to help grow this project. For more information on how you can contribute, check out the [project board](https://github.com/neon-mmd/websurfx/projects?query=is%3Aopen) and the [CONTRIBUTING.md](CONTRIBUTING.md) file for guidelines and rules for making contributions. @@ -186,6 +178,7 @@ We are looking for more willing contributors to help grow this project. For more If you use Websurfx and would like to contribute to its development, we're glad to have you on board! Contributions of any size or type are always welcome, and we will always acknowledge your efforts. Several areas that we need a bit of help with at the moment are: + - **Better and more color schemes**: Help fix color schemes and add other famous color schemes. - **Improve evasion code for bot detection** - Help improve code related to evading IP blocking and emulating human behaviors located in everyone's engine file. - **Logo** - Help create a logo for the project and website. @@ -198,7 +191,7 @@ Several areas that we need a bit of help with at the moment are: # Documentation 📘 > **Note** -> We welcome any contributions to the [documentation](../../tree/HEAD/docs/) as this will benefit everyone who uses this project. +> We welcome any contributions to the [documentation](../../tree/HEAD/docs/) as this will benefit everyone who uses this project. **[⬆️ Back to Top](#--)** @@ -208,7 +201,7 @@ Several areas that we need a bit of help with at the moment are: **[⬆️ Back to Top](#--)** -# Contributing 🙋 +# Contributing 🙋 Contributions are welcome from anyone. It doesn't matter who you are; you can still contribute to the project in your own way. @@ -222,13 +215,13 @@ If you are a developer, have a look at the [CONTRIBUTING.org](CONTRIBUTING.md) d **[⬆️ Back to Top](#--)** -# License 📜 +# License 📜 Websurfx is licensed under the [AGPLv3](LICENSE) license. **[⬆️ Back to Top](#--)** -# Credits 🤝 +# Credits 🤝 We would like to thank the following people for their contributions and support: diff --git a/public/static/cookies.js b/public/static/cookies.js index 677eff7..6b55e02 100644 --- a/public/static/cookies.js +++ b/public/static/cookies.js @@ -16,8 +16,9 @@ document.addEventListener( let cookie = decodeURIComponent(document.cookie) // Set the value of the input field to the decoded cookie value if it is not empty // Otherwise, display a message indicating that no cookies have been saved on the user's system - document.querySelector('.cookies input').value = - cookie !== '' ? cookie : 'No cookies have been saved on your system' + document.querySelector('.cookies input').value = cookie.length + ? cookie + : 'No cookies have been saved on your system' } catch (error) { // If there is an error decoding the cookie, log the error to the console // and display an error message in the input field @@ -25,5 +26,5 @@ document.addEventListener( document.querySelector('.cookies input').value = 'Error decoding cookie' } }, - false + false, ) diff --git a/public/static/index.js b/public/static/index.js index 050829a..515065a 100644 --- a/public/static/index.js +++ b/public/static/index.js @@ -2,16 +2,25 @@ * Selects the input element for the search box * @type {HTMLInputElement} */ -const searchBox = document.querySelector('input'); +const searchBox = document.querySelector('input') /** * Redirects the user to the search results page with the query parameter */ function searchWeb() { - const query = searchBox.value.trim(); - if (query) { - window.location.href = `search?q=${encodeURIComponent(query)}`; - } + const query = searchBox.value.trim() + try { + let safeSearchLevel = document.querySelector('.search_options select').value + if (query) { + window.location.href = `search?q=${encodeURIComponent( + query, + )}&safesearch=${encodeURIComponent(safeSearchLevel)}` + } + } catch (error) { + if (query) { + window.location.href = `search?q=${encodeURIComponent(query)}` + } + } } /** @@ -19,7 +28,7 @@ function searchWeb() { * @param {KeyboardEvent} e - The keyboard event object */ searchBox.addEventListener('keyup', (e) => { - if (e.key === 'Enter') { - searchWeb(); - } -}); + if (e.key === 'Enter') { + searchWeb() + } +}) diff --git a/public/static/pagination.js b/public/static/pagination.js index 4f5697c..bdbfb39 100644 --- a/public/static/pagination.js +++ b/public/static/pagination.js @@ -3,8 +3,8 @@ * @returns {void} */ function navigate_forward() { - const url = new URL(window.location); - const searchParams = url.searchParams; + let url = new URL(window.location); + let searchParams = url.searchParams; let q = searchParams.get('q'); let page = parseInt(searchParams.get('page')); @@ -23,8 +23,8 @@ function navigate_forward() { * @returns {void} */ function navigate_backward() { - const url = new URL(window.location); - const searchParams = url.searchParams; + let url = new URL(window.location); + let searchParams = url.searchParams; let q = searchParams.get('q'); let page = parseInt(searchParams.get('page')); diff --git a/public/static/search_area_options.js b/public/static/search_area_options.js new file mode 100644 index 0000000..10e0390 --- /dev/null +++ b/public/static/search_area_options.js @@ -0,0 +1,18 @@ +document.addEventListener( + 'DOMContentLoaded', + () => { + let url = new URL(window.location) + let searchParams = url.searchParams + + let safeSearchLevel = searchParams.get('safesearch') + + if ( + safeSearchLevel >= 0 && + safeSearchLevel <= 2 && + safeSearchLevel !== null + ) { + document.querySelector('.search_options select').value = safeSearchLevel + } + }, + false, +) diff --git a/public/static/settings.js b/public/static/settings.js index 42b8a4b..fc0e118 100644 --- a/public/static/settings.js +++ b/public/static/settings.js @@ -1,5 +1,5 @@ /** - * This function handles the toggling of selections of all upstream search engines + * This function handles the toggling of selections of all upstream search engines * options in the settings page under the tab engines. */ function toggleAllSelection() { @@ -8,12 +8,12 @@ function toggleAllSelection() { .forEach( (engine_checkbox) => (engine_checkbox.checked = - document.querySelector('.select_all').checked) + document.querySelector('.select_all').checked), ) } /** - * This function adds the functionality to sidebar buttons to only show settings + * This function adds the functionality to sidebar buttons to only show settings * related to that tab. * @param {HTMLElement} current_tab - The current tab that was clicked. */ @@ -43,20 +43,28 @@ function setClientSettings() { // Loop through all select tags and add their values to the cookie dictionary document.querySelectorAll('select').forEach((select_tag) => { - if (select_tag.name === 'themes') { - cookie_dictionary['theme'] = select_tag.value - } else if (select_tag.name === 'colorschemes') { - cookie_dictionary['colorscheme'] = select_tag.value + switch (select_tag.name) { + case 'themes': + cookie_dictionary['theme'] = select_tag.value + break + case 'colorschemes': + cookie_dictionary['colorscheme'] = select_tag.value + break + case 'safe_search_levels': + cookie_dictionary['safe_search_level'] = Number(select_tag.value) + break } }) // Loop through all engine checkboxes and add their values to the cookie dictionary let engines = [] + document.querySelectorAll('.engine').forEach((engine_checkbox) => { - if (engine_checkbox.checked === true) { + if (engine_checkbox.checked) { engines.push(engine_checkbox.parentNode.parentNode.innerText.trim()) } }) + cookie_dictionary['engines'] = engines // Set the expiration date for the cookie to 1 year from the current date @@ -65,7 +73,7 @@ function setClientSettings() { // Save the cookie to the user's machine document.cookie = `appCookie=${JSON.stringify( - cookie_dictionary + cookie_dictionary, )}; expires=${expiration_date.toUTCString()}` // Display a success message to the user @@ -79,9 +87,9 @@ function setClientSettings() { } /** - * This functions gets the saved cookies if it is present on the user's machine If it - * is available then it is parsed and converted to an object which is then used to - * retrieve the preferences that the user had selected previously and is then loaded in the + * This functions gets the saved cookies if it is present on the user's machine If it + * is available then it is parsed and converted to an object which is then used to + * retrieve the preferences that the user had selected previously and is then loaded in the * website otherwise the function does nothing and the default server side settings are loaded. */ function getClientSettings() { @@ -89,21 +97,19 @@ function getClientSettings() { let cookie = decodeURIComponent(document.cookie) // If the cookie is not empty, parse it and use it to set the user's preferences - if (cookie !== '') { - let cookie_value = decodeURIComponent(document.cookie) + if (cookie.length) { + let cookie_value = cookie .split(';') .map((item) => item.split('=')) .reduce((acc, [_, v]) => (acc = JSON.parse(v)) && acc, {}) // Loop through all link tags and update their href values to match the user's preferences - let links = Array.from(document.querySelectorAll('link')).forEach( - (item) => { - if (item.href.includes('static/themes')) { - item.href = `static/themes/${cookie_value['theme']}.css` - } else if (item.href.includes('static/colorschemes')) { - item.href = `static/colorschemes/${cookie_value['colorscheme']}.css` - } + Array.from(document.querySelectorAll('link')).forEach((item) => { + if (item.href.includes('static/themes')) { + item.href = `static/themes/${cookie_value['theme']}.css` + } else if (item.href.includes('static/colorschemes')) { + item.href = `static/colorschemes/${cookie_value['colorscheme']}.css` } - ) + }) } } diff --git a/public/static/themes/simple.css b/public/static/themes/simple.css index 040e049..62ff0ea 100644 --- a/public/static/themes/simple.css +++ b/public/static/themes/simple.css @@ -70,6 +70,28 @@ body { filter: brightness(1.2); } +.search_area .search_options { + display: flex; + justify-content: space-between; + align-items: center; +} + +.search_area .search_options select { + margin: 0.7rem 0; + width: 20rem; + background-color: var(--color-one); + color: var(--foreground-color); + padding: 1rem 2rem; + border-radius: 0.5rem; + outline: none; + border: none; + text-transform: capitalize; +} + +.search_area .search_options option:hover { + background-color: var(--color-one); +} + .result_not_found { display: flex; flex-direction: column; @@ -503,7 +525,8 @@ footer { color: var(--foreground-color); } -.settings_container .user_interface select { +.settings_container .user_interface select, +.settings_container .general select { margin: 0.7rem 0; width: 20rem; background-color: var(--background-color); @@ -515,7 +538,8 @@ footer { text-transform: capitalize; } -.settings_container .user_interface option:hover { +.settings_container .user_interface option:hover, +.settings_container .general option:hover { background-color: var(--color-one); } diff --git a/public/templates/engines_tab.html b/public/templates/engines_tab.html index 0e36b49..ffca881 100644 --- a/public/templates/engines_tab.html +++ b/public/templates/engines_tab.html @@ -1,4 +1,5 @@Select the search engines from the list of engines that you want results diff --git a/public/templates/general_tab.html b/public/templates/general_tab.html index b83935a..92fc592 100644 --- a/public/templates/general_tab.html +++ b/public/templates/general_tab.html @@ -1,4 +1,13 @@
Coming soon!!
++ Select a safe search level from the menu below to filter content based on + the level. +
+
Select the theme from the available themes to be used in user interface
diff --git a/src/models/server_models.rs b/src/models/server_models.rs
index c9ed350..4772b98 100644
--- a/src/models/server_models.rs
+++ b/src/models/server_models.rs
@@ -26,4 +26,6 @@ pub struct Cookie<'a> {
pub colorscheme: &'a str,
/// It stores the user selected upstream search engines selected from the UI.
pub engines: Vec<&'a str>,
+ /// It stores the user selected safe search level from the UI.
+ pub safe_search_level: u8,
}
diff --git a/src/server/routes/search.rs b/src/server/routes/search.rs
index e46d30c..bdfc387 100644
--- a/src/server/routes/search.rs
+++ b/src/server/routes/search.rs
@@ -67,61 +67,48 @@ pub async fn search(
None => 1,
};
- let safe_search: u8 = match config.safe_search {
- 3..=4 => config.safe_search,
- _ => match ¶ms.safesearch {
- Some(safesearch) => match safesearch {
- 0..=2 => *safesearch,
- _ => 1,
- },
- None => config.safe_search,
- },
- };
-
let (_, results, _) = join!(
results(
format!(
- "http://{}:{}/search?q={}&page={}&safesearch={}",
+ "http://{}:{}/search?q={}&page={}&safesearch=",
config.binding_ip,
config.port,
query,
page - 1,
- safe_search
),
&config,
&cache,
query,
page - 1,
req.clone(),
- safe_search
+ ¶ms.safesearch
),
results(
format!(
- "http://{}:{}/search?q={}&page={}&safesearch={}",
- config.binding_ip, config.port, query, page, safe_search
+ "http://{}:{}/search?q={}&page={}&safesearch=",
+ config.binding_ip, config.port, query, page
),
&config,
&cache,
query,
page,
req.clone(),
- safe_search
+ ¶ms.safesearch
),
results(
format!(
- "http://{}:{}/search?q={}&page={}&safesearch={}",
+ "http://{}:{}/search?q={}&page={}&safesearch=",
config.binding_ip,
config.port,
query,
page + 1,
- safe_search
),
&config,
&cache,
query,
page + 1,
req.clone(),
- safe_search
+ ¶ms.safesearch
)
);
@@ -156,7 +143,7 @@ async fn results(
query: &str,
page: u32,
req: HttpRequest,
- safe_search: u8,
+ safe_search: &Option