Skip to content

Instantly share code, notes, and snippets.

@kkai0828
kkai0828 / autoSchedule.js
Created June 17, 2025 05:00
schedule homework
// 條件等待:等到指定元素出現
function waitForElement(selector, timeout = 15000, interval = 300) {
return new Promise((resolve, reject) => { const end = Date.now() + timeout
;(function check() {
const el = document.querySelector(selector)
if (el) return resolve(el)
if (Date.now() > end)
return reject(new Error('元素等待超時: ' + selector))
setTimeout(check, interval)
})()