Detects dynamic osu page changes
目前為
此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/441010/1024850/OsuPageObserver.js
class OsuWebObserver {
constructor(callback) {
this.callback = callback;
const firstLoad = new MutationObserver(() => {
this.callback();
firstLoad.disconnect();
});
const layout = document.querySelector(".osu-layout__section")?.firstElementChild;
if (layout != null) {
firstLoad.observe(layout, {childList: true});
}
this.pageObserver = new MutationObserver(this.detectPageChange);
this.pageObserver.observe(document.documentElement, {childList: true});
}
detectPageChange = (mutations) => {
for (const mutation of mutations) {
if (mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(node => {
if (node.nodeName == "BODY") {
this.callback();
return;
}
});
}
}
}
destroy = () => {
this.pageObserver.disconnect();
}
}