Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/src/main/assets/MozReadability.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function Readability(doc, options) {
return el.innerHTML;
};
this._disableJSONLD = !!options.disableJSONLD;
this._overwriteImgSrc = !!options.overwriteImgSrc;

// Start with all flags set
this._flags = this.FLAG_STRIP_UNLIKELYS |
Expand Down Expand Up @@ -1979,7 +1980,9 @@ Readability.prototype = {
}

// also check for "null" to work around https://github.com/jsdom/jsdom/issues/2580
if ((elem.src || (elem.srcset && elem.srcset != "null")) && elem.className.toLowerCase().indexOf("lazy") === -1) {
if ((elem.src || (elem.srcset && elem.srcset != "null")) &&
elem.className.toLowerCase().indexOf("lazy") === -1 &&
!this._overwriteImgSrc) {
return;
}

Expand All @@ -1991,7 +1994,8 @@ Readability.prototype = {
var copyTo = null;
if (/\.(jpg|jpeg|png|webp)\s+\d/.test(attr.value)) {
copyTo = "srcset";
} else if (/^\s*\S+\.(jpg|jpeg|png|webp)\S*\s*$/.test(attr.value)) {
} else if (/^\s*\S+\.(jpg|jpeg|png|webp)\S*\s*$/.test(attr.value) ||
/^\s*https?:\/\/\S+=(jpg|jpeg|png|webp)\S*\s*$/.test(attr.value)) {
copyTo = "src";
}
if (copyTo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import android.graphics.Bitmap
import android.graphics.Color
import android.net.Uri
import android.os.Message
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.webkit.ConsoleMessage
import android.webkit.CookieManager
import android.webkit.GeolocationPermissions
import android.webkit.PermissionRequest
Expand All @@ -24,6 +26,8 @@ class NinjaWebChromeClient(
private val ninjaWebView: NinjaWebView,
private val onReceiveFavicon: (Bitmap) -> Unit,
) : WebChromeClient() {
private val TAG: String = "NinjaWebChromeClient"

private lateinit var webviewParent: ViewGroup

override fun onCreateWindow(
Expand Down Expand Up @@ -156,6 +160,11 @@ class NinjaWebChromeClient(
super.onGeolocationPermissionsShowPrompt(origin, callback)
}

override fun onConsoleMessage(message: ConsoleMessage): Boolean {
Log.d(TAG, message.message())
return true
}

private val posterBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
.apply { setPixel(0, 0, Color.argb(0, 255, 255, 255)) }

Expand All @@ -166,4 +175,4 @@ class NinjaWebChromeClient(
val bitmap = icon ?: return
onReceiveFavicon(bitmap)
}
}
}
11 changes: 8 additions & 3 deletions app/src/main/java/info/plateaukao/einkbro/view/NinjaWebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1207,9 +1207,14 @@ open class NinjaWebView(
observer.observe(targetNode);
});
"""


private const val readabilityOptions =
"{classesToPreserve: preservedClasses, overwriteImgSrc: true}"

private const val replaceWithReaderModeBodyJs = """
var documentClone = document.cloneNode(true);
var article = new Readability(documentClone, {classesToPreserve: preservedClasses}).parse();
var article = new Readability(documentClone, $readabilityOptions).parse();
document.innerHTMLCache = document.body.innerHTML;

article.readingTime = getReadingTime(article.length, document.lang);
Expand All @@ -1222,7 +1227,7 @@ open class NinjaWebView(
private const val getReaderModeBodyHtmlJs = """
javascript:(function() {
var documentClone = document.cloneNode(true);
var article = new Readability(documentClone, {classesToPreserve: preservedClasses}).parse();
var article = new Readability(documentClone, $readabilityOptions).parse();
article.readingTime = getReadingTime(article.length, document.lang);
var bodyOuterHTML = createHtmlBodyWithUrl(article, "%s")
var headOuterHTML = document.head.outerHTML;
Expand All @@ -1232,7 +1237,7 @@ open class NinjaWebView(
private const val getReaderModeBodyTextJs = """
javascript:(function() {
var documentClone = document.cloneNode(true);
var article = new Readability(documentClone, {classesToPreserve: preservedClasses}).parse();
var article = new Readability(documentClone, $readabilityOptions).parse();
return article.title + ', ' + article.textContent;
})()
"""
Expand Down