content.js
// Hide Likes: toggles classes on <html>; hide.css does the hiding. Settings sync from the popup.
const DEF = { enabled: true, counts: true, comments: false, generic: true, allow: [] };
const root = document.documentElement;
let cfg = DEF;
const NUM = /^\s*\d[\d.,\s]*(\s?[KkMmBb]|\s?(likes?|views?|comments?|replies|reposts?|followers?|Tsd\.|Mio\.))?\s*$/;
function markNumbers(node) {
if (!cfg.enabled || !cfg.counts || !cfg.generic) return;
// Only short numeric labels inside buttons, which is where like/repost counts live.
(node.querySelectorAll ? node : document).querySelectorAll('button span, [role="button"] span').forEach(s => {
if (!s.children.length && NUM.test(s.textContent)) s.classList.add('hl-num');
});
}
function apply() {
const host = location.hostname.replace(/^www\./, '');
const on = cfg.enabled && !cfg.allow.some(a => host.endsWith(a));
root.classList.toggle('hl-counts', on && cfg.counts);
root.classList.toggle('hl-comments', on && cfg.comments);
if (on) markNumbers(document);
}
chrome.storage.sync.get(DEF, v => { cfg = v; apply(); });
chrome.storage.onChanged.addListener(() => chrome.storage.sync.get(DEF, v => { cfg = v; apply(); }));
let pending = false;
new MutationObserver(() => { if (pending) return; pending = true; setTimeout(() => { pending = false; markNumbers(document); }, 400); })
.observe(document, { childList: true, subtree: true });