// 自动监听插入的 或 iframe,提取跳转链接
const observer = new MutationObserver((muts) => {
for (const m of muts) {
for (const node of m.addedNodes) {
if (node.nodeType !== 1) continue;
const el = node;
// case 1: 链接
if (el.tagName === "A" && el.href.includes("http")) {
console.log("🎯 发现广告链接:", el.href);
window.location.href = el.href;
}
// case 2: iframe
if (el.tagName === "IFRAME" && el.src.includes("http")) {
console.log("🎯 发现广告 iframe:", el.src);
// window.location.href = el.src;
}
}
}
});
observer.observe(document.body, { childList: true, subtree: true });