Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Pracuj.pl - ramki ofert według lokalizacji
- // @namespace macgajster
- // @version 1.3
- // @match https://www.pracuj.pl/*
- // @match https://www.it.pracuj.pl/*
- // @run-at document-idle
- // @grant none
- // ==/UserScript==
- (function () {
- 'use strict';
- // Zmień miasto tutaj:
- const CITY = 'Warszawa';
- const offerSelector = '[data-test="default-offer"][data-test-offerid]';
- const processedOffers = new WeakSet();
- const normalize = value =>
- (value || '')
- .toLocaleLowerCase('pl')
- .replace(/\s+/g, ' ')
- .trim();
- const targetCity = normalize(CITY);
- function processOffer(offer) {
- if (processedOffers.has(offer)) return;
- const infoText = normalize(
- Array.from(
- offer.querySelectorAll('li[data-test^="offer-additional-info"]')
- )
- .map(item => item.textContent)
- .join(' ')
- );
- const locationText = normalize(
- Array.from(offer.querySelectorAll('[data-test="text-region"]'))
- .map(element => element.textContent)
- .join(' ')
- );
- // Poczekaj, jeśli karta nie ma jeszcze załadowanych informacji.
- if (!infoText) return;
- const isRemote = infoText.includes('zdaln');
- const isHybrid = infoText.includes('hybryd');
- const isOnsite = infoText.includes('stacjonarn');
- const isTargetCity = locationText.includes(targetCity);
- if (isRemote) {
- offer.style.setProperty('outline', '3px solid #20a34a', 'important');
- offer.style.setProperty('outline-offset', '-3px', 'important');
- } else if (isHybrid || isOnsite) {
- const color = isTargetCity ? '#20a34a' : '#e53935';
- offer.style.setProperty('outline', `3px solid ${color}`, 'important');
- offer.style.setProperty('outline-offset', '-3px', 'important');
- }
- processedOffers.add(offer);
- }
- function processOffersWithin(node) {
- if (!(node instanceof Element)) return;
- if (node.matches(offerSelector)) {
- processOffer(node);
- }
- node.querySelectorAll(offerSelector).forEach(processOffer);
- }
- document.querySelectorAll(offerSelector).forEach(processOffer);
- const observer = new MutationObserver(mutations => {
- for (const mutation of mutations) {
- const target = mutation.target;
- const offer = target instanceof Element
- ? target.closest(offerSelector)
- : target.parentElement?.closest(offerSelector);
- if (offer) processOffer(offer);
- for (const node of mutation.addedNodes) {
- processOffersWithin(node);
- }
- }
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment