WP Poczta - Adblock

Adblocker for https://poczta.wp.pl

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);
  }

})();