mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-07-09 23:09:25 +08:00
fix: bilibili reload (#603)
This commit is contained in:
@@ -18,3 +18,4 @@ export * from './parse-int-with-clamp'
|
||||
export * from './set-element-position-in-viewport'
|
||||
export * from './eventsource-parser.mjs'
|
||||
export * from './update-ref-height'
|
||||
export * from './wait-for-element-to-exist-and-select.mjs'
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
export function waitForElementToExistAndSelect(selector) {
|
||||
return new Promise((resolve) => {
|
||||
if (document.querySelector(selector)) {
|
||||
return resolve(document.querySelector(selector))
|
||||
}
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
if (document.querySelector(selector)) {
|
||||
resolve(document.querySelector(selector))
|
||||
observer.disconnect()
|
||||
}
|
||||
})
|
||||
|
||||
observer.observe(document.body, {
|
||||
subtree: true,
|
||||
childList: true,
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user