improvement:改进复制功能增加兼容性

This commit is contained in:
mason369 2023-04-13 00:18:46 +08:00
parent 3d9cf6aa07
commit e9e9d95ec6

View File

@ -25,7 +25,18 @@ async function init() {
const textToCopy = [
...new Set(spans.map((span) => span.textContent)),
].join("");
navigator.clipboard.writeText(textToCopy);
if (navigator.clipboard) {
navigator.clipboard.writeText(textToCopy);
} else {
const textarea = document.createElement("textarea");
textarea.value = textToCopy;
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);
}
console.log(textToCopy);
});
}