我写了个测试 Mutation Observer 的脚本,在 Seeking Alpha 网站上运行,监听新闻列表最下面翻页的变化,为啥只有第一次加载页面时才能看到 mutation 产生的 log 呢?
测试页面: Apple Inc. (AAPL) Latest Stock News (seekingalpha.com)
// ==UserScript==
// @name test mutation observer
// @namespace http://tampermonkey.net/
// @version 2024-01-28
// @description try to take over the world!
// @author You
// @match https://seekingalpha.com/symbol/*/news*
// @icon https://seekingalpha.com/samw/static/images/apple-touch-icon.png
// @grant window.onurlchange
// ==/UserScript==
const observer = new MutationObserver(()=>{console.log('mutated 啦啦啦')});
const node = document.querySelector('div[data-test-id="pagination"]');
const config = {subtree: true, childList: true, attributes: true, characterData: true};
observer.observe(node, config);