Skip to content

Commit c67d7d1

Browse files
authored
Merge pull request #2 from knktc/add-copy-to-request-body
add a copy button to body area
2 parents dca7bc1 + e84d634 commit c67d7d1

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

templates/main.tmpl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
'source_ip': 'Source IP',
2727
'headers': 'Headers',
2828
'body': 'Body',
29-
'no_body': 'This request has no body.'
29+
'no_body': 'This request has no body.',
30+
'copy': 'Copy',
31+
'copied': 'Copied!'
3032
},
3133
'zh-CN': {
3234
'title': 'Tiny RequestBin',
@@ -46,7 +48,9 @@
4648
'source_ip': '源 IP',
4749
'headers': '标头 (Headers)',
4850
'body': '正文 (Body)',
49-
'no_body': '该请求没有正文。'
51+
'no_body': '该请求没有正文。',
52+
'copy': '复制',
53+
'copied': '已复制!'
5054
}
5155
};
5256

@@ -209,9 +213,17 @@
209213
<h2 class="text-xl font-semibold" data-i18n="body">正文 (Body)</h2>
210214
<svg id="body-chevron" class="w-5 h-5 transform transition-transform" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" /></svg>
211215
</div>
212-
<div id="body-content" class="p-6 transition-all duration-300">
216+
<div id="body-content" class="p-6 transition-all duration-300 relative">
213217
{{if .SelectedRequest.Body}}
214-
<pre class="bg-gray-800 text-white p-4 rounded-md text-sm overflow-x-auto"><code>{{prettyPrintJson .SelectedRequest.Body}}</code></pre>
218+
<div class="relative">
219+
<pre id="body-text" class="bg-gray-800 text-white p-4 rounded-md text-sm overflow-x-auto"><code>{{prettyPrintJson .SelectedRequest.Body}}</code></pre>
220+
<button id="copy-body-btn" class="absolute top-2 right-2 bg-blue-600 hover:bg-blue-700 text-white p-2 rounded-md text-xs transition-colors duration-200 flex items-center gap-1" title="复制正文内容">
221+
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
222+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
223+
</svg>
224+
<span data-i18n="copy">复制</span>
225+
</button>
226+
</div>
215227
{{else}}
216228
<p class="text-gray-500" data-i18n="no_body">该请求没有正文。</p>
217229
{{end}}

0 commit comments

Comments
 (0)