Compare commits

...

3 Commits

Author SHA1 Message Date
vilmibm 7a2ad27484 support image download 2023-08-04 01:49:34 +00:00
vilmibm a12b1febe0 make a little nicer on phone viewport 2023-08-04 01:11:41 +00:00
vilmibm 0f341fa482 fix touch events on mobile 2023-08-04 00:59:21 +00:00
1 changed files with 61 additions and 15 deletions

View File

@ -3,6 +3,7 @@
<head>
<title>blackout engine</title>
<script src="/html2canvas.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<style>
@ -37,6 +38,10 @@
background-color: black;
}
.grey {
background-color: grey;
}
.hidden {
display: none;
}
@ -59,14 +64,30 @@
#paper span {
cursor: help;
/* hack for the image download. without this, thin white artifacting at span margins */
margin-left:-1px;
}
@media (max-width:400px) {
.centering {
display: block;
width: 100%;
margin: 0px;
}
}
@media (hover: hover) {
#paper span:hover {
background-color: white;
/* hack for the image download. without this, thin white artifacting at span margins */
margin-left:-1px;
}
#paper span.black:hover {
background-color: grey;
/* hack for the image download. without this, thin white artifacting at span margins */
margin-left:-1px;
}
}
#aboutToggle {
@ -104,9 +125,7 @@
<center>
<p>
<button id="copyText">copy text to clipboard</button>
</p>
<p>
<button id="copyImage" class="hidden">copy image to clipboard</button>
<button id="downloadImage">download as image</button>
</p>
<p>
<a id="aboutToggle" href="">ABOUT</a>
@ -130,27 +149,54 @@
</div>
</center>
<script>
document.querySelectorAll("#paper span").forEach(span =>
span.onclick = () => span.classList.toggle("black"));
document.querySelectorAll("#paper span").forEach(span => {
span.addEventListener("click", () => span.classList.toggle("black"));
span.addEventListener("touchstart", (e) => {
e.preventDefault();
span.classList.add("grey");
});
span.addEventListener("touchend", (e) => {
e.preventDefault();
span.classList.remove("grey");
span.classList.toggle("black");
});
span.addEventListener("touchcancel", (e) => {
e.preventDefault();
span.classList.remove("grey");
});
});
document.querySelector("#aboutToggle").onclick = (e) => {
e.preventDefault();
document.querySelector("#about").classList.toggle("hidden");
}
const copyImgButton = document.querySelector("#copyImage");
copyImgButton.addEventListener("animationend", () => copyImgButton.classList.remove("rainbow"), false);
copyImgButton.onclick = () => {
const downloadImgButton = document.querySelector("#downloadImage");
downloadImgButton.addEventListener("animationend", () => downloadImgButton.classList.remove("rainbow"), false);
downloadImgButton.addEventListener("click", () => {
html2canvas(document.querySelector("#paper")).then((canvas) => {
canvas.toBlob((blob) => {
/*
// can't use this because ff doesn't have support by default for clipboard.write()
let data = [new ClipboardItem({ [blob.type]: blob })];
navigator.clipboard.write(data).then(() => {
copyImgButton.classList.add("rainbow");
}, console.log);
*/
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = downloadUrl;
a.download = "blackout.png";
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(downloadUrl);
});
});
}
});
const copyTextButton = document.querySelector("#copyText");
copyTextButton.addEventListener("animationend", () => copyTextButton.classList.remove("rainbow"), false);
copyTextButton.onclick = () => {
copyTextButton.addEventListener("click", () => {
let toCopy = "";
document.querySelectorAll("#paper span").forEach(span => {
let guts = span.innerHTML;
@ -187,7 +233,7 @@
}, (err) => {
console.log(err);
});
}
});
</script>
</body>
</html>