added feature to copy to clipboard
This commit is contained in:
10
popup.css
10
popup.css
@@ -305,9 +305,17 @@ button:active {
|
||||
|
||||
.footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 6px;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.footer-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.link {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<header class="title-block">
|
||||
<div class="title-line">
|
||||
<span class="title">WWCompanion</span>
|
||||
<span class="subtitle">Manual reasoning for WaterlooWorks</span>
|
||||
<span class="subtitle">AI companion for WaterlooWorks.</span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -43,6 +43,10 @@
|
||||
</section>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="footer-left">
|
||||
<button id="copyRenderedBtn" class="ghost" type="button">Copy</button>
|
||||
<button id="copyRawBtn" class="ghost" type="button">Copy Markdown</button>
|
||||
</div>
|
||||
<button id="settingsBtn" class="link">Open Settings</button>
|
||||
</footer>
|
||||
|
||||
|
||||
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