Skip to content

Commit

Permalink
more useful empty chapter message
Browse files Browse the repository at this point in the history
  • Loading branch information
nyagami committed Nov 27, 2024
1 parent 5db79a0 commit 2c9df1d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/screens/reader/hooks/useChapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ export default function useChapter(webViewRef: RefObject<WebView>) {
})
.catch(e => setError(e.message));
}
setChapterText(sanitizeChapterText(text));
setChapterText(
sanitizeChapterText(novel.pluginId, novel.name, chapter.name, text),
);
const [nextChap, prevChap] = await Promise.all([
getNextChapter(chapter.novelId, chapter.id),
getPrevChapter(chapter.novelId, chapter.id),
Expand Down
16 changes: 14 additions & 2 deletions src/screens/reader/utils/sanitizeChapterText.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { getString } from '@strings/translations';
import sanitizeHtml from 'sanitize-html';

export const sanitizeChapterText = (html: string): string => {
export const sanitizeChapterText = (
pluginId: string,
novelName: string,
chapterName: string,
html: string,
): string => {
let text = sanitizeHtml(html, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat([
'img',
Expand All @@ -23,5 +28,12 @@ export const sanitizeChapterText = (html: string): string => {
},
allowedSchemes: ['data', 'http', 'https', 'file'],
});
return text || getString('readerScreen.emptyChapterMessage');
return (
text ||
getString('readerScreen.emptyChapterMessage', {
pluginId,
novelName,
chapterName,
})
);
};
2 changes: 1 addition & 1 deletion strings/languages/en/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@
"scrollToCurrentChapter": "Scroll to current chapter",
"scrollToTop": "Scroll to top"
},
"emptyChapterMessage": "<p>Chapter is empty.</p><p>Report on <a href='https://github.com/LNReader/lnreader-sources/issues/new/choose'>GitHub</a> if it's available in WebView.</p>",
"emptyChapterMessage": "<p>Chapter is empty.</p><p>Report on <a href='https://github.com/LNReader/lnreader-sources/issues/new/choose'>GitHub</a> if it's available in WebView.</p><p>Plugin: %{pluginId}</p><p>Novel: %{novelName}</p><p>Chapter: %{chapterName}</p>",
"finished": "Finished",
"nextChapter": "Next: %{name}",
"noNextChapter": "There's no next chapter",
Expand Down
2 changes: 1 addition & 1 deletion strings/languages/vi_VN/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
"scrollToCurrentChapter": "Chương hiện tại",
"scrollToTop": "Lên đầu"
},
"emptyChapterMessage": "<p>Chương này trống.</p><p>Báo lỗi tại<a href='https://github.com/LNReader/lnreader-sources/issues/new/choose'>GitHub</a>nếu như chương vẫn hiện thị ở WebView.</p>",
"emptyChapterMessage": "<p>Chương này trống.</p><p>Báo lỗi tại <a href='https://github.com/LNReader/lnreader-sources/issues/new/choose'>GitHub</a> nếu như chương vẫn hiện thị ở WebView.</p><p>Plugin: %{pluginId}</p><p>Novel: %{novelName}</p><p>Chapter: %{chapterName}</p>",
"finished": "Đã xong",
"nextChapter": "Tiếp: %{name}",
"noNextChapter": "Không có chương kế tiếp",
Expand Down

0 comments on commit 2c9df1d

Please sign in to comment.