Skip to content

Commit fa35a1b

Browse files
committed
added password masking to /examples/openai.html
1 parent 831f950 commit fa35a1b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

examples/openai.html

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ <h3>Settings</h3>
8181
placeholder="">You are a helpful assistant. Answer the user's questions but say 'I don't know that' if you don't know the answer.</textarea>
8282
<label for="apiKey">API Key</label>
8383
<input type="text" id="apiKey" name="apiKey"
84-
placeholder="sk-01234-put-your-api-key-here. It-is-not-stored-on-any-server.">
84+
placeholder="sk-01234-put-your-api-key-here. It-is-not-stored-on-any-server."
85+
onblur="maskInput()" onfocus="unmaskInput()">
8586
<label for="baseUrl">Base URL (optional):</label>
8687
<input type="text" id="baseUrl" name="baseUrl"
8788
placeholder="https://api.openai.com/v1/chat/completions"
@@ -196,6 +197,20 @@ <h3 class="mb-0">Chat</h3>
196197
//}
197198
);
198199

200+
// Mask the API key input
201+
function maskInput() {
202+
var input = document.getElementById("apiKey");
203+
if (input.value !== "") {
204+
input.type = "password"; // Change to password to show bullets
205+
}
206+
}
207+
208+
// Unmask the API key input
209+
function unmaskInput() {
210+
var input = document.getElementById("apiKey");
211+
input.type = "text"; // Change back to text to show input and placeholder
212+
}
213+
199214
// set remember the api key to a local cookie
200215
document.getElementById('settingsForm').addEventListener('submit', function (e) {
201216
e.preventDefault();
@@ -220,6 +235,7 @@ <h3 class="mb-0">Chat</h3>
220235
}
221236
if (name.trim() === 'apiKey') {
222237
document.getElementById('apiKey').value = decodeURIComponent(value);
238+
maskInput();
223239
}
224240
if (name.trim() === 'baseUrl') {
225241
document.getElementById('baseUrl').value = decodeURIComponent(value);
@@ -244,10 +260,10 @@ <h3 class="mb-0">Chat</h3>
244260

245261
// Export chat history and prompt to a text file
246262
document.getElementById('exportChatAndPrompt').addEventListener('click', function () {
247-
const exportData = {}
248-
exportData["history"]= chatInstance.historyGetAllCopy();
263+
const exportData = {}
264+
exportData["history"] = chatInstance.historyGetAllCopy();
249265
exportData["prompt"] = document.getElementById('prompt').value;
250-
266+
251267
const blob = new Blob([JSON.stringify(exportData, null, 2)], { type: 'application/json' });
252268
const url = URL.createObjectURL(blob);
253269
const dateTime = new Date().toISOString().replace(/[:.]/g, '-');

0 commit comments

Comments
 (0)