Hide sponsored posts na LinkedIn / Facebook / Twitter / X — CSS + MutationObserver
Social media feeds są ~30% sponsored posts wmieszanych w organic. Sponsored posts są zaprojektowane żeby nie wyglądać jak ads — random class hash'e, dynamic DOM. Standard ad-blockery łapią z URL pattern (DoubleClick, Adsense), nie z layout'u feed'a. Tu JustZix kombinacja CSS + JS daje sobie radę.
LinkedIn (linkedin.com)
LinkedIn ma najbardziej obfuscated DOM. Class names typu .feed-shared-update-v2--ad są stabilne, ale zmieniają się przy każdym redesign'ie. Text matching jest reliable:
/* CSS attempt — łapie niektóre */
[data-ad-banner], .feed-shared-update-v2--promoted,
.feed-shared-actor__sub-description:has-text("Promoted") {
display: none !important;
}
CSS :has-text() NIE jest standard — to JustZix-only pseudo. Fallback przez JS MutationObserver:
// JS rule — text-match "Promoted" w feed cards
const hideSponsored = () => {
document.querySelectorAll('.feed-shared-update-v2, [data-id*="urn:li:activity"]').forEach(card => {
if (card.dataset.jzChecked) return;
card.dataset.jzChecked = '1';
const text = card.textContent;
if (/^Promoted|Sponsored/m.test(text) ||
/\bPromoted\b/.test(card.querySelector('.feed-shared-actor__sub-description')?.textContent || '')) {
card.style.display = 'none';
JUSTZIX.log(`[LinkedIn] Hidden sponsored card`);
}
});
};
new MutationObserver(hideSponsored).observe(document.body, {childList: true, subtree: true});
hideSponsored();
Facebook (facebook.com)
FB ma ARIA-based markers — bardziej stabilne niż class names:
/* Posts z "Sponsored" labelem — Facebook używa aria attributes */
div[aria-label="Sponsored"],
div:has(> * > span[aria-label="Sponsored"]),
[data-pagelet*="Sponsored"] {
display: none !important;
}
/* Side rail z "Suggested for you" */
[aria-label="Suggested for you"], [aria-label="Reels and short videos"] {
display: none !important;
}
JS booster — czyści feed po scroll, tj. infinite scroll loading wstawia nowe posts:
// JS rule
new MutationObserver(() => {
document.querySelectorAll('div[role="feed"] > div').forEach(post => {
if (post.dataset.jzChecked) return;
post.dataset.jzChecked = '1';
if (post.querySelector('[aria-label="Sponsored"]')) {
post.style.display = 'none';
JUSTZIX.log('[FB] Hidden sponsored');
}
});
}).observe(document.body, {childList: true, subtree: true});
Twitter / X (twitter.com / x.com)
X ma "Promoted" label w SVG icon + text. Twitter też ma "Suggestion" / "Trends for you" sidebary:
/* Sponsored tweets */
article:has([data-testid="promotedIndicator"]),
article:has(svg[data-testid="ad"]) {
display: none !important;
}
/* Trends + Who to follow sidebar */
[aria-label="Timeline: Trending now"],
[data-testid="sidebarColumn"] [data-testid="UserCell"] {
display: none !important;
}
Use case 1 — TOGGLE3 "Ad protection level"
Per-platform 3-stage strict-ness:
// Akcja TOGGLE3 "🛡️ Protection"
states[0] = { label: 'Off', value: 'off' } // brak filtrowania
states[1] = { label: 'Normal', value: 'normal' } // hide sponsored
states[2] = { label: 'Strict', value: 'strict' } // hide sponsored + suggested + trends
code: |
document.documentElement.dataset.jzProtection = value;
JUSTZIX.log(`Protection: ${value}`);
CSS rule używa data attribute:
html[data-jz-protection="off"] .jz-hide-sponsored { display: block !important; }
html[data-jz-protection="strict"] [aria-label*="Suggested"] { display: none !important; }
Use case 2 — Output Console liczy ukrywane elementy
// W JS rule:
let hiddenCount = 0;
window.JZ_HIDDEN_SPONSORED = () => {
JUSTZIX.log(`[${location.hostname}] Hidden sponsored count: ${hiddenCount}`);
};
// W każdym .style.display = 'none' inkrementuj: hiddenCount++;
// Wywołaj z JS Console: JZ_HIDDEN_SPONSORED()
Pułapki
- Selektory się zmieniają. Social media platformy często reorganizują DOM żeby utrudnić blokowanie. Test reguł raz w miesiącu.
- Text-matching jest fragile dla i18n. "Promoted" / "Sponsored" / "Reklama" / "Promocja" — różne języki. Add regex disjunction.
- MutationObserver expensive na duże feedy. Throttle obserwer (setTimeout 200ms debounce) jeśli FPS dropuje.
- :has-text() nie jest CSS standard. JustZix go obsługuje. W natywnym CSS użyj :has(div:contains(...)) (też nonstandard) lub JS observer.
Co dalej
- Ukryj cookie banery — siostrzany pattern
- Customize AI chat apps — CSS + JS observer pattern
- TOGGLE3 — 3-state protection switcher
Zainstaluj JustZix i odzyskaj 30% feed'u z powrotem dla organic content.
Oceń ten wpis
Brak ocen — oceń jako pierwszy.