added feature to copy to clipboard
This commit is contained in:
31
popup.js
31
popup.js
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user