added feature to copy to clipboard

This commit is contained in:
2026-01-16 23:07:44 -05:00
parent 2f7d1acaa9
commit 743b83deb3
3 changed files with 45 additions and 2 deletions

View File

@@ -10,6 +10,8 @@ const statusEl = document.getElementById("status");
const postingCountEl = document.getElementById("postingCount");
const promptCountEl = document.getElementById("promptCount");
const settingsBtn = document.getElementById("settingsBtn");
const copyRenderedBtn = document.getElementById("copyRenderedBtn");
const copyRawBtn = document.getElementById("copyRawBtn");
const state = {
postingText: "",
@@ -432,11 +434,40 @@ function handleAbort() {
setStatus("Aborted.");
}
async function copyTextToClipboard(text, label) {
try {
await navigator.clipboard.writeText(text);
setStatus(`${label} copied.`);
} catch (error) {
setStatus(`Unable to copy ${label.toLowerCase()}.`);
}
}
function handleCopyRendered() {
const text = outputEl.innerText || "";
if (!text.trim()) {
setStatus("Nothing to copy.");
return;
}
void copyTextToClipboard(text, "Output");
}
function handleCopyRaw() {
const text = state.outputRaw || "";
if (!text.trim()) {
setStatus("Nothing to copy.");
return;
}
void copyTextToClipboard(text, "Markdown");
}
extractBtn.addEventListener("click", handleExtract);
analyzeBtn.addEventListener("click", handleAnalyze);
extractRunBtn.addEventListener("click", handleExtractAndAnalyze);
abortBtn.addEventListener("click", handleAbort);
settingsBtn.addEventListener("click", () => chrome.runtime.openOptionsPage());
copyRenderedBtn.addEventListener("click", handleCopyRendered);
copyRawBtn.addEventListener("click", handleCopyRaw);
updatePostingCount();
updatePromptCount(0);