0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-24 23:18:22 -05:00

Merge branch 'rolling' into evan523

This commit is contained in:
neon_arch 2024-11-01 22:55:47 +03:00 committed by GitHub
commit dfa4b209b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 30 additions and 106 deletions

13
Cargo.lock generated
View File

@ -3273,6 +3273,7 @@ dependencies = [
"sync_wrapper", "sync_wrapper",
"tokio 1.40.0", "tokio 1.40.0",
"tokio-rustls", "tokio-rustls",
"tokio-socks",
"tokio-util", "tokio-util",
"tower-service", "tower-service",
"url 2.5.2", "url 2.5.2",
@ -4103,6 +4104,18 @@ dependencies = [
"tokio 1.40.0", "tokio 1.40.0",
] ]
[[package]]
name = "tokio-socks"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d4770b8024672c1101b3f6733eab95b18007dbe0847a8afe341fcf79e06043f"
dependencies = [
"either",
"futures-util",
"thiserror",
"tokio 1.40.0",
]
[[package]] [[package]]
name = "tokio-sync" name = "tokio-sync"
version = "0.1.8" version = "0.1.8"

View File

@ -1,41 +1,6 @@
/**
* Selects the input element for the search box
* @type {HTMLInputElement}
*/
const searchBox = document.querySelector('input')
/**
* Redirects the user to the search results page with the query parameter
*/
function searchWeb() {
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)}`
}
}
}
/**
* Listens for the 'Enter' key press event on the search box and calls the searchWeb function
* @param {KeyboardEvent} e - The keyboard event object
*/
searchBox.addEventListener('keyup', (e) => {
if (e.key === 'Enter') {
searchWeb()
}
})
/** /**
* A function that clears the search input text when the clear button is clicked. * A function that clears the search input text when the clear button is clicked.
*/ */
function clearSearchText() { function clearSearchText() {
document.querySelector('.search_bar input').value = '' document.querySelector('.search_bar > input').value = ''
} }

View File

@ -1,39 +0,0 @@
/**
* Navigates to the next page by incrementing the current page number in the URL query string.
* @returns {void}
*/
function navigate_forward() {
let url = new URL(window.location);
let searchParams = url.searchParams;
let q = searchParams.get('q');
let page = parseInt(searchParams.get('page'));
if (isNaN(page)) {
page = 1;
} else {
page++;
}
window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
}
/**
* Navigates to the previous page by decrementing the current page number in the URL query string.
* @returns {void}
*/
function navigate_backward() {
let url = new URL(window.location);
let searchParams = url.searchParams;
let q = searchParams.get('q');
let page = parseInt(searchParams.get('page'));
if (isNaN(page)) {
page = 0;
} else if (page > 0) {
page--;
}
window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
}

View File

@ -1,18 +0,0 @@
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,
)

View File

@ -448,7 +448,7 @@ footer div {
align-items: center; align-items: center;
} }
.page_navigation button { .page_navigation a {
background: var(--background-color); background: var(--background-color);
color: var(--foreground-color); color: var(--foreground-color);
padding: 1rem; padding: 1rem;
@ -457,7 +457,7 @@ footer div {
border: none; border: none;
} }
.page_navigation button:active { .page_navigation a:active {
filter: brightness(1.2); filter: brightness(1.2);
} }

View File

@ -129,6 +129,7 @@ pub async fn search(
&config.style.theme, &config.style.theme,
&config.style.animation, &config.style.animation,
query, query,
page,
&results.0, &results.0,
) )
.0, .0,

View File

@ -14,12 +14,13 @@ use maud::{html, Markup, PreEscaped};
/// It returns the compiled html code for the search bar as a result. /// It returns the compiled html code for the search bar as a result.
pub fn bar(query: &str) -> Markup { pub fn bar(query: &str) -> Markup {
html!( html!(
(PreEscaped("<form action=\"/search\">"))
(PreEscaped("<div class=\"search_bar\">")) (PreEscaped("<div class=\"search_bar\">"))
input type="search" name="search-box" value=(query) placeholder="Type to search"; input type="search" name="q" value=(query) placeholder="Type to search";
button type="reset" onclick="clearSearchText()" { button type="button" onclick="clearSearchText()" {
img src="./images/close.svg" alt="Clear button icon for clearing search input text"; img src="./images/close.svg" alt="Clear button icon for clearing search input text";
} }
button type="submit" onclick="searchWeb()" { button type="submit" {
img src="./images/magnifying_glass.svg" alt="Info icon for error box"; img src="./images/magnifying_glass.svg" alt="Info icon for error box";
} }
) )

View File

@ -29,7 +29,7 @@ pub fn search_bar(
(bar(query)) (bar(query))
.error_box { .error_box {
@if !engine_errors_info.is_empty(){ @if !engine_errors_info.is_empty(){
button onclick="toggleErrorBox()" class="error_box_toggle_button"{ button type="button" onclick="toggleErrorBox()" class="error_box_toggle_button"{
img src="./images/warning.svg" alt="Info icon for error box"; img src="./images/warning.svg" alt="Info icon for error box";
} }
.dropdown_error_box{ .dropdown_error_box{
@ -43,7 +43,7 @@ pub fn search_bar(
} }
} }
@else { @else {
button onclick="toggleErrorBox()" class="error_box_toggle_button"{ button type="button" onclick="toggleErrorBox()" class="error_box_toggle_button"{
img src="./images/info.svg" alt="Warning icon for error box"; img src="./images/info.svg" alt="Warning icon for error box";
} }
.dropdown_error_box { .dropdown_error_box {
@ -56,10 +56,10 @@ pub fn search_bar(
(PreEscaped("</div>")) (PreEscaped("</div>"))
.search_options { .search_options {
@if safe_search_level >= 3 { @if safe_search_level >= 3 {
(PreEscaped("<select name=\"safe_search_levels\" disabled>")) (PreEscaped("<select name=\"safesearch\" disabled>"))
} }
@else{ @else{
(PreEscaped("<select name=\"safe_search_levels\">")) (PreEscaped(format!("<select name=\"safesearch\" value=\"{}\">", safe_search_level)))
} }
@for (idx, name) in SAFE_SEARCH_LEVELS_NAME.iter().enumerate() { @for (idx, name) in SAFE_SEARCH_LEVELS_NAME.iter().enumerate() {
@if (safe_search_level as usize) == idx { @if (safe_search_level as usize) == idx {
@ -71,6 +71,7 @@ pub fn search_bar(
} }
(PreEscaped("</select>")) (PreEscaped("</select>"))
} }
(PreEscaped("</form>"))
} }
) )
} }

View File

@ -24,6 +24,7 @@ pub fn search(
theme: &str, theme: &str,
animation: &Option<String>, animation: &Option<String>,
query: &str, query: &str,
page: u32,
search_results: &SearchResults, search_results: &SearchResults,
) -> Markup { ) -> Markup {
html!( html!(
@ -108,15 +109,14 @@ pub fn search(
} }
} }
.page_navigation { .page_navigation {
button type="button" onclick="navigate_backward()"{ a href=(format!("/search?q={}&safesearch={}&page={}", query, search_results.safe_search_level, if page > 1 {page-1} else {1})) {
(PreEscaped("&#8592;")) "previous" (PreEscaped("&#8592;")) "previous"
} }
button type="button" onclick="navigate_forward()"{"next" (PreEscaped("&#8594;"))} a href=(format!("/search?q={}&safesearch={}&page={}", query, search_results.safe_search_level, page+2)) {
"next" (PreEscaped("&#8594;"))}
} }
} }
script src="static/index.js"{} script src="static/index.js"{}
script src="static/search_area_options.js"{}
script src="static/pagination.js"{}
script src="static/error_box.js"{} script src="static/error_box.js"{}
(footer()) (footer())
) )