Skip to content

Commit 547cb38

Browse files
committed
fix: handle if the userscript is injected after DOMContentLoaded event
1 parent 422cca5 commit 547cb38

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

sources/src/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const Win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window
1919
export function RunNamuLinkUserscript(BrowserWindow: typeof window, UserscriptName: string = 'NamuLink'): void {
2020
const ProtectedFunctionPrototypeToString = BrowserWindow.Function.prototype.toString
2121

22-
window.addEventListener('DOMContentLoaded', () => {
22+
if (document.readyState === 'loading') {
23+
window.addEventListener('DOMContentLoaded', () => {
2324
SPA.InstallSpaNavigationBridge({
2425
Root: () => document.getElementById('#app'),
2526
StableForMs: 900,
@@ -30,6 +31,20 @@ export function RunNamuLinkUserscript(BrowserWindow: typeof window, UserscriptNa
3031
WatchHashChange: true
3132
})
3233
})
34+
} else {
35+
// 이미 DOMContentLoaded 이후
36+
window.addEventListener('DOMContentLoaded', () => {
37+
SPA.InstallSpaNavigationBridge({
38+
Root: () => document.getElementById('#app'),
39+
StableForMs: 900,
40+
SampleWindowMs: 900,
41+
Threshold: 3,
42+
TimeoutMs: 12000,
43+
IgnoreMutation: SPA.DefaultIgnoreMutation,
44+
WatchHashChange: true
45+
})
46+
})
47+
}
3348

3449
window.addEventListener('SpaRendered', async () => {
3550
let HTMLEle = Sort.CollectDataVAttributes(document)

0 commit comments

Comments
 (0)