(function () {
"use strict";
window.onload = function () {
function removeAllGG() {
let headGG = document.querySelector(".plat_recom_carousel");
let ggList = document.querySelectorAll(".ylh-ad-wrap");
let ggList2 = document.querySelectorAll(".ylh-ad-container");
let topCarousel = document.querySelector("#rec_left");
let rightGG = document.querySelector(".r-right-sec");
ggList.forEach(ad => {
if (ad && ad.parentNode) {
ad.parentNode.removeChild(ad);
}
});
ggList2.forEach(ad => {
if (ad && ad.parentNode) {
ad.parentNode.removeChild(ad);
}
});
if (headGG && headGG.parentNode) {
headGG.parentNode.removeChild(headGG);
console.log("==========去除头部广告");
}
if (topCarousel && topCarousel.parentNode) {
topCarousel.parentNode.removeChild(topCarousel);
console.log("==========去除顶部轮播");
}
if (rightGG && rightGG.parentNode) {
rightGG.parentNode.removeChild(rightGG);
console.log("==========去除右侧广告");
}
}
removeAllGG();
setInterval(() => {
removeAllGG();
}, 2000);
window.addEventListener('popstate', () => {
console.log("URL变化");
setTimeout(removeAllGG, 500);
});
window.addEventListener('hashchange', () => {
console.log("Hash变化");
setTimeout(removeAllGG, 500);
});
const observer = new MutationObserver((mutations) => {
let shouldRemove = false;
mutations.forEach((mutation) => {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === Node.ELEMENT_NODE) {
if (node.classList && (
node.classList.contains('ylh-ad-wrap') ||
node.classList.contains('ylh-ad-container') ||
node.classList.contains('plat_recom_carousel') ||
node.classList.contains('r-right-sec') ||
node.id === 'rec_left'
)) {
shouldRemove = true;
}
}
});
}
});
if (shouldRemove) {
setTimeout(removeAllGG, 100);
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
};
})();