/// /// /// const eventHandlers: MutationCallback[] = []; let cursorChangeObserver: MutationObserver | undefined; export function addCursorChangeEventListener(callback: MutationCallback) { /** * 初期化用関数 * @return {boolean} 成功したならtrue、失敗したらfalse */ function init(): boolean { const cursor = document.querySelector(".cursor"); if (cursor === null) return false; const options: MutationObserverInit = { attributes: true, attributeFilter: ["style"], }; cursorChangeObserver = new MutationObserver(( mutation: MutationRecord[], observer: MutationObserver, ) => eventHandlers.forEach((e) => e(mutation, observer))); cursorChangeObserver.observe(cursor, options); return true; } if (cursorChangeObserver === undefined) if (!init()) return; eventHandlers.push(callback); }