나무위키 광고 삭제

모르겠다 이제

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);