Spaces:
Sleeping
Sleeping
XIao
commited on
fix: 解决内网访问点击复制按钮失效 (#827)
Browse filesfix #826 .
Co-authored-by: w_xiaolizu <[email protected]>
- assets/custom.js +27 -8
assets/custom.js
CHANGED
@@ -373,19 +373,38 @@ function addChuanhuButton(botElement) {
|
|
373 |
copyButton.classList.add('copy-bot-btn');
|
374 |
copyButton.setAttribute('aria-label', 'Copy');
|
375 |
copyButton.innerHTML = copyIcon;
|
376 |
-
copyButton.addEventListener('click', () => {
|
377 |
const textToCopy = rawMessage.innerText;
|
378 |
-
|
379 |
-
|
380 |
-
|
|
|
381 |
copyButton.innerHTML = copiedIcon;
|
382 |
setTimeout(() => {
|
383 |
copyButton.innerHTML = copyIcon;
|
384 |
}, 1500);
|
385 |
-
}
|
386 |
-
|
387 |
-
|
388 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
389 |
});
|
390 |
botElement.appendChild(copyButton);
|
391 |
|
|
|
373 |
copyButton.classList.add('copy-bot-btn');
|
374 |
copyButton.setAttribute('aria-label', 'Copy');
|
375 |
copyButton.innerHTML = copyIcon;
|
376 |
+
copyButton.addEventListener('click', async () => {
|
377 |
const textToCopy = rawMessage.innerText;
|
378 |
+
|
379 |
+
try {
|
380 |
+
if ("clipboard" in navigator) {
|
381 |
+
await navigator.clipboard.writeText(textToCopy);
|
382 |
copyButton.innerHTML = copiedIcon;
|
383 |
setTimeout(() => {
|
384 |
copyButton.innerHTML = copyIcon;
|
385 |
}, 1500);
|
386 |
+
} else {
|
387 |
+
const textArea = document.createElement("textarea");
|
388 |
+
textArea.value = textToCopy;
|
389 |
+
|
390 |
+
document.body.appendChild(textArea);
|
391 |
+
textArea.select();
|
392 |
+
|
393 |
+
try {
|
394 |
+
document.execCommand('copy');
|
395 |
+
copyButton.innerHTML = copiedIcon;
|
396 |
+
setTimeout(() => {
|
397 |
+
copyButton.innerHTML = copyIcon;
|
398 |
+
}, 1500);
|
399 |
+
} catch (error) {
|
400 |
+
console.error("Copy failed: ", error);
|
401 |
+
}
|
402 |
+
|
403 |
+
document.body.removeChild(textArea);
|
404 |
+
}
|
405 |
+
} catch (error) {
|
406 |
+
console.error("Copy failed: ", error);
|
407 |
+
}
|
408 |
});
|
409 |
botElement.appendChild(copyButton);
|
410 |
|