diff options
Diffstat (limited to 'app/src/main/java/org/terst/feedreader/readability')
| -rw-r--r-- | app/src/main/java/org/terst/feedreader/readability/ReaderExtractor.kt | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/app/src/main/java/org/terst/feedreader/readability/ReaderExtractor.kt b/app/src/main/java/org/terst/feedreader/readability/ReaderExtractor.kt index 3eaa158..c41bbfb 100644 --- a/app/src/main/java/org/terst/feedreader/readability/ReaderExtractor.kt +++ b/app/src/main/java/org/terst/feedreader/readability/ReaderExtractor.kt @@ -136,6 +136,15 @@ object ReaderExtractor { // correctly from the (now-resolved) image's real dimensions. img.removeAttribute('width'); img.removeAttribute('height'); + // The browser's native loading="lazy" only fetches an image + // once it's near the (real, on-screen) viewport -- meaningless + // in this hidden, off-screen extraction WebView, where whether + // that ever counts as "near enough" is inconsistent run to run. + // Confirmed live: the same Ars Technica article's gallery photos + // came through in one extraction pass and were silently missing + // in another. Force every image to load immediately instead of + // leaving it to viewport-intersection timing that doesn't apply. + img.removeAttribute('loading'); } var sources = document.querySelectorAll('source'); for (var i = 0; i < sources.length; i++) { @@ -143,6 +152,29 @@ object ReaderExtractor { if (lazySrcset) sources[i].setAttribute('srcset', lazySrcset); } + // A lightbox (PhotoSwipe, and others like it) commonly keeps its own + // copy of an image's caption text in a separate div meant to only + // ever be shown inside the lightbox overlay -- confirmed live on Ars + // Technica: a ".pswp-caption-content" div sits right next to a real, + // normally-visible <figcaption> with the exact same text, inside the + // same <figure>. Readability's hidden-element skip only catches + // display:none/visibility:hidden, not however that div is actually + // kept offscreen until the lightbox opens, so it was coming through + // as a genuine second copy. Only remove it when that real figcaption + // sibling actually exists -- some of Ars's own gallery images use + // this same div as their ONLY caption (no figcaption at all), and + // removing those unconditionally just deleted their caption outright + // (confirmed live: two gallery photos lost their captions entirely + // rather than losing a duplicate). + var pswpCaptions = document.querySelectorAll('.pswp-caption-content'); + for (var i = 0; i < pswpCaptions.length; i++) { + var pc = pswpCaptions[i]; + var figure = pc.closest('figure'); + if (figure && figure.querySelector('figcaption')) { + pc.parentNode.removeChild(pc); + } + } + // Readability's default hidden-element skip (treating display:none / // visibility:hidden nodes as boilerplate) is correct for the vast // majority of sites -- it's what keeps collapsed nav/footer/sidebar |
