|
234 | 234 | font-size: 0.9rem; |
235 | 235 | } |
236 | 236 |
|
| 237 | + /* API key row */ |
| 238 | + #api-key-row { |
| 239 | + display: none; |
| 240 | + margin-bottom: 16px; |
| 241 | + } |
| 242 | + |
| 243 | + #change-api-key-btn { |
| 244 | + background: none; |
| 245 | + border: 1px solid #d1d5db; |
| 246 | + color: #6b7280; |
| 247 | + font-size: 0.8rem; |
| 248 | + padding: 4px 10px; |
| 249 | + border-radius: 5px; |
| 250 | + } |
| 251 | + #change-api-key-btn:hover { |
| 252 | + border-color: #4f7df3; |
| 253 | + color: #4f7df3; |
| 254 | + background: #eff6ff; |
| 255 | + } |
| 256 | + |
237 | 257 | /* Status */ |
238 | 258 | #status { |
239 | 259 | font-size: 0.8rem; |
240 | 260 | color: #6b7280; |
241 | 261 | margin-top: 8px; |
242 | 262 | height: 1.2em; |
243 | 263 | } |
| 264 | + |
| 265 | + @media (max-width: 600px) { |
| 266 | + .controls-row { |
| 267 | + flex-wrap: wrap; |
| 268 | + } |
| 269 | + #submit-btn { |
| 270 | + width: 100%; |
| 271 | + } |
| 272 | + } |
244 | 273 | </style> |
245 | 274 | </head> |
246 | 275 | <body> |
247 | 276 | <h1>Gemini Prompt</h1> |
248 | 277 |
|
| 278 | + <div id="api-key-row"> |
| 279 | + <button id="change-api-key-btn">Change API key</button> |
| 280 | + </div> |
| 281 | + |
249 | 282 | <label for="system-prompt">System Prompt</label> |
250 | 283 | <textarea id="system-prompt" placeholder="Optional system prompt…"></textarea> |
251 | 284 |
|
@@ -303,15 +336,31 @@ <h1>Gemini Prompt</h1> |
303 | 336 | let showAll = false; |
304 | 337 |
|
305 | 338 | // ── API key ──────────────────────────────────────────────────────────────── |
| 339 | + function updateApiKeyUI() { |
| 340 | + const hasKey = !!localStorage.getItem(STORAGE_KEY_API); |
| 341 | + document.getElementById('api-key-row').style.display = hasKey ? 'block' : 'none'; |
| 342 | + } |
| 343 | + |
306 | 344 | function getApiKey() { |
307 | 345 | let key = localStorage.getItem(STORAGE_KEY_API); |
308 | 346 | if (!key) { |
309 | 347 | key = prompt('Enter your Gemini API key:'); |
310 | | - if (key) localStorage.setItem(STORAGE_KEY_API, key.trim()); |
| 348 | + if (key) { |
| 349 | + localStorage.setItem(STORAGE_KEY_API, key.trim()); |
| 350 | + updateApiKeyUI(); |
| 351 | + } |
311 | 352 | } |
312 | 353 | return key; |
313 | 354 | } |
314 | 355 |
|
| 356 | + document.getElementById('change-api-key-btn').addEventListener('click', () => { |
| 357 | + const key = prompt('Enter your new Gemini API key:'); |
| 358 | + if (key && key.trim()) { |
| 359 | + localStorage.setItem(STORAGE_KEY_API, key.trim()); |
| 360 | + updateApiKeyUI(); |
| 361 | + } |
| 362 | + }); |
| 363 | + |
315 | 364 | // ── System prompt history ───────────────────────────────────────────────── |
316 | 365 | function loadHistory() { |
317 | 366 | try { return JSON.parse(localStorage.getItem(STORAGE_KEY_HIST) || '[]'); } |
@@ -476,6 +525,7 @@ <h1>Gemini Prompt</h1> |
476 | 525 | document.getElementById('system-prompt').value = hist[0]; |
477 | 526 | } |
478 | 527 | renderHistory(); |
| 528 | + updateApiKeyUI(); |
479 | 529 | })(); |
480 | 530 | </script> |
481 | 531 | </body> |
|
0 commit comments