Hacking searx

This revision is from 2024/08/06 23:51. You can Restore it.

In no specific order...

I want to add a new checkbox for the custom_option. I direct preferences.html to the the preferences folder and then add a new template for the option.

Update the preferences UI: searx/templates/preferences/custom_option.html, simply copy center_alignment.html and rename it to custom_option.html for this exercise.

<fieldset>{{- '' -}}

<legend id="pref_custom_option">{{ _('Custom Option Language') }}</legend>{{- '' -}}

<p class="value">{{- '' -}}

<input type="checkbox" {{- ' ' -}}

name="custom_option" {{- ' ' -}}

aria-labelledby="pref_custom_option" {{- ' ' -}}

class="checkbox-onoff" {{- ' ' -}}

{%- if preferences.get_value('center_alignment') -%}

checked

{%- endif -%}{{- ' ' -}}

/>{{- '' -}}

</p>{{- '' -}}

<div class="description">

{{- _('Displays my cock (Oscar layout).') -}}

</div>{{- '' -}}

</fieldset>{{- '' -}}

Add the custom template to preferences.html: searx/templates/preferences.html, for example line 197 slot in...

{%- if 'custom_option' not in locked_preferences -%}

{%- include 'simple/preferences/custom_option.html' -%}

{%- endif -%}

Open searx/settings.yml and add a new preference option.

user_preferences:

test_option:

type: bool

default: false

description: "Enable test output"

Find the place to install it... for instance, searx/search/search.py

Find the function where search results are processed (e.g., _get_search_result_container).

Add logic...

def _get_search_result_container(self, request, selected_engines):

if request.preferences['test_option']:

results.append({'title': 'Test Output', 'content': 'this is a test'})

  

📝 📜 ⏱️ ⬆️