mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-07-25 13:10:34 +08:00
chore: improve for github (#7)
This commit is contained in:
@@ -19,22 +19,17 @@ const getPatchData = async (patchUrl) => {
|
||||
export default {
|
||||
init: async (hostname, userConfig, getInput, mountComponent) => {
|
||||
try {
|
||||
const targetNode = document.querySelector('body')
|
||||
const observer = new MutationObserver(async (records) => {
|
||||
if (
|
||||
records.some(
|
||||
(record) =>
|
||||
record.type === 'childList' &&
|
||||
[...record.addedNodes].some((node) => node.classList.contains('page-responsive')),
|
||||
)
|
||||
) {
|
||||
let oldUrl = location.href
|
||||
const checkUrlChange = async () => {
|
||||
if (location.href !== oldUrl) {
|
||||
oldUrl = location.href
|
||||
const patchUrl = await getPatchUrl()
|
||||
if (patchUrl) {
|
||||
mountComponent(config.github, userConfig)
|
||||
}
|
||||
}
|
||||
})
|
||||
observer.observe(targetNode, { childList: true })
|
||||
}
|
||||
window.setInterval(checkUrlChange, 500)
|
||||
} catch (e) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user