use selection to copy from web view

This commit is contained in:
notoriousmango
2025-02-12 19:09:31 +09:00
parent a1d56fd8a2
commit 0928609c9b

View File

@@ -177,6 +177,17 @@ async function copyImage(image: HTMLImageElement, retries = 5) {
})]);
} catch (e) {
console.error(e);
const selection = window.getSelection();
if (!selection) {
await navigator.clipboard.writeText(image.getAttribute('data-src') ?? image.src);
return;
}
selection.removeAllRanges();
const range = document.createRange();
range.selectNode(image);
selection.addRange(range);
document.execCommand('copy');
selection.removeAllRanges();
}
}