fix: align nested rendering CSS synchronization and Word style inheritance

This commit is contained in:
2026-11-04 16:42:10 +08:00
parent 6cc833183d
commit 06c5368b05
15 changed files with 408 additions and 42 deletions
+14 -23
View File
@@ -120,21 +120,7 @@ document.addEventListener("DOMContentLoaded", () => {
button.textContent = "复制";
button.addEventListener("click", async () => {
const text = rawText;
try {
await navigator.clipboard.writeText(text);
button.textContent = "已复制";
} catch (error) {
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.style.position = "fixed";
textarea.style.left = "-9999px";
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
textarea.remove();
button.textContent = "已复制";
}
button.textContent = await copyText(rawText) ? "已复制" : "复制失败,请重试";
window.setTimeout(() => {
button.textContent = "复制";
}, 1200);
@@ -173,20 +159,26 @@ document.addEventListener("DOMContentLoaded", () => {
}, 700);
});
const copyText = async (text) => {
async function copyText(text) {
try {
await navigator.clipboard.writeText(text);
return true;
} catch (error) {
const focused = document.activeElement;
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.style.position = "fixed";
textarea.style.left = "-9999px";
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
textarea.remove();
try { return document.execCommand("copy"); }
catch (fallbackError) { return false; }
finally {
textarea.remove();
focused?.focus({ preventScroll: true });
}
}
};
}
document.querySelectorAll(".reader table").forEach((table) => {
if (table.closest(".table-wrapper")) {
@@ -213,13 +205,12 @@ document.addEventListener("DOMContentLoaded", () => {
copyButton.title = "复制表格";
copyButton.addEventListener("click", async () => {
const rows = [...table.querySelectorAll("tr")].map((row) =>
[...row.querySelectorAll("th, td")]
const rows = [...table.rows].map((row) =>
[...row.cells]
.map((cell) => (cell.innerText || cell.textContent || "").replace(/\s+/g, " ").trim())
.join("\t")
);
await copyText(rows.join("\n"));
copyButton.textContent = "已复制";
copyButton.textContent = await copyText(rows.join("\n")) ? "已复制" : "复制失败,请重试";
window.setTimeout(() => {
copyButton.textContent = "复制表格";
}, 1200);