/*
 * index.js.js
 * Created by 还有醋v on 2021/6/17.
 * Copyright © 2021 haiyoucuv. All rights reserved.
 */

// PC端搜索广告
const content_left = document.getElementById("content_left");
console.log("PC端搜索广告：", content_left);

if (content_left && content_left.children > 0 && !content_left.children[0].id) {
	content_left.children[0].remove();
}

// 手机端搜索广告
const ec_wise_ad = document.getElementsByClassName("ec_wise_ad");
console.log("手机端搜索广告：", ec_wise_ad);
if (ec_wise_ad[0]) {
	ec_wise_ad[0].remove();
}

/**
 * 通过监听dom树的变化，移除异步加载的的广告
 */
function removeAdAsync() {
	// 百科右侧图片广告
	const right_ad = document.getElementsByClassName("right-ad");
	if (right_ad[0]) {
		console.log("百科右侧图片广告", right_ad);
		right_ad[0].remove();
	}

	// 百科右侧恶心的广告
	const side_box_unionAd = document.getElementById("side_box_unionAd");
	if (side_box_unionAd) {
		console.log("百科右侧恶心的广告", right_ad);
		side_box_unionAd.remove();
	}
}

// 监听dom结构变化 DOM2
// document.body.addEventListener("DOMSubtreeModified", ()=>{
// 	console.log("DOMSubtreeModified");
// });


// 监听dom结构变化 DOM3
const observer = new MutationObserver(removeAdAsync);

observer.observe(document.body, {
	childList: true,
	// attributes: true,
	subtree: true,
});

