diff --git a/backend/src/tools/paywallkiller/routes.js b/backend/src/tools/paywallkiller/routes.js index a00eabc..76004f8 100644 --- a/backend/src/tools/paywallkiller/routes.js +++ b/backend/src/tools/paywallkiller/routes.js @@ -85,29 +85,73 @@ router.post('/pdf', authenticate, async (req, res) => { await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'); await page.setViewport({ width: 1280, height: 900 }); await page.goto(targetUrl, { waitUntil: 'networkidle0', timeout: 30000 }); - await new Promise(r => setTimeout(r, 1500)); - await page.addStyleTag({ content: ` - [class*="paywall"],[class*="Paywall"],[id*="paywall"], - [class*="piano"],[class*="Piano"],[id*="piano"], - [class*="subscription"],[class*="subscribe"], - [class*="overlay"],[class*="modal"], - [class*="cookie"],[class*="Cookie"], - [class*="consent"],[class*="gdpr"], - .tp-modal,.tp-backdrop,#tp-container, - .article__paywall,.funke-piano,.piano-checkout, - [data-testid*="paywall"],[data-testid*="piano"], - #usercentrics-root,.uc-banner, - #onetrust-consent-sdk,.onetrust-pc-dark-filter, - #wm-ipp-base,#wm-ipp,#donato, - [class*="ad-"],[class*="-ad-"],[class*="advertisement"] - { display:none !important; visibility:hidden !important; } - body,html { overflow:visible !important; height:auto !important; } - * { filter:none !important; } - ` }); + // Paywall-Elemente per JavaScript entfernen (effektiver als reines CSS) + await page.evaluate(() => { + // Selektoren für Paywall/Overlay-Elemente + const selectors = [ + // Generisch + '[class*="paywall"]', '[class*="Paywall"]', '[id*="paywall"]', + '[class*="piano"]', '[class*="Piano"]', '[id*="piano"]', + '[class*="subscription-wall"]', '[class*="subscriptionWall"]', + '[class*="overlay"]', '[class*="modal-backdrop"]', + // Cookie/Consent + '[class*="cookie-banner"]', '[class*="cookieBanner"]', + '[class*="consent"]', '[id*="consent"]', + '#usercentrics-root', '.uc-banner', + '#onetrust-consent-sdk', '.onetrust-pc-dark-filter', + // Piano/TP + '.tp-modal', '.tp-backdrop', '#tp-container', '.tp-active', + // Funke/WAZ spezifisch + '.funke-piano', '.piano-checkout', '.article__paywall', + '[data-piano-inline]', '[data-tp-content]', + // Werbung + '[id^="ad-"]', '[class*="advertisement"]', + // Wayback toolbar + '#wm-ipp-base', '#wm-ipp', '#donato', + ]; + + // Elemente entfernen + selectors.forEach(sel => { + try { + document.querySelectorAll(sel).forEach(el => el.remove()); + } catch {} + }); + + // body/html overflow und blur zurücksetzen + document.body.style.overflow = 'visible'; + document.documentElement.style.overflow = 'visible'; + + // Alle blur-Filter entfernen + document.querySelectorAll('*').forEach(el => { + const style = window.getComputedStyle(el); + if (style.filter && style.filter !== 'none') { + el.style.filter = 'none'; + } + // Versteckte Artikel-Inhalte aufdecken + if (el.getAttribute('aria-hidden') === 'true') { + const tag = el.tagName.toLowerCase(); + if (['p','div','section','article'].includes(tag)) { + el.removeAttribute('aria-hidden'); + } + } + }); + + // max-height Limits auf Artikel entfernen + document.querySelectorAll('article, [class*="article"], [class*="content"]').forEach(el => { + el.style.maxHeight = 'none'; + el.style.overflow = 'visible'; + el.style.webkitMaskImage = 'none'; + el.style.maskImage = 'none'; + }); + }); + + // Kurz warten damit DOM-Änderungen rendern + await new Promise(r => setTimeout(r, 500)); await page.pdf({ path: tmpFile, format: 'A4', printBackground: true, + printBackground: true, margin: { top: '12mm', bottom: '12mm', left: '12mm', right: '12mm' }, }); await browser.close(); browser = null;