Skip to content

Commit 9a86a30

Browse files
committed
New: Scroll by screen percentage in webtoon mode
1 parent e25b2d5 commit 9a86a30

2 files changed

Lines changed: 59 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1313
- Option to save bookmarked images [`7def9ec`](https://github.com/ollm/OpenComic/commit/7def9eca58ceb24fb3444a3daf3ed81178a13fd1)
1414
- Improved opening behavior options for files and folders [`07ee1f5`](https://github.com/ollm/OpenComic/commit/07ee1f5007576016a709e45d4649319129f75911)
1515
- Make the Ignore single folders option work for images too [`cc9f9c7`](https://github.com/ollm/OpenComic/commit/cc9f9c727ec11b1a12fd4c8dac90506f7e01b378)
16+
- Scroll by screen percentage in webtoon mode
1617

1718
##### 🐛 Bug Fixes
1819

‎scripts/reading.js‎

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,46 @@ function calculateRealReadingDirection(index)
11361136
realReadingDirection = true;
11371137
}
11381138

1139+
goScrollPercentST = false;
1140+
1141+
function goScrollPercent(screenPercent = 50, animation = true)
1142+
{
1143+
if(_config.readingWebtoon || readingViewIs('scroll'))
1144+
{
1145+
let animationDurationMS = (animation ? _config.readingViewSpeed : 0) * 1000;
1146+
1147+
const content = template._contentRight().firstElementChild;
1148+
const rect = content.getBoundingClientRect();
1149+
1150+
const now = Date.now();
1151+
const prevNow = +content.dataset.now;
1152+
1153+
if(now - prevNow < animationDurationMS)
1154+
animationDurationMS = (now - prevNow);
1155+
1156+
const scrollHeight = content.scrollHeight - rect.height;
1157+
let scrollTop = (+content.dataset.scrollTop || content.scrollTop) + (screenPercent / 100 * rect.height);
1158+
1159+
if(scrollTop < 0)
1160+
scrollTop = 0;
1161+
else if(scrollTop > scrollHeight)
1162+
scrollTop = scrollHeight;
1163+
1164+
content.dataset.scrollTop = scrollTop;
1165+
content.dataset.now = now;
1166+
1167+
clearTimeout(goScrollPercentST);
1168+
goScrollPercentST = setTimeout(function(){
1169+
1170+
content.dataset.scrollTop = '';
1171+
content.dataset.now = '';
1172+
1173+
}, animationDurationMS);
1174+
1175+
$(content).stop(true).animate({scrollTop: scrollTop+'px'}, animationDurationMS);
1176+
}
1177+
}
1178+
11391179
//Go to a specific comic index
11401180
function goToIndex(index, animation = true, nextPrevious = false, end = false)
11411181
{
@@ -1380,8 +1420,15 @@ function goNext()
13801420
}
13811421
else if(nextIndex <= indexNum || ((readingViewIs('scroll') && (_config.readingViewAdjustToWidth || _config.readingWebtoon)) && currentPageVisibility < maxPageVisibility))
13821422
{
1383-
goToIndex(nextIndex, true, true);
1384-
music.soundEffect.page();
1423+
if(_config.readingWebtoon)
1424+
{
1425+
goScrollPercent(70, true);
1426+
}
1427+
else
1428+
{
1429+
goToIndex(nextIndex, true, true);
1430+
music.soundEffect.page();
1431+
}
13851432
}
13861433
else if(currentIndex == indexNum && dom.nextComic() && (!_config.readingManga || readingViewIs('scroll')))
13871434
{
@@ -1408,8 +1455,15 @@ function goPrevious()
14081455
}
14091456
else if(previousIndex > 0 || ((readingViewIs('scroll') && (_config.readingViewAdjustToWidth || _config.readingWebtoon)) && currentPageVisibility > 0))
14101457
{
1411-
goToIndex(previousIndex, true, true);
1412-
music.soundEffect.page();
1458+
if(_config.readingWebtoon)
1459+
{
1460+
goScrollPercent(-70, true);
1461+
}
1462+
else
1463+
{
1464+
goToIndex(previousIndex, true, true);
1465+
music.soundEffect.page();
1466+
}
14131467
}
14141468
else if(previousIndex == 0 && dom.previousComic() && (!_config.readingManga || readingViewIs('scroll')))
14151469
{

0 commit comments

Comments
 (0)