Skip to content

Commit

Permalink
Feat: Adding line chart copy to clipboard JS
Browse files Browse the repository at this point in the history
  • Loading branch information
JT-39 committed Oct 18, 2024
1 parent 9f083c6 commit 4d6d972
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions www/custom_js.js
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@

async function getImageBlobFromUrl(url) {
const fetchedImageData = await fetch(url);
const blob = await fetchedImageData.blob();
return blob;
}
$(document).ready(function () {
$("#stat_n_focus_line-copybtn").on("click", async () => {
const src = $("#stat_n_focus_line-copy_plot>img").attr("src");
try {
const blob = await getImageBlobFromUrl(src);
await navigator.clipboard.write([
new ClipboardItem({
[blob.type]: blob
})
]);
alert("Image copied to clipboard!");
} catch (err) {
console.error(err.name, err.message);
alert("There was an error while copying image to clipboard :/");
}
});
});

0 comments on commit 4d6d972

Please sign in to comment.