萌娘百科去除烦人的 adblock 检测弹窗

去除烦人的 adblock 检测弹窗

// ==UserScript==
// @name         萌娘百科去除烦人的 adblock 检测弹窗
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  去除烦人的 adblock 检测弹窗
// @author       https://github.com/yuzhanglong
// @match        https://zh.moegirl.org.cn/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=moegirl.org.cn
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  const mutationObserver = new MutationObserver((mutationsList) => {
    for (const mutation of mutationsList) {
      if (mutation.type === 'childList') {
        const adblockDialog = [...mutation.addedNodes].find((node) => {
          return node.className === 'fc-ab-root';
        });

        if (adblockDialog) {
          if (adblockDialog.innerHTML.includes('白名单')) {
            const closeButton = adblockDialog.getElementsByClassName('fc-close')[0];
            if (closeButton) {
              closeButton.click();
            }
          }
        }
      }
    }
  });

  mutationObserver.observe(document.body, { childList: true, subtree: true });
})();