add screenshot function
This commit is contained in:
parent
f38eee8a15
commit
afd2a178dc
2 changed files with 24 additions and 2 deletions
1
dist/index.html
vendored
1
dist/index.html
vendored
|
@ -44,6 +44,7 @@
|
||||||
<button class="btn btn-secondary" id="takeTurnBtn">Take Turn</button>
|
<button class="btn btn-secondary" id="takeTurnBtn">Take Turn</button>
|
||||||
<button class="btn btn-secondary" id="changeUsernameBtn">Change Username</button>
|
<button class="btn btn-secondary" id="changeUsernameBtn">Change Username</button>
|
||||||
<button class="btn btn-secondary" id="voteResetButton">Vote for Reset</button>
|
<button class="btn btn-secondary" id="voteResetButton">Vote for Reset</button>
|
||||||
|
<button class="btn btn-secondary" id="screenshotButton">Screenshot</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
|
|
25
src/index.js
25
src/index.js
|
@ -11,7 +11,8 @@ const users = [];
|
||||||
const buttons = {
|
const buttons = {
|
||||||
takeTurn: window.document.getElementById("takeTurnBtn"),
|
takeTurn: window.document.getElementById("takeTurnBtn"),
|
||||||
changeUsername: window.document.getElementById("changeUsernameBtn"),
|
changeUsername: window.document.getElementById("changeUsernameBtn"),
|
||||||
voteReset: window.document.getElementById("voteResetButton")
|
voteReset: window.document.getElementById("voteResetButton"),
|
||||||
|
screenshot: window.document.getElementById("screenshotButton")
|
||||||
}
|
}
|
||||||
var hasTurn = false;
|
var hasTurn = false;
|
||||||
var vm;
|
var vm;
|
||||||
|
@ -363,6 +364,23 @@ async function openVM(url, node) {
|
||||||
display.addEventListener('keydown', (e) => vm.keyevent(e, true));
|
display.addEventListener('keydown', (e) => vm.keyevent(e, true));
|
||||||
display.addEventListener('keyup', (e) => vm.keyevent(e, false));
|
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) => {
|
chatinput.addEventListener("keypress", (e) => {
|
||||||
if (e.key == "Enter") {
|
if (e.key == "Enter") {
|
||||||
vm.chat(chatinput.value);
|
vm.chat(chatinput.value);
|
||||||
|
@ -378,4 +396,7 @@ buttons.takeTurn.addEventListener('click', () => vm.turn());
|
||||||
buttons.voteReset.addEventListener('click', () => vm.voteReset(true));
|
buttons.voteReset.addEventListener('click', () => vm.voteReset(true));
|
||||||
voteyesbtn.addEventListener('click', () => vm.voteReset(true));
|
voteyesbtn.addEventListener('click', () => vm.voteReset(true));
|
||||||
votenobtn.addEventListener('click', () => vm.voteReset(false));
|
votenobtn.addEventListener('click', () => vm.voteReset(false));
|
||||||
config.serverAddresses.forEach(multicollab);
|
config.serverAddresses.forEach(multicollab);
|
||||||
|
|
||||||
|
// Export some stuff
|
||||||
|
window.screenshotVM = screenshotVM;
|
Loading…
Reference in a new issue