mirror of
https://github.com/Andre-Bzk/AnyClip.git
synced 2026-11-15 09:33:08 +01:00
Anzeigenfilter überarbeitet
This commit is contained in:
+73
-3
@@ -173,6 +173,7 @@ function cleanClone(node) {
|
|||||||
clone.querySelectorAll(selector).forEach((element) => element.remove());
|
clone.querySelectorAll(selector).forEach((element) => element.remove());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
removeEditorialRecommendationSections(clone);
|
||||||
removePromotionalBlocks(clone);
|
removePromotionalBlocks(clone);
|
||||||
|
|
||||||
clone.querySelectorAll("a[href]").forEach((link) => {
|
clone.querySelectorAll("a[href]").forEach((link) => {
|
||||||
@@ -430,6 +431,7 @@ function sanitizeSectionClone(wrapper) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
removeEditorialRecommendationSections(wrapper);
|
||||||
removePromotionalBlocks(wrapper);
|
removePromotionalBlocks(wrapper);
|
||||||
|
|
||||||
wrapper.querySelectorAll("a[href]").forEach((link) => {
|
wrapper.querySelectorAll("a[href]").forEach((link) => {
|
||||||
@@ -441,6 +443,59 @@ function sanitizeSectionClone(wrapper) {
|
|||||||
wrapper.querySelectorAll('.comments, #comments, [class*="comment-thread"], [class*="comment-list"]').forEach((element) => element.remove());
|
wrapper.querySelectorAll('.comments, #comments, [class*="comment-thread"], [class*="comment-list"]').forEach((element) => element.remove());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeEditorialRecommendationSections(root) {
|
||||||
|
if (!root || typeof root.querySelectorAll !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const editorialHeadingPatterns = [
|
||||||
|
/^empfehlungen der redaktion$/i,
|
||||||
|
/^das könnte (dich|euch|sie) (auch )?interessieren$/i,
|
||||||
|
/^mehr zum thema$/i,
|
||||||
|
/^ähnliche (artikel|beiträge|news)$/i,
|
||||||
|
/^verwandte (artikel|beiträge)$/i,
|
||||||
|
/^sponsored( post| content)?$/i,
|
||||||
|
/^weitere (artikel|news|beiträge) (zum thema|dazu)$/i,
|
||||||
|
/^lesen sie auch$/i,
|
||||||
|
];
|
||||||
|
|
||||||
|
const cssRecommendationSelectors = [
|
||||||
|
'[class*="recommendation"]',
|
||||||
|
'[class*="related-article"]',
|
||||||
|
'[class*="more-articles"]',
|
||||||
|
'[class*="further-reading"]',
|
||||||
|
'[data-component*="recommendation"]',
|
||||||
|
'[data-module*="recommendation"]',
|
||||||
|
];
|
||||||
|
|
||||||
|
cssRecommendationSelectors.forEach((selector) => {
|
||||||
|
root.querySelectorAll(selector).forEach((el) => el.remove());
|
||||||
|
});
|
||||||
|
|
||||||
|
const headings = Array.from(root.querySelectorAll('h2, h3, h4'));
|
||||||
|
|
||||||
|
for (const heading of headings) {
|
||||||
|
const text = (heading.textContent || '').trim();
|
||||||
|
const isEditorial = editorialHeadingPatterns.some((pattern) => pattern.test(text));
|
||||||
|
|
||||||
|
if (!isEditorial) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let container = heading.parentElement;
|
||||||
|
while (container && container !== root) {
|
||||||
|
if (container.children.length >= 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
container = container.parentElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (container && container !== root) {
|
||||||
|
container.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function removePromotionalBlocks(root) {
|
function removePromotionalBlocks(root) {
|
||||||
if (!root || typeof root.querySelectorAll !== "function") {
|
if (!root || typeof root.querySelectorAll !== "function") {
|
||||||
return;
|
return;
|
||||||
@@ -449,13 +504,24 @@ function removePromotionalBlocks(root) {
|
|||||||
const candidates = Array.from(root.querySelectorAll("div, section, aside, p, blockquote, ul"));
|
const candidates = Array.from(root.querySelectorAll("div, section, aside, p, blockquote, ul"));
|
||||||
candidates.forEach((element) => {
|
candidates.forEach((element) => {
|
||||||
const text = normalizeInlineWhitespace(element.textContent || "").trim().toLowerCase();
|
const text = normalizeInlineWhitespace(element.textContent || "").trim().toLowerCase();
|
||||||
const paragraphCount = element.querySelectorAll("p").length;
|
|
||||||
const listCount = element.querySelectorAll("ul, ol").length;
|
|
||||||
|
|
||||||
if (!text || text.length < 18) {
|
if (!text) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check short promotional labels (e.g. "Anzeige") before the length guard
|
||||||
|
if (text.length <= 18 && isPromotionalTextBlock(text)) {
|
||||||
|
element.remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text.length < 18) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const paragraphCount = element.querySelectorAll("p").length;
|
||||||
|
const listCount = element.querySelectorAll("ul, ol").length;
|
||||||
|
|
||||||
if (text.length > 600 || paragraphCount > 2 || listCount > 1) {
|
if (text.length > 600 || paragraphCount > 2 || listCount > 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -471,6 +537,10 @@ function isPromotionalTextBlock(text) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (/^anzeige[.:!]?$/.test(text)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (/kein bock auf werbung\?/.test(text)) {
|
if (/kein bock auf werbung\?/.test(text)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user