SearXNG Changes

This revision is from 2024/08/12 09:51. You can Restore it.

Add HTML5 tag required

/searx/templates/search.html and /searx/templates/simple_search.html

     

<input id="q" name="q" type="text" placeholder="{{ _('Search for...') }}" autocomplete="off" autocapitalize="none" spellcheck="false" autocorrect="off" dir="auto" value="{{ q or '' }}" required>

Adding the required tag will also add a input box hover tooltip. In google, pushing the search button with no query gives trending topics.

Disable search button while no query or input box is empty

/searx/static/themes/simple/css/searxng.min.css

<style>

#send_search:disabled,

.category_button:disabled {

pointer-events: none;

opacity: 0.5; /* Optionally, to visually indicate the disabled state */

}

</style>

/searx/static/themes/simple/js/searxng.min.js

<script>

document.addEventListener('DOMContentLoaded', function() {

const searchInput = document.getElementById('q');

const searchButton = document.getElementById('send_search');

const clearButton = document.getElementById('clear_search');

const form = document.getElementById('search');

const categoryButtons = document.querySelectorAll('.category_button');

// Function to toggle the search button state

function toggleSearchButton() {

const isInputEmpty = searchInput.value.trim() === '';

searchButton.disabled = isInputEmpty;

toggleCategoryButtons(isInputEmpty);

}

// Function to toggle the state of all category buttons

function toggleCategoryButtons(isDisabled) {

categoryButtons.forEach(button => {

button.disabled = isDisabled;

});

}

// Add input event listener to toggle the search and category buttons

searchInput.addEventListener('input', toggleSearchButton);

// Add click event listener to the clear button

clearButton.addEventListener('click', function() {

// Clear the input

searchInput.value = '';

// Disable the search and category buttons

toggleSearchButton();

});

// Add reset event listener to the form

form.addEventListener('reset', function() {

// Delay to allow the reset to complete

setTimeout(toggleSearchButton, 0);

});

// Initial check in case there's a pre-filled value

toggleSearchButton();

});

</script>

Bug Fix (x does not appear when using mouse only)

/searx/static/themes/simple/js/searxng.min.js

function a(t){

var e=document.getElementById("clear_search");

var n=function(){

if(t.value.length===0){

e.classList.add("empty")

}else{

e.classList.remove("empty")

}

};

n();

e.addEventListener("click",function(e){

t.value="";

t.focus();

n();

e.preventDefault()

});

t.addEventListener("keyup",n,false); // Replace this line

t.addEventListener("input",n,false); // with this line to handle paste events

}

  

📝 📜 ⏱️ ⬆️