Skip to content

Commit

Permalink
Add a copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
ninegua committed Jun 19, 2021
1 parent ce146e5 commit f621d18
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/bare-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export async function send_message(message, update_status, sleep) {
let canister_id = new Principal(ingress.content.canister_id).toString();
let method_name = ingress.content.method_name;
let reply = await query(canister_id, ingress_content);
update_status(await try_decode(canister_id, method_name, reply));
update_status(await try_decode(canister_id, method_name, reply), true);
} else {
// Update call, handle json format of both nano and dfx
const ingress_content = fromHexString(
Expand Down Expand Up @@ -184,9 +184,12 @@ export async function send_message(message, update_status, sleep) {
continue;
} else {
if (reply.status == "replied") {
update_status(await try_decode(canister_id, method_name, reply));
update_status(
await try_decode(canister_id, method_name, reply),
true
);
} else {
update_status(reply);
update_status(reply, true);
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<style>
#scan,
#send,
#copy,
#video {
margin: 0 auto;
display: block;
Expand Down
26 changes: 20 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,30 @@ function do_send(message) {
send_button.innerHTML = "Sent";
const result = document.getElementById("result");
const pre = document.createElement("pre");
const update_status = (reply) => {
let text = typeof reply == "string" ? reply : stringify(reply, null, 2);
pre.innerText = text;
};
pre.id = "status";
pre.onclick = () => {
pre.select();
const copy_button = document.createElement("button");
copy_button.id = "copy";
copy_button.innerHTML = "Copy";
copy_button.style.display = "none";
copy_button.onclick = () => {
const txt = document.createElement("textarea");
txt.value = pre.innerText;
txt.setAttribute("readonly", "");
txt.style = { position: "absolute", left: "-9999px" };
result.appendChild(txt);
txt.select();
document.execCommand("copy");
result.removeChild(txt);
};
result.appendChild(pre);
result.appendChild(copy_button);
const update_status = (reply, replied) => {
if (replied) {
copy_button.style.display = "block";
}
let text = typeof reply == "string" ? reply : stringify(reply, null, 2);
pre.innerText = text;
};
await send_message(message, update_status, sleep);
};
}
Expand Down

0 comments on commit f621d18

Please sign in to comment.