|
@@ -123,24 +123,34 @@ function clearLog(target) {
|
|
|
|
|
|
|
|
function copyLog(target) {
|
|
function copyLog(target) {
|
|
|
var el = typeof target === "string" ? document.getElementById(target) : target;
|
|
var el = typeof target === "string" ? document.getElementById(target) : target;
|
|
|
- var text = el ? el.textContent : logLines.join("\n");
|
|
|
|
|
- if (navigator.clipboard) {
|
|
|
|
|
|
|
+ // 每行日志是一个独立的 div,textContent 直接拼接不会带换行,需逐行 join("\n")
|
|
|
|
|
+ var text = el
|
|
|
|
|
+ ? Array.prototype.map
|
|
|
|
|
+ .call(el.children, function (c) {
|
|
|
|
|
+ return c.textContent;
|
|
|
|
|
+ })
|
|
|
|
|
+ .join("\n")
|
|
|
|
|
+ : logLines.join("\n");
|
|
|
|
|
+ function fallbackCopy() {
|
|
|
|
|
+ var ta = document.createElement("textarea");
|
|
|
|
|
+ ta.value = text;
|
|
|
|
|
+ ta.style.position = "fixed";
|
|
|
|
|
+ ta.style.opacity = "0";
|
|
|
|
|
+ document.body.appendChild(ta);
|
|
|
|
|
+ ta.select();
|
|
|
|
|
+ var ok = document.execCommand("copy");
|
|
|
|
|
+ ta.remove();
|
|
|
|
|
+ alert(ok ? "复制成功" : "复制失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
|
navigator.clipboard
|
|
navigator.clipboard
|
|
|
.writeText(text)
|
|
.writeText(text)
|
|
|
.then(function () {
|
|
.then(function () {
|
|
|
return alert("复制成功");
|
|
return alert("复制成功");
|
|
|
})
|
|
})
|
|
|
- .catch(function () {
|
|
|
|
|
- return alert("复制失败");
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ .catch(fallbackCopy);
|
|
|
} else {
|
|
} else {
|
|
|
- var ta = document.createElement("textarea");
|
|
|
|
|
- ta.value = text;
|
|
|
|
|
- document.body.appendChild(ta);
|
|
|
|
|
- ta.select();
|
|
|
|
|
- document.execCommand("copy");
|
|
|
|
|
- ta.remove();
|
|
|
|
|
- alert("复制成功");
|
|
|
|
|
|
|
+ fallbackCopy();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
["beforeunload", "pagehide"].forEach(function (e) {
|
|
["beforeunload", "pagehide"].forEach(function (e) {
|