Skip to content

Commit 6684710

Browse files
committed
Make watchForElement helper promise-only
Signed-off-by: Bayu Satiyo <itsyuukunz@gmail.com>
1 parent 1578def commit 6684710

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/helpers/dom.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,22 @@ export function awaitElement(elem, func) {
182182
}
183183

184184
/**
185-
* Watch for an element to appear on the page and then call a function immediately. This is used to prevent the script from running if the element doesn't exist. Improved version of waitForElement.
185+
* Watch for an element to appear on the page. This is used to prevent the script from running if the element doesn't exist. Improved version of waitForElement.
186186
* @param {string} e - The element to watch.
187-
* @param {function} f - The function to call.
187+
* @returns {Promise<any>} A promise that resolves with the element.
188188
*/
189-
export function watchForElement (selector, callback) {
189+
export function watchForElement (selector) {
190190
return new Promise(resolve => {
191191
const element = document.querySelector(selector)
192192
if (element) {
193193
console.log(`[FastForward] Element found: ${element} | Selector: ${selector}`)
194-
callback(element)
195194
resolve(element)
196195
return
197196
}
198197

199198
const observer = new MutationObserver(() => {
200199
Array.from(document.querySelectorAll(selector)).forEach(el => {
201200
console.log(`[FastForward] Element found: ${el} | Selector: ${selector}`)
202-
callback(el)
203201
resolve(el)
204202
observer.disconnect()
205203
})

0 commit comments

Comments
 (0)