Skip to content

Commit

Permalink
New: Setting to show full path and improved go back
Browse files Browse the repository at this point in the history
  • Loading branch information
ollm committed Jun 22, 2022
1 parent 143dbd9 commit 12907bc
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 25 deletions.
66 changes: 46 additions & 20 deletions scripts/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function loadFilesIndexPage(animation, path, keepScroll, mainPath)

var currentPath = false, currentPathScrollTop = [];

function loadIndexPage(animation = true, path = false, content = false, keepScroll = false, mainPath = false)
function loadIndexPage(animation = true, path = false, content = false, keepScroll = false, mainPath = false, fromGoBack = false)
{
onReading = false;

Expand Down Expand Up @@ -407,7 +407,7 @@ function loadIndexPage(animation = true, path = false, content = false, keepScro
var images = getFolderThumbnailsAsync(comics[key].path);

comics[key].images = images;
comics[key].mainPath = comics[key].path;
comics[key].mainPath = config.showFullPathLibrary ? p.parse(comics[key].path).root : comics[key].path;
}

comics.sort(function (a, b) {
Expand Down Expand Up @@ -438,7 +438,8 @@ function loadIndexPage(animation = true, path = false, content = false, keepScro
}
else
{
indexPathControl(path, mainPath);
if(!fromGoBack)
indexPathControl(path, mainPath);

handlebarsContext.comicsIndex = false;
handlebarsContext.comicsIndexVar = 'false';
Expand Down Expand Up @@ -530,9 +531,17 @@ function compressedError(error)
});
}

function addSepToEnd(path)
{
if(!new RegExp(pregQuote(p.sep)+'\s*$').test(path))
path = path + p.sep;

return path;
}

function returnTextPath(path, mainPath, image = false)
{
var mainPathR = p.dirname(mainPath) + p.sep;
mainPathR = addSepToEnd(p.dirname(mainPath));

var files = path.replace(new RegExp('^\s*'+pregQuote(mainPathR)), '').split(p.sep);

Expand All @@ -548,7 +557,7 @@ function returnTextPath(path, mainPath, image = false)

function headerPath(path, mainPath)
{
var mainPathR = p.dirname(mainPath) + p.sep;
mainPathR = addSepToEnd(p.dirname(mainPath));

var files = path.replace(new RegExp('^\s*'+pregQuote(mainPathR)), '').split(p.sep);

Expand Down Expand Up @@ -1035,13 +1044,33 @@ function indexPathControlGoBack()
}
else if(indexPathControlA.length > 0)
{
loadIndexPage(true, indexPathControlA[indexPathControlA.length - 2].path, false, false, indexPathControlA[indexPathControlA.length - 2].mainPath);
let goBack = indexPathControlA[indexPathControlA.length - 2];

if(goBack.isComic)
openComic(true, goBack.path, goBack.mainPath, false, true);
else
loadIndexPage(true, goBack.path, false, false, goBack.mainPath, true);


indexPathControlA.pop();
}
}

function indexPathControlUpdateLastComic(path = false)
{
let index = indexPathControlA.length - 1;
let last = indexPathControlA[index];

if(last.isComic && p.normalize(p.dirname(last.path)) === p.normalize(p.dirname(path)))
{
indexPathControlA[index].file = p.basename(path);
indexPathControlA[index].path = path;
}
}

var barBackStatus = false;

function indexPathControl(path = false, mainPath = false)
function indexPathControl(path = false, mainPath = false, isComic = false)
{
if(path === false || mainPath === false)
{
Expand All @@ -1052,20 +1081,14 @@ function indexPathControl(path = false, mainPath = false)
indexPathA = path;
indexMainPathA = mainPath;

var mainPathR = p.dirname(mainPath) + p.sep;
mainPathR = addSepToEnd(p.dirname(mainPath));

var files = path.replace(new RegExp('^\s*'+pregQuote(mainPathR)), '').split(p.sep);

var prev = '';
let index = files.length - 1;

indexPathControlA = [];

for(let index in files)
{
indexPathControlA.push({file: files[index], path: p.join(mainPathR, prev, files[index]), mainPath: mainPath});

prev = p.join(prev, files[index]);
}
if(index >= 0)
indexPathControlA.push({file: files[index], path: path, mainPath: mainPath, isComic: isComic});
}

if(indexPathControlA.length > 0)
Expand Down Expand Up @@ -1424,7 +1447,7 @@ function removeComic(path, confirm = false)

var readingActive = false, skipNextComic = false, skipPreviousComic = false;

function openComic(animation = true, path = true, mainPath = true, end = false)
function openComic(animation = true, path = true, mainPath = true, end = false, fromGoBack = false)
{
currentPathScrollTop[currentPath === false ? 0 : currentPath] = template.contentRight().children().scrollTop();
currentPath = path;
Expand All @@ -1451,7 +1474,8 @@ function openComic(animation = true, path = true, mainPath = true, end = false)
if(checkError(skipPreviousComic))
skipPreviousComic = false;

indexPathControl(imagePath, mainPath);
if(!fromGoBack)
indexPathControl(imagePath, mainPath, true);

readingActive = true;

Expand Down Expand Up @@ -1602,7 +1626,7 @@ module.exports = {
changeView: changeView,
changeSort: changeSort,
indexPathControl: indexPathControl,
indexPathControlA: indexPathControlA,
indexPathControlA: function(){return indexPathControlA},
indexPathControlGoBack: indexPathControlGoBack,
folderImages: folderImages,
folderImagesWD: folderImagesWD,
Expand All @@ -1620,5 +1644,7 @@ module.exports = {
justifyViewModule: justifyViewModule,
compressedError: compressedError,
addImageToDom: addImageToDom,
addSepToEnd: addSepToEnd,
indexPathControlUpdateLastComic: indexPathControlUpdateLastComic,
indexMainPathA: function(){return indexMainPathA},
};
2 changes: 2 additions & 0 deletions scripts/opencomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,8 @@ function openComic(filePath, animation = true)
if(mainPath === false)
mainPath = path;

mainPath = config.showFullPathOpened ? p.parse(mainPath).root : mainPath;

if(onReading)
reading.saveReadingProgress();

Expand Down
3 changes: 3 additions & 0 deletions scripts/reading.js
Original file line number Diff line number Diff line change
Expand Up @@ -2031,13 +2031,16 @@ function saveReadingProgress(path = false)
break;
}
}

storage.updateVar('readingProgress', dom.indexMainPathA(), {
index: imagesPath[path],
path: path,
lastReading: +new Date(),
progress: 0,
});

dom.indexPathControlUpdateLastComic(path);

if(comic && path)
{
comic.readingProgress.path = imagesPath[path];
Expand Down
12 changes: 12 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ function setGlobalZoom(value)
storage.updateVar('config', 'readingGlobalZoom', value);
}

function setShowFullPathLibrary(value)
{
storage.updateVar('config', 'showFullPathLibrary', value);
}

function setShowFullPathOpened(value)
{
storage.updateVar('config', 'showFullPathOpened', value);
}

module.exports = {
start: start,
setMaxMargin: setMaxMargin,
setGlobalZoom: setGlobalZoom,
setShowFullPathLibrary: setShowFullPathLibrary,
setShowFullPathOpened: setShowFullPathOpened,
};
4 changes: 3 additions & 1 deletion scripts/storage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var changes = 39; // Update this if readingPagesConfig is updated
var changes = 40; // Update this if readingPagesConfig is updated

var readingPagesConfig = {
readingConfigName: '',
Expand Down Expand Up @@ -49,6 +49,8 @@ var storageDefault = {
sort: 'name-numeric',
sortInvertIndex: false,
sortInvert: false,
showFullPathLibrary: false,
showFullPathOpened: false,
...readingPagesConfig,
readingMagnifyingGlass: false,
readingMagnifyingGlassZoom: 2,
Expand Down
10 changes: 6 additions & 4 deletions templates/settings.content.right.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ <h2>{{language.settings.reading.main}}</h2>

<h2>{{language.settings.navigation.main}}</h2>

<div class="simple-slider">
<div class="simple-text-text">{{language.settings.navigation.showFullPathLibrary}}</div>
<div class="menu-simple-text">
{{language.settings.navigation.showFullPathLibrary}}
<div class="switch{{#if config.showFullPathLibrary}} a{{/if}}" on="settings.setShowFullPathLibrary(true)" off="settings.setShowFullPathLibrary(false)"></div>
</div>

<div class="simple-slider">
<div class="simple-text-text">{{language.settings.navigation.showFullPathOpened}}</div>
<div class="menu-simple-text">
{{language.settings.navigation.showFullPathOpened}}
<div class="switch{{#if config.showFullPathOpened}} a{{/if}}" on="settings.setShowFullPathOpened(true)" off="settings.setShowFullPathOpened(false)"></div>
</div>

</div>

0 comments on commit 12907bc

Please sign in to comment.