<commit_before><link rel="import" href="../connector.html">

<script>

    /**
     * 
     */
    class WordPressMadara extends Connector {

        /**
         *
         */
        constructor() {
            super();
            // Public members for usage in UI (mandatory)
            super.id         = undefined;
            super.label      = undefined;
            super.isLocked   = false;
            this.initialized = undefined;
            // Private members for internal usage only (convenience)
            this.url         = undefined;
            // Private members for internal use that can be configured by the user through settings menu (set to undefined or false to hide from settings menu!)
            this.config = undefined;

            this.formManga = new URLSearchParams();
            this.formManga.append( 'action', 'madara_load_more' );
            this.formManga.append( 'page', '0' );
            this.formManga.append( 'template', 'madara-core/content/content-archive' );
            this.formManga.append( 'vars[post_type]', 'wp-manga' );
            this.formManga.append( 'vars[posts_per_page]', '512' );
            this.formManga = this.formManga.toString();
        }

        /**
         *
         */
        _getMangaList( callback ) {
            this.requestOptions.method = 'POST';
            this.requestOptions.body = this.formManga;
            this.requestOptions.headers.set( 'content-type', 'application/x-www-form-urlencoded' );
            this.fetchDOM( this.url + '/wp-admin/admin-ajax.php', 'div.post-title h5 a' )
            .then( data => {
                let mangaList = data.map( element => {
                    return {
                        id: this.getRelativeLink( element ),
                        title: element.text.trim()
                    };
                } );
                callback( null, mangaList );
            } )
            .catch( error => {
                console.error( error, this );
                callback( error, undefined );
            } );
            this.requestOptions.headers.delete( 'content-type' );
            delete this.requestOptions.body;
            this.requestOptions.method = 'GET';
        }

        /**
         *
         */
        _getChapterList( manga, callback ) {
            this.fetchDOM( this.url + manga.id, 'ul.main li a' )
            .then( data => {
                let chapterList = data.map( element => {
                    return {
                        id: this.getRelativeLink( element ),
                        title: element.text.trim(),
                        language: ''
                    };
                } );
                callback( null, chapterList );
            } )
            .catch( error => {
                console.error( error, manga );
                callback( error, undefined );
            } );
        }

        /**
         *
         */
        _getPageList( manga, chapter, callback ) {
            let uri = new URL( this.url + chapter.id );
            uri.searchParams.set( 'style', 'list' );
            this.fetchDOM( uri.href, 'div.page-break source' )
            .then( data => {
                let pageLinks = data.map( element => element.src );
                callback( null, pageLinks );
            } )
            .catch( error => {
                console.error( error, chapter );
                callback( error, undefined );<commit_msg>[wp-madara] fixed chapter grouping by nested lists<commit_after><link rel="import" href="../connector.html">

<script>

    /**
     * 
     */
    class WordPressMadara extends Connector {

        /**
         *
         */
        constructor() {
            super();
            // Public members for usage in UI (mandatory)
            super.id         = undefined;
            super.label      = undefined;
            super.isLocked   = false;
            this.initialized = undefined;
            // Private members for internal usage only (convenience)
            this.url         = undefined;
            // Private members for internal use that can be configured by the user through settings menu (set to undefined or false to hide from settings menu!)
            this.config = undefined;

            this.formManga = new URLSearchParams();
            this.formManga.append( 'action', 'madara_load_more' );
            this.formManga.append( 'page', '0' );
            this.formManga.append( 'template', 'madara-core/content/content-archive' );
            this.formManga.append( 'vars[post_type]', 'wp-manga' );
            this.formManga.append( 'vars[posts_per_page]', '512' );
            this.formManga = this.formManga.toString();
        }

        /**
         *
         */
        _getMangaList( callback ) {
            this.requestOptions.method = 'POST';
            this.requestOptions.body = this.formManga;
            this.requestOptions.headers.set( 'content-type', 'application/x-www-form-urlencoded' );
            this.fetchDOM( this.url + '/wp-admin/admin-ajax.php', 'div.post-title h5 a' )
            .then( data => {
                let mangaList = data.map( element => {
                    return {
                        id: this.getRelativeLink( element ),
                        title: element.text.trim()
                    };
                } );
                callback( null, mangaList );
            } )
            .catch( error => {
                console.error( error, this );
                callback( error, undefined );
            } );
            this.requestOptions.headers.delete( 'content-type' );
            delete this.requestOptions.body;
            this.requestOptions.method = 'GET';
        }

        /**
         *
         */
        _getChapterList( manga, callback ) {
            this.fetchDOM( this.url + manga.id, 'ul.main li.wp-manga-chapter a' )
            .then( data => {
                let chapterList = data.map( element => {
                    return {
                        id: this.getRelativeLink( element ),
                        title: element.text.trim(),
                        language: ''
                    };
                } );
                callback( null, chapterList );
            } )
            .catch( error => {
                console.error( error, manga );
                callback( error, undefined );
            } );
        }

        /**
         *
         */
        _getPageList( manga, chapter, callback ) {
            let uri = new URL( this.url + chapter.id );
            uri.searchParams.set( 'style', 'list' );
            this.fetchDOM( uri.href, 'div.page-break source' )
            .then( data => {
                let pageLinks = data.map( element => element.src );
                callback( null, pageLinks );
            } )
            .catch( error => {
                console.error( error, chapter );
                callback( error, undefined );
{'fraction_non_alphanumeric': 0.1179354094579008, 'fraction_numerical': 0.0014417531718569781, 'mean_word_length': 1.294740324181277, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '976212', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1725, 'n_words': 392}