MCPcopy
hub / github.com/ollm/OpenComic / generateEbookPages

Function generateEbookPages

scripts/reading.js:4503–4628  ·  view source on GitHub ↗
(end = false, reset = false, fast = false, imagePath = false, first = false)

Source from the content-addressed store, hash-verified

4501var hasGenerateEbookPages = false;
4502
4503async function generateEbookPages(end = false, reset = false, fast = false, imagePath = false, first = false)
4504{
4505 // Avoid running multiple times at the same time
4506 if(hasGenerateEbookPages)
4507 {
4508 hasGenerateEbookPages = 1;
4509
4510 return;
4511 }
4512 else if(!nextOpenChapterProgress && imagesDistribution && imagesDistribution[0] && !imagePath)
4513 {
4514 const _doublePage = imagesDistribution[0].length > 1 ? true : false;
4515
4516 let index = currentIndex;
4517
4518 if(_doublePage && !doublePage.active())
4519 index = Math.ceil(index / 2);
4520
4521 let imageIndex = imagesDistribution[index - 1][0].index;
4522 let page = _ebook.pages[imageIndex - 1];
4523
4524 let chapterIndex = page.chapterIndex;
4525 let chapterProgress = page.chapterProgress;
4526
4527 setNextOpenChapterProgress(chapterIndex, chapterProgress);
4528 }
4529
4530 hasGenerateEbookPages = true;
4531
4532 let ebookConfig = await getEbookConfig();
4533 let ebookPages = await readingFileC.ebookPages(ebookConfig);
4534
4535 if(hasGenerateEbookPages === 1) // Priorize last generateEbookPages request
4536 {
4537 hasGenerateEbookPages = false;
4538 generateEbookPages(end, reset, fast);
4539 }
4540 else if(!generateEbookPagesCancel && onReading)
4541 {
4542 images = {}, imagesData = {}, imagesDataClip = {}, imagesPath = {}, imagesNum = 0, contentNum = 0, pageRangeHistory = [];
4543
4544 let comics = [];
4545
4546 for(let i = 0, len = ebookPages.pages.length; i < len; i++)
4547 {
4548 let page = ebookPages.pages[i];
4549 let index = i + 1;
4550 let path = page.path+'?page='+i;
4551
4552 images[index] = {index: index, path: path};
4553 imagesPath[path] = index;
4554
4555 imagesData[index] = {width: ebookConfig.width, height: ebookConfig.height, aspectRatio: (ebookConfig.width / ebookConfig.height), name: page.name};
4556
4557 comics.push({
4558 index: i + 1,
4559 sha: sha1(path),
4560 name: ''.replace(/\.[^\.]*$/, ''),

Callers 2

readFunction · 0.85

Calls 13

getEbookConfigFunction · 0.85
sha1Function · 0.85
setCurrentComicsFunction · 0.85
addHtmlImagesFunction · 0.85
disposeImagesFunction · 0.85
calculateViewFunction · 0.85
readingMangaFunction · 0.85
goToChapterProgressFunction · 0.85
readingViewIsFunction · 0.85
getPreviusContentSizeFunction · 0.85
resetMethod · 0.80

Tested by

no test coverage detected