Update index.js

This commit is contained in:
mason369 2023-04-13 12:27:10 +08:00
parent e9e9d95ec6
commit 21c68889b8

View File

@ -18,7 +18,8 @@ async function init() {
for (let i = 0; i < copyBtnList.length; i++) {
const btn = copyBtnList[i];
btn.addEventListener("click", () => {
btn.addEventListener("touchend", () => {
alert("touchend");
const parentDiv = btn.parentNode;
const codeElem = parentDiv.querySelector("code");
const spans = [...codeElem.querySelectorAll("span")];
@ -27,7 +28,9 @@ async function init() {
].join("");
if (navigator.clipboard) {
navigator.clipboard.writeText(textToCopy);
navigator.clipboard.writeText(textToCopy).then(() => {
console.log("Text copied to clipboard");
});
} else {
const textarea = document.createElement("textarea");
textarea.value = textToCopy;