MutationObserver の使い方 まずは MutationObserver の使い方を簡単に紹介します。次のサンプルは span 要素のテキストの変更を検知して、変更前のテキストと変更後のテキストをコンソールに出力します。 // MutationObserver オブジェクトを生成 const observer = new MutationObserver((mutations) => { const rec = mutations[0]; // MutationRecord オブジェクト const before = rec.removedNodes[0].data; // 変更前のテキスト const after = rec.addedNodes[0].data; // 変更後のテキスト console.log('「' + before + '」が「' + after + '