Skip to content

Commit

Permalink
don't turn on reader mode in onyx translate feature
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed Jun 27, 2021
1 parent 90a4b48 commit 0dc3638
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
30 changes: 15 additions & 15 deletions app/src/main/java/de/baumann/browser/view/NinjaWebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -401,21 +401,21 @@ class NinjaWebView : WebView, AlbumController {

// only works in isReadModeOn
suspend fun getRawText() = suspendCoroutine<String> { continuation ->
// if (!isReaderModeOn) {
// injectMozReaderModeJs(false)
// evaluateJavascript(getReaderModeBodyTextJs) { text -> continuation.resume(text.substring(1, text.length-2)) }
// } else {
if (!isReaderModeOn) continuation.resume("")

evaluateJavascript(
"(function() { return document.getElementsByTagName('html')[0].innerText; })();"
) { text ->
val processedText = if (text.startsWith("\"") && text.endsWith("\"")) {
text.substring(1, text.length-2)
} else text
continuation.resume(processedText)
}
// }
if (!isReaderModeOn) {
injectMozReaderModeJs(false)
evaluateJavascript(getReaderModeBodyTextJs) { text -> continuation.resume(text.substring(1, text.length-2)) }
} else {
//if (!isReaderModeOn) continuation.resume("")

evaluateJavascript(
"(function() { return document.getElementsByTagName('html')[0].innerText; })();"
) { text ->
val processedText = if (text.startsWith("\"") && text.endsWith("\"")) {
text.substring(1, text.length-2)
} else text
continuation.resume(processedText)
}
}
}

private fun shiftOffset(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TranslationViewController(
}

suspend fun showTranslation(webView: NinjaWebView) {
if (!webView.isReaderModeOn) {
if (!webView.isReaderModeOn && config.translationMode != TranslationMode.ONYX) {
webView.toggleReaderMode { launchTranslateWindow(it.purify()) }
} else {
launchTranslateWindow(webView.getRawText().purify())
Expand All @@ -68,15 +68,10 @@ class TranslationViewController(
}
// onyx case
if (config.translationMode == TranslationMode.ONYX) {
(activity as LifecycleOwner).lifecycleScope.launch {
if (!ViewUnit.isMultiWindowEnabled(activity)) {
ViewUnit.toggleMultiWindow(activity, true)
delay(2000)
}
try {
launchOnyxDictTranslation(text)
} catch (ignored: ClassNotFoundException) {}
}
ViewUnit.toggleMultiWindow(activity, true)
try {
launchOnyxDictTranslation(text)
} catch (ignored: ClassNotFoundException) {}
return
}

Expand Down Expand Up @@ -105,7 +100,8 @@ class TranslationViewController(
val selected = valueArray.indexOf(config.translationMode.ordinal)
AlertDialog.Builder(activity, R.style.TouchAreaDialog).apply{
setTitle("Translation Mode")
setSingleChoiceItems(translationModeArray, selected) { _, which ->
setSingleChoiceItems(translationModeArray, selected) { dialog, which ->
dialog.dismiss()
config.translationMode = enumValues[which]
if (isTranslationModeOn()) showTranslationAction.invoke()
}
Expand Down

0 comments on commit 0dc3638

Please sign in to comment.