fix language/safe search gui
This commit is contained in:
parent
8fece91f75
commit
6b3373f7d6
13 changed files with 748 additions and 694 deletions
44
files.go
44
files.go
|
@ -59,27 +59,31 @@ func handleFileSearch(w http.ResponseWriter, settings UserSettings, query string
|
||||||
}
|
}
|
||||||
|
|
||||||
data := struct {
|
data := struct {
|
||||||
Results []TorrentResult
|
Results []TorrentResult
|
||||||
Query string
|
Query string
|
||||||
Fetched string
|
Fetched string
|
||||||
Category string
|
Category string
|
||||||
Sort string
|
Sort string
|
||||||
HasPrevPage bool
|
Page int
|
||||||
HasNextPage bool
|
HasPrevPage bool
|
||||||
Page int
|
HasNextPage bool
|
||||||
Settings Settings
|
LanguageOptions []LanguageOption
|
||||||
Theme string
|
CurrentLang string
|
||||||
|
Theme string
|
||||||
|
Safe string
|
||||||
}{
|
}{
|
||||||
Results: combinedResults,
|
Results: combinedResults,
|
||||||
Query: query,
|
Query: query,
|
||||||
Fetched: fmt.Sprintf("%.2f", elapsedTime.Seconds()),
|
Fetched: fmt.Sprintf("%.2f seconds", elapsedTime.Seconds()),
|
||||||
Category: "all",
|
Category: "all",
|
||||||
Sort: "seed",
|
Sort: "seed",
|
||||||
HasPrevPage: page > 1,
|
Page: page,
|
||||||
HasNextPage: len(combinedResults) > 0,
|
HasPrevPage: page > 1,
|
||||||
Page: page,
|
HasNextPage: len(combinedResults) > 0,
|
||||||
Settings: Settings{UxLang: settings.Language, Safe: settings.SafeSearch}, // Now this is painful, are there two Settings variables??
|
LanguageOptions: languageOptions,
|
||||||
Theme: settings.Theme,
|
CurrentLang: settings.Language,
|
||||||
|
Theme: settings.Theme,
|
||||||
|
Safe: settings.SafeSearch,
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Debugging: Print results before rendering template
|
// // Debugging: Print results before rendering template
|
||||||
|
|
10
forums.go
10
forums.go
|
@ -108,21 +108,23 @@ func handleForumsSearch(w http.ResponseWriter, settings UserSettings, query stri
|
||||||
data := struct {
|
data := struct {
|
||||||
Query string
|
Query string
|
||||||
Results []ForumSearchResult
|
Results []ForumSearchResult
|
||||||
LanguageOptions []LanguageOption
|
|
||||||
CurrentLang string
|
|
||||||
Page int
|
Page int
|
||||||
HasPrevPage bool
|
HasPrevPage bool
|
||||||
HasNextPage bool
|
HasNextPage bool
|
||||||
|
LanguageOptions []LanguageOption
|
||||||
|
CurrentLang string
|
||||||
Theme string
|
Theme string
|
||||||
|
Safe string
|
||||||
}{
|
}{
|
||||||
Query: query,
|
Query: query,
|
||||||
Results: results,
|
Results: results,
|
||||||
LanguageOptions: languageOptions,
|
|
||||||
CurrentLang: settings.Language,
|
|
||||||
Page: page,
|
Page: page,
|
||||||
HasPrevPage: page > 1,
|
HasPrevPage: page > 1,
|
||||||
HasNextPage: len(results) == 25,
|
HasNextPage: len(results) == 25,
|
||||||
|
LanguageOptions: languageOptions,
|
||||||
|
CurrentLang: settings.Language,
|
||||||
Theme: settings.Theme,
|
Theme: settings.Theme,
|
||||||
|
Safe: settings.SafeSearch,
|
||||||
}
|
}
|
||||||
|
|
||||||
funcMap := template.FuncMap{
|
funcMap := template.FuncMap{
|
||||||
|
|
10
images.go
10
images.go
|
@ -37,23 +37,25 @@ func handleImageSearch(w http.ResponseWriter, settings UserSettings, query strin
|
||||||
Query string
|
Query string
|
||||||
Page int
|
Page int
|
||||||
Fetched string
|
Fetched string
|
||||||
LanguageOptions []LanguageOption
|
|
||||||
CurrentLang string
|
|
||||||
HasPrevPage bool
|
HasPrevPage bool
|
||||||
HasNextPage bool
|
HasNextPage bool
|
||||||
NoResults bool
|
NoResults bool
|
||||||
|
LanguageOptions []LanguageOption
|
||||||
|
CurrentLang string
|
||||||
Theme string
|
Theme string
|
||||||
|
Safe string
|
||||||
}{
|
}{
|
||||||
Results: combinedResults,
|
Results: combinedResults,
|
||||||
Query: query,
|
Query: query,
|
||||||
Page: page,
|
Page: page,
|
||||||
Fetched: fmt.Sprintf("%.2f seconds", elapsedTime.Seconds()),
|
Fetched: fmt.Sprintf("%.2f seconds", elapsedTime.Seconds()),
|
||||||
LanguageOptions: languageOptions,
|
|
||||||
CurrentLang: settings.Language,
|
|
||||||
HasPrevPage: page > 1,
|
HasPrevPage: page > 1,
|
||||||
HasNextPage: len(combinedResults) >= 50,
|
HasNextPage: len(combinedResults) >= 50,
|
||||||
NoResults: len(combinedResults) == 0,
|
NoResults: len(combinedResults) == 0,
|
||||||
|
LanguageOptions: languageOptions,
|
||||||
|
CurrentLang: settings.Language,
|
||||||
Theme: settings.Theme,
|
Theme: settings.Theme,
|
||||||
|
Safe: settings.SafeSearch,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tmpl.Execute(w, data)
|
err = tmpl.Execute(w, data)
|
||||||
|
|
14
main.go
14
main.go
|
@ -92,9 +92,21 @@ func handleSearch(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the search page template if no query
|
// Render the search page template if no query
|
||||||
|
|
||||||
|
data := struct {
|
||||||
|
LanguageOptions []LanguageOption
|
||||||
|
CurrentLang string
|
||||||
|
Theme string
|
||||||
|
Safe string
|
||||||
|
}{
|
||||||
|
LanguageOptions: languageOptions,
|
||||||
|
CurrentLang: settings.Language,
|
||||||
|
Theme: settings.Theme,
|
||||||
|
Safe: settings.SafeSearch,
|
||||||
|
}
|
||||||
if query == "" {
|
if query == "" {
|
||||||
tmpl := template.Must(template.ParseFiles("templates/search.html"))
|
tmpl := template.Must(template.ParseFiles("templates/search.html"))
|
||||||
tmpl.Execute(w, settings)
|
tmpl.Execute(w, data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
map.go
1
map.go
|
@ -59,6 +59,7 @@ func handleMapSearch(w http.ResponseWriter, settings UserSettings, query string)
|
||||||
"Longitude": longitude,
|
"Longitude": longitude,
|
||||||
"Found": found,
|
"Found": found,
|
||||||
"Theme": settings.Theme,
|
"Theme": settings.Theme,
|
||||||
|
"Safe": settings.SafeSearch,
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles("templates/map.html")
|
tmpl, err := template.ParseFiles("templates/map.html")
|
||||||
|
|
2
templates/files.html
Normal file → Executable file
2
templates/files.html
Normal file → Executable file
|
@ -67,7 +67,7 @@
|
||||||
<option value="software" {{ if eq .Category "software" }} selected {{ end }}>Software</option>
|
<option value="software" {{ if eq .Category "software" }} selected {{ end }}>Software</option>
|
||||||
<option value="anime" {{ if eq .Category "anime" }} selected {{ end }}>Anime</option>
|
<option value="anime" {{ if eq .Category "anime" }} selected {{ end }}>Anime</option>
|
||||||
<option value="music" {{ if eq .Category "music" }} selected {{ end }}>Music</option>
|
<option value="music" {{ if eq .Category "music" }} selected {{ end }}>Music</option>
|
||||||
{{ if eq .Settings.Safe "inactive" }}
|
{{ if eq .Safe "disabled" }}
|
||||||
<option value="xxx" {{ if eq .Category "xxx" }} selected {{ end }}>XXX (18+)</option>
|
<option value="xxx" {{ if eq .Category "xxx" }} selected {{ end }}>XXX (18+)</option>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</select>
|
</select>
|
||||||
|
|
4
templates/forums.html
Normal file → Executable file
4
templates/forums.html
Normal file → Executable file
|
@ -48,8 +48,8 @@
|
||||||
<form class="results_settings" action="/search" method="get">
|
<form class="results_settings" action="/search" method="get">
|
||||||
<input type="hidden" name="q" value="{{ .Query }}">
|
<input type="hidden" name="q" value="{{ .Query }}">
|
||||||
<select class="results-settings" name="safe" id="safeSearchSelect">
|
<select class="results-settings" name="safe" id="safeSearchSelect">
|
||||||
<option value="">Safe Search Off</option>
|
<option value="disabled" {{if eq .Safe "disabled"}}selected{{end}}>Safe Search Off</option>
|
||||||
<option value="active">Safe Search On</option>
|
<option value="active" {{if eq .Safe "active"}}selected{{end}}>Safe Search On</option>
|
||||||
</select>
|
</select>
|
||||||
<select class="results-settings" name="lang" id="languageSelect">
|
<select class="results-settings" name="lang" id="languageSelect">
|
||||||
{{range .LanguageOptions}}
|
{{range .LanguageOptions}}
|
||||||
|
|
4
templates/images.html
Normal file → Executable file
4
templates/images.html
Normal file → Executable file
|
@ -48,8 +48,8 @@
|
||||||
<form class="results_settings" action="/search" method="get">
|
<form class="results_settings" action="/search" method="get">
|
||||||
<input type="hidden" name="q" value="{{ .Query }}">
|
<input type="hidden" name="q" value="{{ .Query }}">
|
||||||
<select class="results-settings" name="safe" id="safeSearchSelect">
|
<select class="results-settings" name="safe" id="safeSearchSelect">
|
||||||
<option value="">Safe Search Off</option>
|
<option value="disabled" {{if eq .Safe "disabled"}}selected{{end}}>Safe Search Off</option>
|
||||||
<option value="active">Safe Search On</option>
|
<option value="active" {{if eq .Safe "active"}}selected{{end}}>Safe Search On</option>
|
||||||
</select>
|
</select>
|
||||||
<select class="results-settings" name="lang" id="languageSelect">
|
<select class="results-settings" name="lang" id="languageSelect">
|
||||||
{{range .LanguageOptions}}
|
{{range .LanguageOptions}}
|
||||||
|
|
46
templates/search.html
Normal file → Executable file
46
templates/search.html
Normal file → Executable file
|
@ -11,6 +11,21 @@
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
// Define the updateSettings function first
|
||||||
|
function updateSettings(settingKey, settingValue) {
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('POST', '/updateSettings', true);
|
||||||
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||||
|
xhr.onload = function () {
|
||||||
|
if (this.status >= 200 && this.status < 300) {
|
||||||
|
console.log('Settings updated successfully!');
|
||||||
|
} else {
|
||||||
|
console.log('Failed to update settings.');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.send(encodeURI(settingKey + '=' + settingValue));
|
||||||
|
}
|
||||||
|
|
||||||
const settingsIcon = document.querySelector('.settings-icon-link-search');
|
const settingsIcon = document.querySelector('.settings-icon-link-search');
|
||||||
const searchMenu = document.querySelector('.search-menu');
|
const searchMenu = document.querySelector('.search-menu');
|
||||||
|
|
||||||
|
@ -26,6 +41,16 @@
|
||||||
document.getElementById('light_theme').addEventListener('click', function () {
|
document.getElementById('light_theme').addEventListener('click', function () {
|
||||||
window.location.href = '/search?theme=light';
|
window.location.href = '/search?theme=light';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Event listener for Safe Search Selection
|
||||||
|
document.getElementById('safeSearchSelect').addEventListener('change', function () {
|
||||||
|
updateSettings('safe', this.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Event listener for Language Selection
|
||||||
|
document.getElementById('languageSelect').addEventListener('change', function () {
|
||||||
|
updateSettings('lang', this.value);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<div class="settings-search-div settings-search-div-search">
|
<div class="settings-search-div settings-search-div-search">
|
||||||
|
@ -34,26 +59,23 @@
|
||||||
<div class="search-menu settings-menu-hidden">
|
<div class="search-menu settings-menu-hidden">
|
||||||
<h2>Settings</h2>
|
<h2>Settings</h2>
|
||||||
<div class="settings-content">
|
<div class="settings-content">
|
||||||
<button id="settingsButton" onclick="window.location.href='/settings'">All settings</button> <!-- Well its unessesary to use js here but this menu will not work without js anyway -->
|
<!-- <button id="settingsButton" onclick="window.location.href='/settings'">All settings</button> Well its unessesary to use js here but this menu will not work without js anyway -->
|
||||||
<div class="theme-settings">
|
<div class="theme-settings">
|
||||||
<p><span class="highlight">Theme: </span> <span id="theme_name">Default Theme</span></p>
|
<p><span class="highlight">Current theme: </span> <span id="theme_name">{{.Theme}}</span></p>
|
||||||
<div class="themes-settings-menu">
|
<div class="themes-settings-menu">
|
||||||
<div><img class="view-image-search clickable" id="dark_theme" alt="Dark Theme" src="/static/images/dark.webp"></div>
|
<div><img class="view-image-search clickable" id="dark_theme" alt="Dark Theme" src="/static/images/dark.webp"></div>
|
||||||
<div><img class="view-image-search clickable" id="light_theme" alt="Light Theme" src="/static/images/light.webp"></div>
|
<div><img class="view-image-search clickable" id="light_theme" alt="Light Theme" src="/static/images/light.webp"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<select class="lang" name="lang">
|
<select class="lang" name="safe" id="safeSearchSelect">
|
||||||
<option value="en" selected>English</option>
|
<option value="disabled" {{if eq .Safe "disabled"}}selected{{end}}>Safe Search Off</option>
|
||||||
<option value="fr">Français</option>
|
<option value="active" {{if eq .Safe "active"}}selected{{end}}>Safe Search On</option>
|
||||||
<option value="es">Español</option>
|
|
||||||
<!-- Add other languages as needed -->
|
|
||||||
</select>
|
</select>
|
||||||
<select class="domain" name="safe">
|
<select class="lang" name="lang" id="languageSelect">
|
||||||
<option value="active" selected>Safe search on</option>
|
{{range .LanguageOptions}}
|
||||||
<option value="">Safe search off</option>
|
<option value="{{.Code}}" {{if eq .Code $.CurrentLang}}selected{{end}}>{{.Name}}</option>
|
||||||
<!-- Add other domains as needed -->
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<form action="/search" class="search-container" method="post" autocomplete="off">
|
<form action="/search" class="search-container" method="post" autocomplete="off">
|
||||||
|
|
4
templates/text.html
Normal file → Executable file
4
templates/text.html
Normal file → Executable file
|
@ -48,8 +48,8 @@
|
||||||
<form class="results_settings" action="/search" method="get">
|
<form class="results_settings" action="/search" method="get">
|
||||||
<input type="hidden" name="q" value="{{ .Query }}">
|
<input type="hidden" name="q" value="{{ .Query }}">
|
||||||
<select class="results-settings" name="safe" id="safeSearchSelect">
|
<select class="results-settings" name="safe" id="safeSearchSelect">
|
||||||
<option value="">Safe Search Off</option>
|
<option value="disabled" {{if eq .Safe "disabled"}}selected{{end}}>Safe Search Off</option>
|
||||||
<option value="active">Safe Search On</option>
|
<option value="active" {{if eq .Safe "active"}}selected{{end}}>Safe Search On</option>
|
||||||
</select>
|
</select>
|
||||||
<select class="results-settings" name="lang" id="languageSelect">
|
<select class="results-settings" name="lang" id="languageSelect">
|
||||||
{{range .LanguageOptions}}
|
{{range .LanguageOptions}}
|
||||||
|
|
10
text.go
10
text.go
|
@ -48,23 +48,25 @@ func HandleTextSearch(w http.ResponseWriter, settings UserSettings, query string
|
||||||
Query string
|
Query string
|
||||||
Page int
|
Page int
|
||||||
Fetched string
|
Fetched string
|
||||||
LanguageOptions []LanguageOption
|
|
||||||
CurrentLang string
|
|
||||||
HasPrevPage bool
|
HasPrevPage bool
|
||||||
HasNextPage bool
|
HasNextPage bool
|
||||||
NoResults bool
|
NoResults bool
|
||||||
|
LanguageOptions []LanguageOption
|
||||||
|
CurrentLang string
|
||||||
Theme string
|
Theme string
|
||||||
|
Safe string
|
||||||
}{
|
}{
|
||||||
Results: combinedResults,
|
Results: combinedResults,
|
||||||
Query: query,
|
Query: query,
|
||||||
Page: page,
|
Page: page,
|
||||||
Fetched: fmt.Sprintf("%.2f seconds", elapsedTime.Seconds()),
|
Fetched: fmt.Sprintf("%.2f seconds", elapsedTime.Seconds()),
|
||||||
LanguageOptions: languageOptions,
|
|
||||||
CurrentLang: settings.Language,
|
|
||||||
HasPrevPage: page > 1,
|
HasPrevPage: page > 1,
|
||||||
HasNextPage: len(combinedResults) >= 50,
|
HasNextPage: len(combinedResults) >= 50,
|
||||||
NoResults: len(combinedResults) == 0,
|
NoResults: len(combinedResults) == 0,
|
||||||
|
LanguageOptions: languageOptions,
|
||||||
|
CurrentLang: settings.Language,
|
||||||
Theme: settings.Theme,
|
Theme: settings.Theme,
|
||||||
|
Safe: settings.SafeSearch,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tmpl.Execute(w, data)
|
err = tmpl.Execute(w, data)
|
||||||
|
|
24
user-settings.go
Normal file → Executable file
24
user-settings.go
Normal file → Executable file
|
@ -37,18 +37,24 @@ func loadUserSettings(r *http.Request) UserSettings {
|
||||||
|
|
||||||
func saveUserSettings(w http.ResponseWriter, settings UserSettings) {
|
func saveUserSettings(w http.ResponseWriter, settings UserSettings) {
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "theme",
|
Name: "theme",
|
||||||
Value: settings.Theme,
|
Value: settings.Theme,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
Secure: true, // Ensure cookie is sent over HTTPS only
|
||||||
|
SameSite: http.SameSiteNoneMode, // Set SameSite to None
|
||||||
})
|
})
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "language",
|
Name: "language",
|
||||||
Value: settings.Language,
|
Value: settings.Language,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
Secure: true, // Ensure cookie is sent over HTTPS only
|
||||||
|
SameSite: http.SameSiteNoneMode, // Set SameSite to None
|
||||||
})
|
})
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "safe",
|
Name: "safe",
|
||||||
Value: settings.SafeSearch,
|
Value: settings.SafeSearch,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
Secure: true, // Ensure cookie is sent over HTTPS only
|
||||||
|
SameSite: http.SameSiteNoneMode, // Set SameSite to None
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
17
video.go
17
video.go
|
@ -166,13 +166,16 @@ func handleVideoSearch(w http.ResponseWriter, settings UserSettings, query strin
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tmpl.Execute(w, map[string]interface{}{
|
err = tmpl.Execute(w, map[string]interface{}{
|
||||||
"Results": results,
|
"Results": results,
|
||||||
"Query": query,
|
"Query": query,
|
||||||
"Fetched": fmt.Sprintf("%.2f seconds", elapsed.Seconds()),
|
"Fetched": fmt.Sprintf("%.2f seconds", elapsed.Seconds()),
|
||||||
"Page": page,
|
"Page": page,
|
||||||
"HasPrevPage": page > 1,
|
"HasPrevPage": page > 1,
|
||||||
"HasNextPage": len(results) > 0, // no
|
"HasNextPage": len(results) > 0,
|
||||||
"Theme": settings.Theme,
|
"LanguageOptions": languageOptions,
|
||||||
|
"CurrentLang": settings.Language,
|
||||||
|
"Theme": settings.Theme,
|
||||||
|
"Safe": settings.SafeSearch,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printErr("Error executing template: %v", err)
|
printErr("Error executing template: %v", err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue