Webtoon Polish Part 2 (#739)
* Change css scoping to be on the book content itself only to prevent any leaking on the reading section code. Apply a margin so that book margins on the whole content doesn't show black lines. * Take out debug outline on webtoon reader * Removed some imports * Fixed an issue where when restoring current page in webtoon mode, the page number would jump forward * Last page on webtoon reader now properly counts. This was due to a - 1 issue fixing previous issues. * Fixed an issue where scrollToPage (from progress bar or go to page) wouldn't work if the page somehow was visible. * Ready for testing on beta users
This commit is contained in:
parent
336283be6e
commit
094c12d43d
5 changed files with 40 additions and 34 deletions
|
|
@ -30,6 +30,7 @@ namespace API.Services
|
|||
private readonly ILogger<BookService> _logger;
|
||||
private readonly StylesheetParser _cssParser = new ();
|
||||
private static readonly RecyclableMemoryStreamManager StreamManager = new ();
|
||||
private const string CssScopeClass = ".book-content";
|
||||
|
||||
public BookService(ILogger<BookService> logger)
|
||||
{
|
||||
|
|
@ -152,22 +153,23 @@ namespace API.Services
|
|||
EscapeCssImageReferences(ref stylesheetHtml, apiBase, book);
|
||||
|
||||
var styleContent = RemoveWhiteSpaceFromStylesheets(stylesheetHtml);
|
||||
styleContent = styleContent.Replace("body", ".reading-section");
|
||||
|
||||
styleContent = styleContent.Replace("body", CssScopeClass);
|
||||
|
||||
if (string.IsNullOrEmpty(styleContent)) return string.Empty;
|
||||
|
||||
var stylesheet = await _cssParser.ParseAsync(styleContent);
|
||||
foreach (var styleRule in stylesheet.StyleRules)
|
||||
{
|
||||
if (styleRule.Selector.Text == ".reading-section") continue;
|
||||
if (styleRule.Selector.Text == CssScopeClass) continue;
|
||||
if (styleRule.Selector.Text.Contains(","))
|
||||
{
|
||||
styleRule.Text = styleRule.Text.Replace(styleRule.SelectorText,
|
||||
string.Join(", ",
|
||||
styleRule.Selector.Text.Split(",").Select(s => ".reading-section " + s)));
|
||||
styleRule.Selector.Text.Split(",").Select(s => $"{CssScopeClass} " + s)));
|
||||
continue;
|
||||
}
|
||||
styleRule.Text = ".reading-section " + styleRule.Text;
|
||||
styleRule.Text = $"{CssScopeClass} " + styleRule.Text;
|
||||
}
|
||||
return RemoveWhiteSpaceFromStylesheets(stylesheet.ToCss());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue