Skip to content

Commit

Permalink
feat: add padding config for reader mode. fix #33
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed Dec 7, 2024
1 parent a40ed5b commit b4f4d59
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/src/main/assets/MozReadability.js
Original file line number Diff line number Diff line change
Expand Up @@ -2407,4 +2407,11 @@ function getReadingTime(length, lang = "en") {
}

return "";
}

function setPadding(paddingValue) {
var elements = document.getElementsByClassName('mozac-readerview-body');
for (var i = 0; i < elements.length; i++) {
elements[i].style.padding = paddingValue + 'px';
}
}
2 changes: 1 addition & 1 deletion app/src/main/assets/process_text_nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function convertToVerticalStyle(node) {
if (node.nodeType === Node.TEXT_NODE) {
let text = convertToFullWidth(node.nodeValue);
// 1.1 | 1. | 2024 | a.
const regex = /(\b\d\.\d\b|\d{1}\.(?=\s|\b)|\d{1,4}|\b[a-zA-Z]\.|\b[a-zA-Z]{1,3}(?![a-zA-Z]))/g;
const regex = /(\b\d\.\d\b|\d{1}\.(?=\s|\b)|\d{1,4}|\b[a-zA-Z]\.|\b[a-zA-Z]{1,3}(?![a-zA-Z])(?!\S))/g;
let match;
let lastIndex = 0;
const fragment = document.createDocumentFragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ class SettingActivity : FragmentActivity() {
R.string.setting_summary_page_left_value,
config::pageReservedOffsetInString
),
ValueSettingItem(
R.string.setting_title_reader_mode_padding,
0,
R.string.setting_summary_reader_mode_padding,
config::paddingForReaderMode
),
ListSettingWithEnumItem(
R.string.dark_mode,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ class ConfigManager(

var fontBoldness by IntPreference(sp, K_FONT_BOLDNESS, 700)

private val K_PADDING_FOR_READER_MODE = "sp_padding_for_reader_mode"
var paddingForReaderMode by IntPreference(sp, K_PADDING_FOR_READER_MODE, 10)

var customUserAgent by StringPreference(sp, K_CUSTOM_USER_AGENT)
val customProcessTextUrl by StringPreference(sp, K_CUSTOM_PROCESS_TEXT_URL)
var preferredTranslateLanguageString by StringPreference(sp, K_TRANSLATED_LANGS)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/info/plateaukao/einkbro/view/EBWebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,9 @@ open class EBWebView(
// need to wait for a while to jump to top, so that vertical read starts from beginning
postDelayed({ jumpToTop() }, 200)
}
} else {
// add padding
setPaddingInReaderMode(config.paddingForReaderMode)
}
}
}
Expand All @@ -780,6 +783,10 @@ open class EBWebView(
}
}

private fun setPaddingInReaderMode(padding: Int) {
evaluateJavascript("javascript:setPadding($padding)", null)
}

fun clearTranslationElements() {
evaluateJavascript(clearTranslationElementsJs, null)
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,6 @@
<string name="deepl_translate_by_paragraph">Deepl by Paragraph</string>
<string name="dialog_message_remove_highlight">Remove highlight?</string>
<string name="read_from_here">Read from here</string>
<string name="setting_title_reader_mode_padding">Padding for reader mode</string>
<string name="setting_summary_reader_mode_padding">Padding value (in px) for reader mode, default value is 10</string>
</resources>
6 changes: 4 additions & 2 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@
<string name="gray">灰色字體</string>
<string name="bold">粗體字</string>
<string name="deepl_translate_by_paragraph">Deepl by Paragraph</string>
<string name="dialog_message_remove_highlight">Remove highlight?</string>
<string name="read_from_here">Read from here</string>
<string name="dialog_message_remove_highlight">移除劃線?</string>
<string name="read_from_here">從這裡開始朗讀</string>
<string name="setting_title_reader_mode_padding">閱讀模式的留白</string>
<string name="setting_summary_reader_mode_padding">閱讀模式的四周留白(單位: px) 預設值是 10</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,6 @@
<string name="deepl_translate_by_paragraph">Deepl by Paragraph</string>
<string name="dialog_message_remove_highlight">Remove highlight?</string>
<string name="read_from_here">From here</string>
<string name="setting_title_reader_mode_padding">Padding for reader mode</string>
<string name="setting_summary_reader_mode_padding">Padding value (in px) for reader mode, default value is 10</string>
</resources>

0 comments on commit b4f4d59

Please sign in to comment.