added feature to copy to clipboard
This commit is contained in:
10
popup.css
10
popup.css
@@ -305,9 +305,17 @@ button:active {
|
|||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link {
|
.link {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<header class="title-block">
|
<header class="title-block">
|
||||||
<div class="title-line">
|
<div class="title-line">
|
||||||
<span class="title">WWCompanion</span>
|
<span class="title">WWCompanion</span>
|
||||||
<span class="subtitle">Manual reasoning for WaterlooWorks</span>
|
<span class="subtitle">AI companion for WaterlooWorks.</span>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@@ -43,6 +43,10 @@
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<footer class="footer">
|
<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>
|
<button id="settingsBtn" class="link">Open Settings</button>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
|||||||
31
popup.js
31
popup.js
@@ -10,6 +10,8 @@ const statusEl = document.getElementById("status");
|
|||||||
const postingCountEl = document.getElementById("postingCount");
|
const postingCountEl = document.getElementById("postingCount");
|
||||||
const promptCountEl = document.getElementById("promptCount");
|
const promptCountEl = document.getElementById("promptCount");
|
||||||
const settingsBtn = document.getElementById("settingsBtn");
|
const settingsBtn = document.getElementById("settingsBtn");
|
||||||
|
const copyRenderedBtn = document.getElementById("copyRenderedBtn");
|
||||||
|
const copyRawBtn = document.getElementById("copyRawBtn");
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
postingText: "",
|
postingText: "",
|
||||||
@@ -432,11 +434,40 @@ function handleAbort() {
|
|||||||
setStatus("Aborted.");
|
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);
|
extractBtn.addEventListener("click", handleExtract);
|
||||||
analyzeBtn.addEventListener("click", handleAnalyze);
|
analyzeBtn.addEventListener("click", handleAnalyze);
|
||||||
extractRunBtn.addEventListener("click", handleExtractAndAnalyze);
|
extractRunBtn.addEventListener("click", handleExtractAndAnalyze);
|
||||||
abortBtn.addEventListener("click", handleAbort);
|
abortBtn.addEventListener("click", handleAbort);
|
||||||
settingsBtn.addEventListener("click", () => chrome.runtime.openOptionsPage());
|
settingsBtn.addEventListener("click", () => chrome.runtime.openOptionsPage());
|
||||||
|
copyRenderedBtn.addEventListener("click", handleCopyRendered);
|
||||||
|
copyRawBtn.addEventListener("click", handleCopyRaw);
|
||||||
|
|
||||||
updatePostingCount();
|
updatePostingCount();
|
||||||
updatePromptCount(0);
|
updatePromptCount(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user