Skip to content

Commit

Permalink
New: Shortcut to go next/prev chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
ollm committed Mar 31, 2024
1 parent b95de2c commit 20258ff
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

##### 🚀 New Features

- Shortcut to go next/prev chapter

##### 🐛 Bug Fixes

- Scroll does not work correctly when zooming and then resizing the window [`65a447c`](https://github.com/ollm/OpenComic/commit/65a447c1ce395214b1f787e5eb0824f003655f11)
Expand Down
42 changes: 40 additions & 2 deletions scripts/reading.js
Original file line number Diff line number Diff line change
Expand Up @@ -1339,17 +1339,35 @@ function goStart(force = false)
if((currentIndex > indexNum || (currentIndex - 1 == 0 && dom.previousComic())) && (!maxPageVisibility || currentPageVisibility == 0))
{
goPrevious();

return false;
}
else
{
readingDirection = true;

goToIndex(1, true);

return true;
}
}
else
{
goEnd(true);
return goEnd(true);
}
}

function goPrevComic()
{
if(dom.previousComic())
{
let speed = _config.readingViewSpeed;
_config.readingViewSpeed = 0;

let double = goStart();
if(double) goStart();

_config.readingViewSpeed = speed;
}
}

Expand All @@ -1363,17 +1381,35 @@ function goEnd(force = false)
if((currentIndex < 1 || (currentIndex == indexNum && dom.nextComic())) && (!maxPageVisibility || maxPageVisibility == currentPageVisibility))
{
goNext();

return false;
}
else
{
readingDirection = false;

goToIndex(indexNum, true, true, true);

return true;
}
}
else
{
goStart(true);
return goStart(true);
}
}

function goNextComic()
{
if(dom.nextComic())
{
let speed = _config.readingViewSpeed;
_config.readingViewSpeed = 0;

let double = goEnd();
if(double) goEnd();

_config.readingViewSpeed = speed;
}
}

Expand Down Expand Up @@ -5139,8 +5175,10 @@ module.exports = {
goStart: goStart,
goPrevious: goPrevious,
goPrev: goPrevious,
goPrevComic: goPrevComic,
goNext: goNext,
goEnd: goEnd,
goNextComic: goNextComic,
pageRange: pageRange,
goBackPageRangeHistory: goBackPageRangeHistory,
goPageDialog: goPageDialog,
Expand Down
52 changes: 49 additions & 3 deletions scripts/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ function loadShortcuts()
'next',
'start',
'end',
'prevComic',
'nextComic',
'magnifyingGlass',
'hideBarHeader',
'hideContentLeft',
Expand Down Expand Up @@ -145,11 +147,11 @@ function loadShortcuts()
},
start: {
name: language.reading.firstPage,
function: function(){
function: function(event){

if(inputIsFocused()) return false;

if(!reading.readingViewIs('scroll') || event.key !== 'ArrowUp')
if(!reading.readingViewIs('scroll') || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') || event.ctrlKey || event.altKey || event.shiftKey || event.metaKey)
{
reading.goStart();
return true;
Expand All @@ -169,7 +171,7 @@ function loadShortcuts()

if(inputIsFocused()) return false;

if(!reading.readingViewIs('scroll') || event.key !== 'ArrowDown')
if(!reading.readingViewIs('scroll') || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') || event.ctrlKey || event.altKey || event.shiftKey || event.metaKey)
{
reading.goEnd();
return true;
Expand All @@ -183,6 +185,46 @@ function loadShortcuts()
return false;
},
},
prevComic: {
name: language.reading.prevChapter,
function: function(event){

if(inputIsFocused()) return false;

if(!reading.readingViewIs('scroll') || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') || event.ctrlKey || event.altKey || event.shiftKey || event.metaKey)
{
reading.goPrevComic();
return true;
}
else if(!reading.zoomingIn())
{
reading.disableOnScroll(false);
if(reading.scrollNextOrPrevComic(true)) return true;
}

return false;
},
},
nextComic: {
name: language.reading.nextChapter,
function: function(event){

if(inputIsFocused()) return false;

if(!reading.readingViewIs('scroll') || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') || event.ctrlKey || event.altKey || event.shiftKey || event.metaKey)
{
reading.goNextComic();
return true;
}
else if(!reading.zoomingIn())
{
reading.disableOnScroll(false);
if(reading.scrollNextOrPrevComic(false)) return true;
}

return false;
},
},
magnifyingGlass: {
name: language.reading.magnifyingGlass.main,
function: function(event, gamepad = false){
Expand Down Expand Up @@ -283,6 +325,10 @@ function loadShortcuts()
'Down': 'end',
'S': 'end',
'End': 'end',
'Ctrl+Up': 'prevComic',
'Ctrl+Left': 'prevComic',
'Ctrl+Down': 'nextComic',
'Ctrl+Right': 'nextComic',
'M': 'magnifyingGlass',
'B': 'hideBarHeader',
'H': 'hideBarHeader',
Expand Down

0 comments on commit 20258ff

Please sign in to comment.