From a005c2803ffe8996499aef6cc55748ae717775fa Mon Sep 17 00:00:00 2001 From: wearrrrr Date: Sun, 21 Jan 2024 06:05:44 -0600 Subject: [PATCH] =?UTF-8?q?Properly=20add=20custom=20searxng=20url=20suppo?= =?UTF-8?q?rt=20=F0=9F=8E=89=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Dropdown.astro | 2 + src/components/SettingsTablist.astro | 64 +++++++++++++++++++--------- src/components/UVRegistrar.astro | 9 +++- 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/components/Dropdown.astro b/src/components/Dropdown.astro index 0f79859..355006d 100644 --- a/src/components/Dropdown.astro +++ b/src/components/Dropdown.astro @@ -46,6 +46,8 @@ const { buttonNameDefault, dropdownList, id } = Astro.props; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; background-color: #212121; + position: fixed; + width: 140px; } .dropdown-item { border-bottom: 1px solid #4d4d4d; diff --git a/src/components/SettingsTablist.astro b/src/components/SettingsTablist.astro index d9a9c52..7ee02e3 100644 --- a/src/components/SettingsTablist.astro +++ b/src/components/SettingsTablist.astro @@ -66,7 +66,6 @@ import Input from "./Input.astro"; document.addEventListener("astro:before-swap", () => { window.currentlySelectedTab = "" document.removeEventListener('setting-tabChange', determineListener) - document.removeEventListener('setting-tabLoad', setLocalStorageItem) }) window.currentlySelectedTab; window.loadedContentStorage = {} @@ -158,38 +157,53 @@ import Input from "./Input.astro"; }) } + function applyInputListeners(item, localStorageItem) { + item.addEventListener('input', () => { + localStorage.setItem(localStorageItem, item.value) + }) + } + document.addEventListener('setting-tabChange', determineListener) loadContent('setting-tab-proxy') function setupSettings(event) { if (event.detail == "setting-tab-proxy") { - applySavedLocalStorage('selectedProxy', 'dropdown__selected-proxy'); - applySavedLocalStorage('alu__search_engine', 'dropdown__search-engine'); - applySavedLocalStorage("selectedOpenWith", 'dropdown__open-with'); - let selectedProxyDropdown = document.getElementById('dropdown__selected-proxy-menu') - let searchEngineDropdown = document.getElementById('dropdown__search-engine-menu') - let openWithDropdown = document.getElementById('dropdown__open-with-menu') - let bareUrlInput = document.getElementById('bare-url-input') - bareUrlInput.addEventListener('change', () => { - localStorage.setItem('bareUrl', bareUrlInput.value) - }) - applyDropdownEventListeners(searchEngineDropdown, 'dropdown__search-engine', 'alu__search_engine', checkSearxng); - applyDropdownEventListeners(selectedProxyDropdown, 'dropdown__selected-proxy', 'selectedProxy'); - applyDropdownEventListeners(openWithDropdown, 'dropdown__open-with', 'selectedOpenWith'); - if (localStorage.getItem('bareUrl')) { - bareUrlInput.value = localStorage.getItem('bareUrl') - } else { - bareUrlInput.value = '/bare/' - } - + applySavedLocalStorage('alu__selectedProxy', 'dropdown__selected-proxy'); + applySavedLocalStorage('alu__search_engine', 'dropdown__search-engine'); + applySavedLocalStorage("alu__selectedOpenWith", 'dropdown__open-with'); + let selectedProxyDropdown = document.getElementById('dropdown__selected-proxy-menu') + let searchEngineDropdown = document.getElementById('dropdown__search-engine-menu') + let openWithDropdown = document.getElementById('dropdown__open-with-menu') + let bareUrlInput = document.getElementById('bare-url-input') + let searxngUrlInput = document.getElementById('searxng-url-input') + let savedSearxngUrl = localStorage.getItem("alu__searxngUrl") + if (savedSearxngUrl != undefined) { + if (savedSearxngUrl == "") localStorage.setItem("alu__searxngUrl", "https://searxng.site/") + searxngUrlInput.value = localStorage.getItem("alu__searxngUrl") + } + applyInputListeners(bareUrlInput, 'alu__bareUrl') + applyInputListeners(searxngUrlInput, 'alu__searxngUrl') + applyDropdownEventListeners(searchEngineDropdown, 'dropdown__search-engine', 'alu__search_engine', checkSearxng); + applyDropdownEventListeners(selectedProxyDropdown, 'dropdown__selected-proxy', 'alu__selectedProxy'); + applyDropdownEventListeners(openWithDropdown, 'dropdown__open-with', 'alu__selectedOpenWith'); + if (localStorage.getItem('bareUrl')) { + bareUrlInput.value = localStorage.getItem('bareUrl') + } else { + bareUrlInput.value = '/bare/' + } + checkSearxng(); } } function checkSearxng() { // This function checks if the "searxng" option was clicked, display an additional option if so. if (localStorage.getItem("alu__search_engine")) { - + if (localStorage.getItem("alu__search_engine").toLowerCase() == "searx") { + document.getElementsByClassName('setting__searxng-url')[0].style.opacity = '1' + } else { + document.getElementsByClassName('setting__searxng-url')[0].style.opacity = '0' + } } } @@ -206,11 +220,19 @@ import Input from "./Input.astro"; .settings-container { display: flex; gap: 20px; + position: relative; + z-index: 2; } .setting-label { color: white; font-size: 18px; } + +.setting__searxng-url { + margin-top: 10px; + opacity: 0; + transition: opacity 250ms ease-in-out; +} label { font-size: 24px; font-weight: 700; diff --git a/src/components/UVRegistrar.astro b/src/components/UVRegistrar.astro index b60148b..705e28c 100644 --- a/src/components/UVRegistrar.astro +++ b/src/components/UVRegistrar.astro @@ -63,7 +63,14 @@ return "https://search.brave.com/search?q="; } case "searx": { - return "https://searxng.site/search?q="; + let localStorageURL = localStorage.getItem("alu__searxngUrl"); + if (localStorageURL) { + if (localStorageURL == "") return "https://searxng.site/search?q="; + // Ugly hack to remove the trailing slash :) + if (localStorageURL.endsWith("/")) localStorageURL = localStorageURL.slice(0, -1); + return localStorageURL + "/search?q="; + } + else return "https://searxng.site/search?q="; } default: { return "https://google.com/search?q="