copy to clipboard instead of downloading an image

This commit is contained in:
Julien Calixte
2025-04-26 11:23:20 +02:00
parent 857969163f
commit 75541a0764
3 changed files with 16 additions and 8 deletions

View File

@@ -161,7 +161,7 @@
</ul> </ul>
<p> <p>
Screenshot the house: Screenshot the house:
<button class="button" id="screenshot-house">Screenshot</button> <button class="button" id="screenshot-house">copy to clipboard</button>
</p> </p>
</details> </details>
<svg class="round-svg" xmlns="http://www.w3.org/2000/svg"> <svg class="round-svg" xmlns="http://www.w3.org/2000/svg">

18
main.ts
View File

@@ -83,12 +83,20 @@ const screenshotHouseButton = document.querySelector('#screenshot-house')
if (screenshotHouseButton) { if (screenshotHouseButton) {
screenshotHouseButton.addEventListener('click', async () => { screenshotHouseButton.addEventListener('click', async () => {
const house = document.querySelector('#thinking-people-system') const house = document.querySelector('#thinking-people-system')
if (house) { if (!house) {
return
}
const png = await domToPng(house) const png = await domToPng(house)
const a = document.createElement('a')
a.href = png try {
a.download = 'thinking-people-system.png' const response = await fetch(png)
a.click() const blob = await response.blob()
await navigator.clipboard.write([
new ClipboardItem({ [blob.type]: blob })
])
} catch (error) {
console.warn(error)
} }
}) })
} }

View File

@@ -152,7 +152,7 @@
</ul> </ul>
<p> <p>
Screenshot the house: Screenshot the house:
<button class="button" id="screenshot-house">Screenshot</button> <button class="button" id="screenshot-house">copy to clipboard</button>
</p> </p>
</details> </details>
<svg class="round-svg" xmlns="http://www.w3.org/2000/svg"> <svg class="round-svg" xmlns="http://www.w3.org/2000/svg">