Skip to content

Commit 8786660

Browse files
committed
Update index.js
1 parent 21c6888 commit 8786660

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

  • rustedwarfareapicode/.vitepress/theme

rustedwarfareapicode/.vitepress/theme/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function init() {
1818

1919
for (let i = 0; i < copyBtnList.length; i++) {
2020
const btn = copyBtnList[i];
21-
btn.addEventListener("touchend", () => {
21+
btn.addEventListener("touchend", async () => {
2222
alert("touchend");
2323
const parentDiv = btn.parentNode;
2424
const codeElem = parentDiv.querySelector("code");
@@ -27,20 +27,18 @@ async function init() {
2727
...new Set(spans.map((span) => span.textContent)),
2828
].join("");
2929

30-
if (navigator.clipboard) {
31-
navigator.clipboard.writeText(textToCopy).then(() => {
32-
console.log("Text copied to clipboard");
33-
});
34-
} else {
30+
try {
31+
await navigator.clipboard.writeText(textToCopy);
32+
console.log("Text copied to clipboard");
33+
} catch (error) {
3534
const textarea = document.createElement("textarea");
3635
textarea.value = textToCopy;
3736
document.body.appendChild(textarea);
3837
textarea.select();
3938
document.execCommand("copy");
4039
document.body.removeChild(textarea);
40+
console.log("Text copied to clipboard");
4141
}
42-
43-
console.log(textToCopy);
4442
});
4543
}
4644
} catch (error) {

0 commit comments

Comments
 (0)