나무위키 광고 삭제

모르겠다 이제

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        나무위키 광고 삭제
// @namespace   Violentmonkey Scripts
// @icon        https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://namu.wiki
// @match       https://namu.wiki/*
// @grant       none
// @version     1.27
// @author      Xlbatross
// @run-at      document-end
// @description 모르겠다 이제
// ==/UserScript==

// 변경 전 Power Link
const powerLink2 = document.querySelector('[style="margin 0; color: #d9d7ce1f"]');
powerLink2?.remove();

// 변경을 감지할 노드 선택
const targetNode = document.body;

// 감지 옵션 (감지할 변경)
const config = { childList: true, subtree: true };

// 변경 감지 시 실행할 콜백 함수
const callback = (mutationList, observer) => {
  for (const mutation of mutationList) {
    if (mutation.type === "childList") {
      const addedNodes = mutation.addedNodes;
      if (addedNodes.length > 0) {
        let parent;

        const queryId = mutation.target.querySelector('[data-google-query-id]');
        parent = queryId;
        while (parent && parent.parentElement.children.length == 1) {
          let oldParent = parent;
          parent = parent.parentElement;
          if (!parent) {
            parent = oldParent;
            break;
          }
        }
        parent?.remove();

        // Power Link
        const powerLink1 = mutation.target.querySelector('[style*="color: rgba(217, 215, 206, 0.12);"]');
        powerLink1?.remove();
      }
    }
  }
};

// 콜백 함수에 연결된 감지기 인스턴스 생성
const observer = new MutationObserver(callback);

// 설정한 변경의 감지 시작
observer.observe(targetNode, config);