<commit_before><script>

    /**
     *
     */
    class Chapter {

        /**
         *
         */
        constructor( manga, id, title, language ) {
            this.manga = manga;
            this.id = id;
            this.title = title;
            this.language = language;
            this.status = undefined;
            this.pageProcess = false;
            this.pageCache = undefined;
            this.updateStatus();
        }

        /**
         *
         */
        setStatus( status ) {
            if( this.status !== status ) {
                this.status = status;
                document.dispatchEvent( new CustomEvent( EventListener.onChapterStatusChanged, { detail: this } ) );
            }
        }

        /**
         * 
         */
        updateStatus() {
            // do not overwrite download status ...
            if( !this.status || this.status === DownloadStatus.available || this.status === DownloadStatus.completed ) {
                // look in the manga's list of existing chapters (found in directory), if this chapter already exist
                if( !this.manga || !this.manga.existingChapters ) {
                    return;
                }
                let sanatizedTitle = Engine.Storage.sanatizePath ( this.title );
                if( Engine.Settings.chapterFormat.value === ChapterFormat.cbz ) {
                    sanatizedTitle += ChapterFormat.cbz;
                }
                if( Engine.Settings.chapterFormat.value === ChapterFormat.pdf ) {
                    sanatizedTitle += ChapterFormat.pdf;
                }
                if( Engine.Settings.chapterFormat.value === ChapterFormat.epub ) {
                    sanatizedTitle += ChapterFormat.epub;
                }
                if( this.manga.existingChapters[sanatizedTitle] ) {
                    this.setStatus( DownloadStatus.completed );
                } else {
                    this.setStatus( DownloadStatus.available );
                }
            }
        }

        /**
         * Get all pages for the chapter.
         * Callback will be executed after completion and provided with an error (or null when no error occured)
         * and a reference to the page list (undefined on error).
         */
        getPages( callback ) {
            if( this.status === DownloadStatus.completed ) {
                Engine.Storage.loadChapterPages( this, callback );
            } else {
            // check if page list is cached
                if( this.pageCache && this.pageCache.length > 0 ) {
                    callback( null, this.pageCache );
                    return;
                }
                // get page list directly from the connector interface and cache them
                this.manga.connector._getPageList( this.manga, this, ( error, pages ) => {
                    this.pageCache = pages;
                    callback( error, this.pageCache );
                });
            }
        }

    }
    Chapter; // reference the class to prevent removal of the class through js-minify

</script><commit_msg>fixed chapter to only update page cache when no error occurs<commit_after><script>

    /**
     *
     */
    class Chapter {

        /**
         *
         */
        constructor( manga, id, title, language ) {
            this.manga = manga;
            this.id = id;
            this.title = title;
            this.language = language;
            this.status = undefined;
            this.pageProcess = false;
            this.pageCache = undefined;
            this.updateStatus();
        }

        /**
         *
         */
        setStatus( status ) {
            if( this.status !== status ) {
                this.status = status;
                document.dispatchEvent( new CustomEvent( EventListener.onChapterStatusChanged, { detail: this } ) );
            }
        }

        /**
         * 
         */
        updateStatus() {
            // do not overwrite download status ...
            if( !this.status || this.status === DownloadStatus.available || this.status === DownloadStatus.completed ) {
                // look in the manga's list of existing chapters (found in directory), if this chapter already exist
                if( !this.manga || !this.manga.existingChapters ) {
                    return;
                }
                let sanatizedTitle = Engine.Storage.sanatizePath ( this.title );
                if( Engine.Settings.chapterFormat.value === ChapterFormat.cbz ) {
                    sanatizedTitle += ChapterFormat.cbz;
                }
                if( Engine.Settings.chapterFormat.value === ChapterFormat.pdf ) {
                    sanatizedTitle += ChapterFormat.pdf;
                }
                if( Engine.Settings.chapterFormat.value === ChapterFormat.epub ) {
                    sanatizedTitle += ChapterFormat.epub;
                }
                if( this.manga.existingChapters[sanatizedTitle] ) {
                    this.setStatus( DownloadStatus.completed );
                } else {
                    this.setStatus( DownloadStatus.available );
                }
            }
        }

        /**
         * Get all pages for the chapter.
         * Callback will be executed after completion and provided with an error (or null when no error occured)
         * and a reference to the page list (undefined on error).
         */
        getPages( callback ) {
            if( this.status === DownloadStatus.completed ) {
                Engine.Storage.loadChapterPages( this, callback );
            } else {
                // check if page list is cached
                if( this.pageCache && this.pageCache.length > 0 ) {
                    callback( null, this.pageCache );
                    return;
                }
                // get page list directly from the connector interface and cache them
                this.manga.connector._getPageList( this.manga, this, ( error, pages ) => {
                    if( !error ) {
                        this.pageCache = pages;
                    }
                    callback( error, this.pageCache );
                });
            }
        }

    }
    Chapter; // reference the class to prevent removal of the class through js-minify

</script>
{'fraction_non_alphanumeric': 0.09436664544875875, 'fraction_numerical': 0.00031826861871419476, 'mean_word_length': 1.2971491228070176, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4429016', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1438, 'n_words': 379}