perf: replace MutationObserver with setInterval to fix performance issue
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name ljq_web_driver
|
// @name ljq_web_driver
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 0.33
|
// @version 0.40
|
||||||
// @description Execute JS via ljq_web_driver
|
// @description Execute JS via ljq_web_driver
|
||||||
// @require https://code.jquery.com/jquery-3.6.0.min.js
|
// @require https://code.jquery.com/jquery-3.6.0.min.js
|
||||||
// @author You
|
// @author You
|
||||||
@@ -405,22 +405,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 监控DOM变化
|
// 监控DOM变化 (改为10秒定时器以优化性能)
|
||||||
const observer = new MutationObserver(() => getIndicator());
|
let indicatorTimer = null;
|
||||||
|
|
||||||
if (document.readyState !== 'loading') {
|
if (document.readyState !== 'loading') {
|
||||||
init();
|
init();
|
||||||
observer.observe(document.body, { childList: true, subtree: true });
|
indicatorTimer = setInterval(() => getIndicator(), 10000);
|
||||||
} else {
|
} else {
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
init();
|
init();
|
||||||
observer.observe(document.body, { childList: true, subtree: true });
|
indicatorTimer = setInterval(() => getIndicator(), 10000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理
|
// 清理
|
||||||
window.addEventListener('beforeunload', () => {
|
window.addEventListener('beforeunload', () => {
|
||||||
observer.disconnect();
|
if (indicatorTimer) clearInterval(indicatorTimer);
|
||||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||||
ws.close();
|
ws.close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user