Skip to content

Commit

Permalink
Fix loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Dianliang233 committed Jul 22, 2024
1 parent eedb090 commit 75bcaa0
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions mediawiki/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ mw.hook('wikipage.content').add(() => {
if (localStorage.getItem('mcwCalcLocal') === 'true') {
console.log('You are in development environment and tools are loaded from localhost.')
iframe.src = `http://localhost:5173${url}`
}
else {
} else {
iframe.src = `https://tools.minecraft.wiki/static${url}`
}

Expand Down Expand Up @@ -64,7 +63,7 @@ mw.hook('wikipage.content').add(() => {
theme: document.body.classList.contains('wgl-theme-light') ? 'light' : 'dark',
},
},
new URL(iframe.src).origin,
new URL(iframe.src).origin
)

// eslint-disable-next-line no-undef
Expand All @@ -76,16 +75,14 @@ mw.hook('wikipage.content').add(() => {
theme,
},
},
new URL(iframe.src).origin,
new URL(iframe.src).origin
)
})
})

window.addEventListener('message', (event) => {
if (event.origin !== new URL(iframe.src).origin)
return
if (event.data.id !== id)
return
if (event.origin !== new URL(iframe.src).origin) return
if (event.data.id !== id) return

if (event.data.type === 'mcw-calc-init-request-data') {
event.source.postMessage(
Expand All @@ -96,13 +93,11 @@ mw.hook('wikipage.content').add(() => {
innerHTML: calc.innerHTML,
},
},
new URL(iframe.src).origin,
new URL(iframe.src).origin
)
}
else if (event.data.type === 'mcw-calc-height-change') {
} else if (event.data.type === 'mcw-calc-height-change') {
iframe.style.height = `${event.data.data.height}px`
}
else if (event.data.type === 'mcw-calc-clipboard') {
} else if (event.data.type === 'mcw-calc-clipboard') {
navigator.clipboard.writeText(event.data.data.text)
}
})
Expand Down

0 comments on commit 75bcaa0

Please sign in to comment.