Skip to content

Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.

Add AI API key field visibility toggle (#998)

LumiDevf3ab48360cce
diff --git a/scripts/settings.js b/scripts/settings.js
index 9713a62..9beab1e 100644
--- a/scripts/settings.js
+++ b/scripts/settings.js
@@ -877,6 +877,10 @@ document.addEventListener('DOMContentLoaded', function () {
});
});
+ if (document.getElementById("ai_type")) {
+ toggleAiInputs();
+ }
+
});
function addFixerKeyButton() {
@@ -1079,17 +1083,52 @@ function fetch_ai_models() {
function toggleAiInputs() {
const aiTypeSelect = document.getElementById("ai_type");
const apiKeyInput = document.getElementById("ai_api_key");
+ const apiKeyToggleButton = document.getElementById("toggleAiApiKey");
+ const apiKeyToggleIcon = apiKeyToggleButton ? apiKeyToggleButton.querySelector("i") : null;
const ollamaHostInput = document.getElementById("ai_ollama_host");
const type = aiTypeSelect.value;
if (type === "ollama") {
apiKeyInput.classList.add("hidden");
+ if (apiKeyToggleButton) {
+ apiKeyToggleButton.classList.add("hidden");
+ }
+ apiKeyInput.type = "password";
+ if (apiKeyToggleIcon) {
+ apiKeyToggleIcon.classList.remove("fa-eye-slash");
+ apiKeyToggleIcon.classList.add("fa-eye");
+ }
ollamaHostInput.classList.remove("hidden");
} else {
apiKeyInput.classList.remove("hidden");
+ if (apiKeyToggleButton) {
+ apiKeyToggleButton.classList.remove("hidden");
+ }
+ apiKeyInput.type = "password";
+ if (apiKeyToggleIcon) {
+ apiKeyToggleIcon.classList.remove("fa-eye-slash");
+ apiKeyToggleIcon.classList.add("fa-eye");
+ }
ollamaHostInput.classList.add("hidden");
}
}
+function toggleAiApiKeyVisibility() {
+ const apiKeyInput = document.getElementById("ai_api_key");
+ const apiKeyToggleButton = document.getElementById("toggleAiApiKey");
+ if (!apiKeyInput || !apiKeyToggleButton) {
+ return;
+ }
+
+ const icon = apiKeyToggleButton.querySelector("i");
+ const isPassword = apiKeyInput.type === "password";
+ apiKeyInput.type = isPassword ? "text" : "password";
+
+ if (icon) {
+ icon.classList.toggle("fa-eye", !isPassword);
+ icon.classList.toggle("fa-eye-slash", isPassword);
+ }
+}
+
function saveAiSettingsButton() {
const aiEnabled = document.querySelector("#ai_enabled").checked;
const aiType = document.querySelector("#ai_type").value;
diff --git a/settings.php b/settings.php
index bad289d..9410de7 100644
--- a/settings.php
+++ b/settings.php
@@ -1093,10 +1093,13 @@ $userData['currency_symbol'] = $currencies[$main_currency]['symbol'];
</select>
</div>
<div class="form-group-inline">
- <input type="text" id="ai_api_key" name="ai_api_key" autocomplete="off"
+ <input type="password" id="ai_api_key" name="ai_api_key" autocomplete="off"
class="<?= (isset($aiSettings['type']) && $aiSettings['type'] == 'ollama') ? 'hidden' : '' ?>"
placeholder="<?= translate('api_key', $i18n) ?>"
value="<?= isset($aiSettings['api_key']) ? htmlspecialchars($aiSettings['api_key']) : '' ?>" />
+ <button type="button" id="toggleAiApiKey" class="button tiny <?= (isset($aiSettings['type']) && $aiSettings['type'] == 'ollama') ? 'hidden' : '' ?>" onclick="toggleAiApiKeyVisibility()" aria-label="Toggle API key visibility">
+ <i class="fa-solid fa-eye"></i>
+ </button>
<input type="text" id="ai_ollama_host" name="ai_ollama_host" autocomplete="off"
class="<?= (!isset($aiSettings['type']) || $aiSettings['type'] != 'ollama') ? 'hidden' : '' ?>"
placeholder="<?= translate('host', $i18n) ?>"