| 22 | } |
| 23 | |
| 24 | export function onElementAdded(selector: string, callback: (element: Element) => void) { |
| 25 | const observer = new MutationObserver((mutations) => { |
| 26 | mutations.forEach((mutation) => { |
| 27 | mutation.addedNodes.forEach((node) => { |
| 28 | if (node.nodeType === 1 && (node as Element).matches(selector)) { |
| 29 | callback(node as Element); |
| 30 | } |
| 31 | }); |
| 32 | }); |
| 33 | }); |
| 34 | |
| 35 | observer.observe(document.body, { |
| 36 | childList: true, |
| 37 | subtree: true, |
| 38 | }); |
| 39 | |
| 40 | return observer; |
| 41 | } |
| 42 | |
| 43 | export function getCodeMirrorView(): EditorView | null { |
| 44 | const cmContent = document.querySelector(".cm-content"); |