uview-plus被迫看广告解决方案

823 阅读1分钟

image.png

按f12控制台输入下面命令

let modal = document.getElementsByClassName("v-modal");
if (modal.length > 0) {
  modal[0].style.visibility = "hidden";
}
let dialog = document.getElementsByClassName("el-dialog__wrapper");
if (dialog.length > 0) {
  dialog[0].style.visibility = "hidden";
}
// 创建一个 MutationObserver 来监听 DOM 变化
const observer = new MutationObserver((mutationsList) => {
  for (const mutation of mutationsList) {
    if (mutation.type === "childList") {
      // 检查是否有新添加的元素带有 v-modal 类
      //mask
      const modalElements = document.querySelectorAll(".v-modal");
      //dialog
      const dialogElements = document.querySelectorAll(".el-dialog__wrapper");
      //广告
      const gg = document.querySelectorAll(".adsbygoogle");
      if (gg.length > 0) {
        // 广告元素隐藏
        gg.forEach((item) => {
          console.log("成功拦截广告");

          item.style.setProperty("display", "none", "important");
        });
      }
      if (modalElements.length > 0) {
        //  v-modal 类的元素隐藏
        console.log("成功拦截mask");

        document.getElementsByClassName("v-modal")[0].style.zIndex = "-100";
      }
      if (dialogElements.length > 0) {
        console.log("成功拦截dialog");

        // el-dialog__wrapper 类的元素隐藏
        document.getElementsByClassName("el-dialog__wrapper")[0].style.zIndex = "-100";
      }
    }
  }
});