Skip to content

Commit 8ef8fd6

Browse files
simonwclaude
andauthored
Auto-decode URL-encoded content pasted into Gemini Prompt (#234)
Adds a paste event listener on the Content textarea that detects URL-encoded text (containing %XX hex sequences) and automatically decodes it via decodeURIComponent. Falls back to normal paste if decoding fails (malformed sequences). https://claude.ai/code/session_013F3xkvp8LebNQ9wPj3d1md Co-authored-by: Claude <noreply@anthropic.com>
1 parent 18cd012 commit 8ef8fd6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

gemini-prompt.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,28 @@ <h1>Gemini Prompt</h1>
518518
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') submit();
519519
});
520520

521+
// ── Auto-decode URL-encoded paste ───────────────────────────────────────
522+
document.getElementById('content').addEventListener('paste', e => {
523+
const text = e.clipboardData?.getData('text');
524+
if (!text) return;
525+
if (/%[0-9A-Fa-f]{2}/.test(text)) {
526+
try {
527+
const decoded = decodeURIComponent(text);
528+
if (decoded !== text) {
529+
e.preventDefault();
530+
const ta = e.target;
531+
const start = ta.selectionStart;
532+
const end = ta.selectionEnd;
533+
ta.value = ta.value.slice(0, start) + decoded + ta.value.slice(end);
534+
const cursor = start + decoded.length;
535+
ta.selectionStart = ta.selectionEnd = cursor;
536+
}
537+
} catch {
538+
// malformed URI sequence — let the normal paste go through
539+
}
540+
}
541+
});
542+
521543
// ── Init ───────────────────────────────────────────────────────────────────
522544
(function init() {
523545
const hist = loadHistory();

0 commit comments

Comments
 (0)