// 监控所有新增的 script 标签
new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
Array.from(mutation.addedNodes).forEach((node) => {
if (node.tagName === ‘SCRIPT’ && node.src.includes(‘hm.baidu.com/hm.js’)) {
node.parentNode.removeChild(node);
console.log(‘已阻止百度统计脚本:’, node.src);
}
});
});
}).observe(document.documentElement, {
childList: true,
subtree: true
});
new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
Array.from(mutation.addedNodes).forEach((node) => {
if (node.tagName === ‘SCRIPT’ && node.src.includes(‘hm.baidu.com/hm.js’)) {
node.parentNode.removeChild(node);
console.log(‘已阻止百度统计脚本:’, node.src);
}
});
});
}).observe(document.documentElement, {
childList: true,
subtree: true
});