console.log("[MemberFilter] content script loaded"); const seen = new WeakSet(); let whitelist = []; /* ---------------- CSS injection ---------------- */ function injectStyleOnce() { if (document.getElementById("member-filter-style")) return; const style = document.createElement("style"); style.id = "member-filter-style"; style.textContent = ` [data-member-filter-hidden="true"] { display: none !important; } `; document.head.appendChild(style); } injectStyleOnce(); /* ---------------- load whitelist ---------------- */ function loadWhitelist() { chrome.storage.local.get({ whitelist: [] }, data => { whitelist = data.whitelist.map(n => n.toLowerCase()); console.log("[MemberFilter] whitelist loaded:", whitelist); }); } loadWhitelist(); // Reload whitelist if popup changes it chrome.storage.onChanged.addListener(loadWhitelist); /* ---------------- detection logic ---------------- */ function process(root = document) { const badges = root.querySelectorAll("badge-shape"); badges.forEach(badge => { if (!badge.textContent?.includes("Nur für Kanalmitglieder")) return; const video = badge.closest( "ytd-rich-item-renderer, ytd-video-renderer, ytd-grid-video-renderer" ); if (!video) return; if (seen.has(video)) return; seen.add(video); const titleEl = video.querySelector("#video-title"); const channelEl = video.querySelector("ytd-channel-name a") || video.querySelector(".ytd-channel-name a"); const title = titleEl?.textContent?.trim() ?? "(no title)"; const url = titleEl?.href ?? "(no url)"; const channel = channelEl?.textContent?.trim() ?? "(no channel)"; const channelKey = channel.toLowerCase(); const whitelisted = whitelist.includes(channelKey); console.group("[MemberFilter]"); console.log("Title :", title); console.log("Channel:", channel); console.log("URL :", url); console.log("Whitelisted:", whitelisted); console.groupEnd(); if (!whitelisted) { video.setAttribute("data-member-filter-hidden", "true"); } }); } /* ---------------- initial + observer ---------------- */ process(); const observer = new MutationObserver(mutations => { for (const m of mutations) { for (const node of m.addedNodes) { if (node instanceof HTMLElement) { process(node); } } } }); observer.observe(document.body, { childList: true, subtree: true });