From afd2a178dc7d78f93803a8964130a5559955dd07 Mon Sep 17 00:00:00 2001 From: elijahr2411 Date: Wed, 25 Jan 2023 21:29:10 -0500 Subject: [PATCH] add screenshot function --- dist/index.html | 1 + src/index.js | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/dist/index.html b/dist/index.html index da394f0..48922ba 100644 --- a/dist/index.html +++ b/dist/index.html @@ -44,6 +44,7 @@ +
diff --git a/src/index.js b/src/index.js index deddb95..f9b272b 100644 --- a/src/index.js +++ b/src/index.js @@ -11,7 +11,8 @@ const users = []; const buttons = { takeTurn: window.document.getElementById("takeTurnBtn"), changeUsername: window.document.getElementById("changeUsernameBtn"), - voteReset: window.document.getElementById("voteResetButton") + voteReset: window.document.getElementById("voteResetButton"), + screenshot: window.document.getElementById("screenshotButton") } var hasTurn = false; var vm; @@ -363,6 +364,23 @@ async function openVM(url, node) { display.addEventListener('keydown', (e) => vm.keyevent(e, true)); display.addEventListener('keyup', (e) => vm.keyevent(e, false)); } +function screenshotVM() { + return new Promise((res, rej) => { + display.toBlob((b) => { + if (b == null) { + rej(); + return; + } + res(b); + }, "image/png"); + }) +} +buttons.screenshot.addEventListener('click', async () => { + var blob = await screenshotVM(); + var url = URL.createObjectURL(blob); + window.open(url, "_blank"); + URL.revokeObjectURL(url); +}); chatinput.addEventListener("keypress", (e) => { if (e.key == "Enter") { vm.chat(chatinput.value); @@ -378,4 +396,7 @@ buttons.takeTurn.addEventListener('click', () => vm.turn()); buttons.voteReset.addEventListener('click', () => vm.voteReset(true)); voteyesbtn.addEventListener('click', () => vm.voteReset(true)); votenobtn.addEventListener('click', () => vm.voteReset(false)); -config.serverAddresses.forEach(multicollab); \ No newline at end of file +config.serverAddresses.forEach(multicollab); + +// Export some stuff +window.screenshotVM = screenshotVM; \ No newline at end of file