From d5d3f5c6d9323ec826756771149f5821d559ef69 Mon Sep 17 00:00:00 2001 From: cdhigh Date: Tue, 3 Sep 2024 09:56:37 -0300 Subject: [PATCH] save dark mode settings to db --- .../lib/ebook_translator/html_translator.py | 18 ++++++++++-------- application/static/reader.js | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/application/lib/ebook_translator/html_translator.py b/application/lib/ebook_translator/html_translator.py index f3360384..7498c079 100644 --- a/application/lib/ebook_translator/html_translator.py +++ b/application/lib/ebook_translator/html_translator.py @@ -119,13 +119,13 @@ def _tag_is_filtered(tag): def _extract(tag, position): for child in tag.find_all(recursive=False): if _contains_text(child) and not _tag_is_filtered(child): - text = str(child).strip() - if text: - #因为非AI翻译容易误翻译超链接里面的内容,所以这里去掉超链接 - if position != 'replace' and ']*>', '', text) - text = text.replace('', '') - elements.append((child, text)) + text = str(child).strip() if position == 'replace' else child.get_text() + elements.append((child, text)) + #if text: + # #因为非AI翻译容易误翻译超链接里面的内容,所以这里去掉超链接 + # if position != 'replace' and ']*>', '', text) + # text = text.replace('', '') else: _extract(child, position) @@ -148,7 +148,9 @@ def add_translation_soup(self, soup, tag, trans, dst): transTag = transTag.contents[0] if isinstance(transTag, NavigableString): oldTxt = str(transTag) - transTag = soup.new_tag('span') + transTagName = 'span' if tag.name in ('title', 'tr', 'td', 'th', 'thead', 'tbody', 'table', + 'ul', 'ol', 'li', 'a') else tag.name + transTag = soup.new_tag(transTagName) transTag.string = oldTxt if origStyle: diff --git a/application/static/reader.js b/application/static/reader.js index 5ca12a1d..9152af9c 100644 --- a/application/static/reader.js +++ b/application/static/reader.js @@ -669,7 +669,7 @@ function decreaseFontSize() { //将目前的配置保存到服务器 function saveSettings() { ajax_post('/reader/settings', {fontSize: g_fontSize, allowLinks: g_allowLinks, inkMode: g_inkMode, - topleftDict: g_topleftDict}); + darkMode: g_darkMode, topleftDict: g_topleftDict}); } //显示触摸区域图示