Guest User

Pracuj.pl - czarna lista firm

a guest
Oct 12th, 2026
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Pracuj.pl - czarna lista firm
  3. // @namespace    macgajster
  4. // @version      1.5
  5. // @match        https://www.pracuj.pl/*
  6. // @match        https://www.it.pracuj.pl/*
  7. // @run-at       document-idle
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12.     'use strict';
  13.  
  14.     const blacklist = [
  15.         'firma A',
  16.         'firma B',
  17.         'firma C'
  18.     ];
  19.  
  20.     const offerSelector = '#offers-list [data-test-offerid]';
  21.     const processedOffers = new WeakSet();
  22.     const seenOffers = new Set();
  23.     const hiddenOffers = new Set();
  24.  
  25.     const normalize = value =>
  26.         (value || '')
  27.             .toLocaleLowerCase('pl')
  28.             .replace(/\s+/g, ' ')
  29.             .trim();
  30.  
  31.     function getCompanyNames(offer) {
  32.         return Array.from(
  33.             offer.querySelectorAll('[data-test="link-company-profile"]')
  34.         )
  35.             .map(link =>
  36.                 link.textContent ||
  37.                 link.getAttribute('title') ||
  38.                 ''
  39.             )
  40.             .map(name => name.trim())
  41.             .filter(Boolean);
  42.     }
  43.  
  44.     function createWarning(company) {
  45.         const warning = document.createElement('div');
  46.  
  47.         warning.dataset.blacklistWarning = '1';
  48.         warning.style.cssText = [
  49.             'background:#fff3cd',
  50.             'border:1px solid #ffc107',
  51.             'border-radius:8px',
  52.             'padding:8px 12px',
  53.             'margin:8px 0',
  54.             'color:#856404',
  55.             'font-weight:600'
  56.         ].join(';');
  57.  
  58.         warning.textContent = `🚫 Ukryto ofertÄ™ firmy: ${company}`;
  59.         return warning;
  60.     }
  61.  
  62.     function updateStatus() {
  63.         let status = document.getElementById('blacklist-script-status');
  64.  
  65.         if (!status) {
  66.             status = document.createElement('div');
  67.             status.id = 'blacklist-script-status';
  68.             status.style.cssText = [
  69.                 'position:fixed',
  70.                 'right:12px',
  71.                 'bottom:12px',
  72.                 'z-index:2147483647',
  73.                 'background:#222',
  74.                 'color:#fff',
  75.                 'padding:8px 12px',
  76.                 'border-radius:6px',
  77.                 'font:13px/1.4 sans-serif',
  78.                 'box-shadow:0 2px 8px #0005'
  79.             ].join(';');
  80.  
  81.             document.body.appendChild(status);
  82.         }
  83.  
  84.         status.textContent =
  85.             `Czarna lista: kart znalezionych: ${seenOffers.size}, ukrytych: ${hiddenOffers.size}`;
  86.     }
  87.  
  88.     function processOffer(offer) {
  89.         if (processedOffers.has(offer)) {
  90.             return;
  91.         }
  92.  
  93.         const companyNames = getCompanyNames(offer);
  94.  
  95.         // JeÅ›li karta jest dodana przed nazwÄ… firmy, spróbujemy ponownie
  96.         // po kolejnym dodaniu elementów do tej karty.
  97.         if (companyNames.length === 0) {
  98.             return;
  99.         }
  100.  
  101.         processedOffers.add(offer);
  102.         seenOffers.add(offer);
  103.  
  104.         const matchedName = blacklist.find(blockedName =>
  105.             companyNames.some(companyName =>
  106.                 normalize(companyName).includes(normalize(blockedName))
  107.             )
  108.         );
  109.  
  110.         if (matchedName) {
  111.             const companyName =
  112.                 companyNames.find(name =>
  113.                     normalize(name).includes(normalize(matchedName))
  114.                 ) || matchedName;
  115.  
  116.             offer.parentNode.insertBefore(
  117.                 createWarning(companyName),
  118.                 offer
  119.             );
  120.  
  121.             offer.style.setProperty('display', 'none', 'important');
  122.             hiddenOffers.add(offer);
  123.         }
  124.  
  125.         updateStatus();
  126.     }
  127.  
  128.     function findOffersIn(node) {
  129.         if (!(node instanceof Element)) {
  130.             return;
  131.         }
  132.  
  133.         if (node.matches(offerSelector)) {
  134.             processOffer(node);
  135.         }
  136.  
  137.         node.querySelectorAll(offerSelector).forEach(processOffer);
  138.     }
  139.  
  140.     // Jednorazowe sprawdzenie ofert już obecnych na stronie.
  141.     document.querySelectorAll(offerSelector).forEach(processOffer);
  142.  
  143.     // Obserwujemy wyłącznie dodawanie elementów, nie zmiany tekstu i atrybutów.
  144.     let pendingNodes = new Set();
  145.     let scheduled = false;
  146.  
  147.     const observer = new MutationObserver(mutations => {
  148.         for (const mutation of mutations) {
  149.             for (const node of mutation.addedNodes) {
  150.                 if (node instanceof Element) {
  151.                     pendingNodes.add(node);
  152.                 }
  153.             }
  154.         }
  155.  
  156.         if (scheduled || pendingNodes.size === 0) {
  157.             return;
  158.         }
  159.  
  160.         scheduled = true;
  161.  
  162.         requestAnimationFrame(() => {
  163.             scheduled = false;
  164.  
  165.             const nodesToProcess = pendingNodes;
  166.             pendingNodes = new Set();
  167.  
  168.             nodesToProcess.forEach(findOffersIn);
  169.         });
  170.     });
  171.  
  172.     observer.observe(document.body, {
  173.         childList: true,
  174.         subtree: true
  175.     });
  176.  
  177.     updateStatus();
  178. })();
  179.  
Advertisement
Add Comment
Please, Sign In to add comment