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>
<p>
Screenshot the house:
<button class="button" id="screenshot-house">Screenshot</button>
<button class="button" id="screenshot-house">copy to clipboard</button>
</p>
</details>
<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) {
screenshotHouseButton.addEventListener('click', async () => {
const house = document.querySelector('#thinking-people-system')
if (house) {
if (!house) {
return
}
const png = await domToPng(house)
const a = document.createElement('a')
a.href = png
a.download = 'thinking-people-system.png'
a.click()
try {
const response = await fetch(png)
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>
<p>
Screenshot the house:
<button class="button" id="screenshot-house">Screenshot</button>
<button class="button" id="screenshot-house">copy to clipboard</button>
</p>
</details>
<svg class="round-svg" xmlns="http://www.w3.org/2000/svg">