Skip to content

Commit 24dcb02

Browse files
committed
add button pos & handle onLoad event listener only if document is not in readyState
1 parent 75b9581 commit 24dcb02

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

apps/chrome-extension/src/content.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ const initButtons = (): void => {
155155
right,
156156
bottom: startBottom + 2 * itemHeight,
157157
},
158+
{
159+
right,
160+
bottom: startBottom + 3 * itemHeight,
161+
},
158162
]
159163
}
160164

apps/chrome-extension/src/scripts/view-lark-docx-as-markdown.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ const main = async () => {
9595

9696
previewWindow.document.title = 'Markdown Preview'
9797

98-
// Wait until the new window’s document is ready
99-
previewWindow.onload = () => {
98+
// prepare markdown preview for document
99+
const writeViewContent = () => {
100100
const doc = previewWindow.document
101101

102102
const style = doc.createElement('style')
@@ -127,6 +127,17 @@ const main = async () => {
127127
doc.body.appendChild(pre)
128128
}
129129

130+
if (
131+
previewWindow.document.readyState === 'complete' ||
132+
document.readyState === 'interactive'
133+
) {
134+
writeViewContent()
135+
} else {
136+
previewWindow.onload = () => {
137+
writeViewContent()
138+
}
139+
}
140+
130141
if (tokens.length > 0) {
131142
const isSuccess = await makePublicUrlEffective(
132143
Object.fromEntries(tokens) as Record<string, string>,

0 commit comments

Comments
 (0)