Add debug copy button and functionality

Includes a button for administrators to copy all transcripts and the
document markdown to the clipboard.
The data is embedded as JSON in a script tag and pre-sanitized to
prevent
`</script>` tag injection.
The JavaScript handles copying to the clipboard using the modern
Clipboard API,
with a fallback for older browsers.
This commit is contained in:
2026-05-03 12:13:12 +02:00
parent 5ee276ba1d
commit bf6464d7e1
2 changed files with 86 additions and 3 deletions
+52
View File
@@ -400,6 +400,15 @@
<input type="hidden" name="return_to" value="/web/cases/{{ case_id }}">
<button type="submit">Reset</button>
</form>
<button
type="button"
id="debug-copy-btn"
class="admin-only"
title="Alle Transkripte + Dokument-Markdown in die Zwischenablage"
>Debug-Copy</button>
<script type="application/json" id="debug-copy-data">
{{ debug_copy_json|safe }}
</script>
{% endif %}
</div>
@@ -604,5 +613,48 @@
<script>
{% include "partials/oneliner_edit.js" %}
</script>
{% if is_admin %}
<script>
(() => {
const btn = document.getElementById("debug-copy-btn");
const data = document.getElementById("debug-copy-data");
if (!btn || !data) return;
let payload;
try {
payload = JSON.parse(data.textContent);
} catch (_) {
return;
}
btn.addEventListener("click", async () => {
const parts = [...(payload.transcripts || [])];
if (payload.document) parts.push(payload.document);
const text = parts.join("\n\n---\n\n");
let ok = false;
try {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(text);
ok = true;
}
} catch (_) {}
if (!ok) {
const ta = document.createElement("textarea");
ta.value = text;
ta.setAttribute("readonly", "");
ta.style.position = "fixed";
ta.style.top = "-1000px";
document.body.appendChild(ta);
ta.select();
try { ok = document.execCommand("copy"); } catch (_) {}
ta.remove();
}
if (ok) {
const original = btn.textContent;
btn.textContent = "Kopiert!";
setTimeout(() => { btn.textContent = original; }, 1500);
}
});
})();
</script>
{% endif %}
</body>
</html>