WP Poczta - Adblock

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

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            WP Poczta - Adblock
// @description:pl  Adblocker for https://poczta.wp.pl
// @description:en  Adblocker for https://poczta.wp.pl
// @version         10
// @include         https://poczta.wp.pl/*
// @grant           none
// @run-at          document-start
// @namespace https://greasyfork.org/users/1628334
// ==/UserScript==

(function() {
  'use strict';

  const injectCSS = () => {
    const style = document.createElement('style');
    style.innerHTML = `
      div.pt_2.pb_2.pl_4.pr_2.bg-c_white.min-h_unset,
      div[class*="print-hide-tactic_removed"],
      div[class*="h_168px"] {
        display: none !important;
      }
    `;
    if (document.head) document.head.appendChild(style);
    else document.addEventListener('DOMContentLoaded', () => document.head.appendChild(style));
  };
  injectCSS();

  let btnClicked = false;
  let updateScheduled = false;

  const runTextChecks = () => {
    updateScheduled = false;

    if (!btnClicked) {
      const buttons = document.querySelectorAll('button');
      for (const btn of buttons) {
        if (btn.textContent.includes('Rozumiem ryzyko, przechodzę do poczty')) {
          btn.click();
          btnClicked = true;
          break; 
        }
      }
    }

    const wpDivs = document.querySelectorAll('div.flex-sh_1.trunc_true');
    for (const div of wpDivs) {
      if (div.textContent.includes('/WP')) {
        const parent = div.closest('div.group.d_flex.flex-d_column') || div.closest('div.cursor_pointer');
        if (parent && parent.style.display !== 'none') {
          parent.style.setProperty('display', 'none', 'important');
        }
      }
    }

    const pocztaDivs = document.querySelectorAll('div.textStyle_bodyBoldMd');
    for (const div of pocztaDivs) {
      if (div.textContent.includes('Poczta')) {
        const parent = div.closest('div.group.d_flex.flex-d_column') || div.closest('div.cursor_pointer');
        if (parent && parent.style.display !== 'none') {
          parent.style.setProperty('display', 'none', 'important');
        }
      }
    }
  };

  const observer = new MutationObserver((mutations) => {
    const hasNewNodes = mutations.some(m => m.addedNodes.length > 0);
    if (!hasNewNodes) return;

    if (!updateScheduled) {
      updateScheduled = true;
      requestAnimationFrame(runTextChecks);
    }
  });

  const initObserver = () => {
    observer.observe(document.body, { childList: true, subtree: true });
    runTextChecks();
  };

  if (document.body) {
    initObserver();
  } else {
    document.addEventListener('DOMContentLoaded', initObserver);
  }

})();