<commit_before>console.log( "=== simpread read load ===" )

import pangu       from 'pangu';
import ProgressBar from 'readschedule';
import Footer      from 'readfooter';

import { ReadCtlbar, ReadCtlAdapter } from 'readctlbar';
import { storage, Clone } from 'storage';
import * as util          from 'util';

const rdcls   = "ks-simpread-read",
      bgtmpl  = `<div class="${rdcls}"></div>`,
      rdclsjq = "." + rdcls,
      $root   = $( "html" ),
      theme   = `sr-rd-theme-bg`;

class Read extends React.Component {

    componentWillMount() {
        $( "body" ).addClass( "ks-simpread-body-hide" );
    }

    async componentDidMount() {
        await excludes( $("sr-rd-content"), this.props.wrapper.exclude );
        await specbeautify( $( "sr-rd-content" ));
        await commbeautify( $( "sr-rd-content" ));
        $root.addClass( theme ).find( rdclsjq ).addClass( theme );
        pangu.spacingElementByClassName( rdcls );
    }

    componentWillUnmount() {
        $root.removeClass( theme );
        $( "body" ).removeClass( "ks-simpread-body-hide" );
        $( rdclsjq ).addClass( "ks-simpread-read-hide" );
        $( rdclsjq ).one( "animationend", () => {
            $( rdclsjq ).remove();
        });
    }

    constructor( props ) {
        super( props );
        switch ( this.props.read.theme ) {
            case "theme1":
               require( "theme1" );
               break;
            case "theme2":
               require( "theme2" );
               break;
        }
    }

   // exit read mode
   exit() {
        ReactDOM.unmountComponentAtNode( getReadRoot() );
    }

    render() {
        return(
            <sr-read class="sr-rd-font">
                <ProgressBar />
                <sr-rd-title>{ this.props.wrapper.title }</sr-rd-title>
                <sr-rd-desc>{ this.props.wrapper.desc }</sr-rd-desc>
                <sr-rd-content dangerouslySetInnerHTML={{__html: this.props.wrapper.include }} ></sr-rd-content>
                <Footer />
                <ReadCtlbar exit={ ()=> this.exit() } />
            </sr-read>
        )
    }

}

/**
 * Render entry
 * 
 */
function Render() {
    ReactDOM.render( <Read read={ storage.current } wrapper={ wrap(storage.current.site) } />, getReadRoot() );
}

/**
 * Get read root
 * 
 * @return {jquery} read root jquery object
 */
function getReadRoot() {
    if ( $root.find( rdclsjq ).length == 0 ) {
        $root.append( bgtmpl );
    }
    return $( rdclsjq )[0];
}

/**
 * Verify ks-simpread-read tag exit
 * 
 * @return {boolean}
 */
function Exist( action = true ) {
    if ( $root.find( rdclsjq ).length > 0 ) {
        if (action) ReadCtlAdapter( "setting" );
        return true;
    } else {
        return false;
    }
}

/**
 * Wrap storage.current.site object
 * 
 * @param  {object} storage.current.site object
 * @return {object} wrapper object
 */
function wrap( site ) {
    const wrapper   = Clone( site ),
          title     = util.selector( site.title   ),
          desc      = util.selector( site.desc    ),
          include   = util.selector( site.include );
    wrapper.title   = query( title );
    wrapper.desc    = query( desc  );
    wrapper.include = query( include, "html" );
    return wrapper;
}

/**
 * Query content usage jquery
 * 
 * @param  {string} query content
 * @param  {string} type, incldue: text and html
 * @return {string} query result
 */
function query( content, type = "text" ) {
    if ( util.specTest( content ) ) {
        content = util.specAction( content )[0];
    } else if ( type == "html" ) {
        content = rules($root.find( content ).html().trim());
    } else {
        content = $root.find( content ).text().trim();
    }
    return content;
}

/**
 * Set exclude style
 * 
 * @param {jquery} jquery object
 * @param {array}  hidden html
 */
async function excludes( $target, exclude ) {
    const tags = util.exclude( $target, exclude );
    $target.find( tags ).remove();
}

/**
 * Special beautify html with other webiste
 * 
 * @param {jquery}
 */
async function specbeautify( $target ) {
    switch ( storage.current.site.name ) {
        case "sspai.com":
            $target.find( ".relation-apps" ).map( (index, item) => {
                // TO-DO
                $(item).remove();
            });
            break;
        case "smzdm.com":
            $target.find( "img.face, .insert-outer" ).map( (index, item) => {
                if ( $(item).is("img") ) {
                    $(item).addClass( "sr-rd-content-nobeautify" );
                } else {
                    $(item).find( "img" ).addClass( "sr-rd-content-nobeautify" );
                }
            });
            break;
        case "infoq.com":
            $target.find( "img" ).map( (index, item) => {
                if ( $(item).css("float") == "left" ) {
                    $(item).addClass( "sr-rd-content-nobeautify" );
                }
            });
            break;
        case "douban.com":
            $target.find( ".review-content" ).children().unwrap();
            $target.find( "table" ).addClass( "sr-rd-content-center" );
            break;<commit_msg>Add same comment.<commit_after>console.log( "=== simpread read load ===" )

import pangu       from 'pangu';
import ProgressBar from 'readschedule';
import Footer      from 'readfooter';

import { ReadCtlbar, ReadCtlAdapter } from 'readctlbar';
import { storage, Clone } from 'storage';
import * as util          from 'util';

const rdcls   = "ks-simpread-read",
      bgtmpl  = `<div class="${rdcls}"></div>`,
      rdclsjq = "." + rdcls,
      $root   = $( "html" ),
      theme   = `sr-rd-theme-bg`;

class Read extends React.Component {

    componentWillMount() {
        $( "body" ).addClass( "ks-simpread-body-hide" );
    }

    async componentDidMount() {
        await excludes( $("sr-rd-content"), this.props.wrapper.exclude );
        await specbeautify( $( "sr-rd-content" ));
        await commbeautify( $( "sr-rd-content" ));
        $root.addClass( theme ).find( rdclsjq ).addClass( theme );
        pangu.spacingElementByClassName( rdcls );
    }

    componentWillUnmount() {
        $root.removeClass( theme );
        $( "body" ).removeClass( "ks-simpread-body-hide" );
        $( rdclsjq ).addClass( "ks-simpread-read-hide" );
        $( rdclsjq ).one( "animationend", () => {
            $( rdclsjq ).remove();
        });
    }

    constructor( props ) {
        super( props );
        switch ( this.props.read.theme ) {
            case "theme1":
               require( "theme1" );
               break;
            case "theme2":
               require( "theme2" );
               break;
        }
    }

   // exit read mode
   exit() {
        ReactDOM.unmountComponentAtNode( getReadRoot() );
    }

    render() {
        return(
            <sr-read class="sr-rd-font">
                <ProgressBar />
                <sr-rd-title>{ this.props.wrapper.title }</sr-rd-title>
                <sr-rd-desc>{ this.props.wrapper.desc }</sr-rd-desc>
                <sr-rd-content dangerouslySetInnerHTML={{__html: this.props.wrapper.include }} ></sr-rd-content>
                <Footer />
                <ReadCtlbar exit={ ()=> this.exit() } />
            </sr-read>
        )
    }

}

/**
 * Render entry
 * 
 */
function Render() {
    ReactDOM.render( <Read read={ storage.current } wrapper={ wrap(storage.current.site) } />, getReadRoot() );
}

/**
 * Get read root
 * 
 * @return {jquery} read root jquery object
 */
function getReadRoot() {
    if ( $root.find( rdclsjq ).length == 0 ) {
        $root.append( bgtmpl );
    }
    return $( rdclsjq )[0];
}

/**
 * Verify ks-simpread-read tag exit
 * 
 * @return {boolean}
 */
function Exist( action = true ) {
    if ( $root.find( rdclsjq ).length > 0 ) {
        if (action) ReadCtlAdapter( "setting" );
        return true;
    } else {
        return false;
    }
}

/**
 * Wrap storage.current.site object
 * 
 * @param  {object} storage.current.site object
 * @return {object} wrapper object
 */
function wrap( site ) {
    const wrapper   = Clone( site ),
          title     = util.selector( site.title   ),
          desc      = util.selector( site.desc    ),
          include   = util.selector( site.include );
    wrapper.title   = query( title );
    wrapper.desc    = query( desc  );
    wrapper.include = query( include, "html" );
    return wrapper;
}

/**
 * Query content usage jquery
 * 
 * @param  {string} query content
 * @param  {string} type, incldue: text and html
 * @return {string} query result
 */
function query( content, type = "text" ) {
    if ( util.specTest( content ) ) {
        content = util.specAction( content )[0];
    } else if ( type == "html" ) {
        content = rules($root.find( content ).html().trim());
    } else {
        content = $root.find( content ).text().trim();
    }
    return content;
}

/**
 * Set exclude style
 * 
 * @param {jquery} jquery object
 * @param {array}  hidden html
 */
async function excludes( $target, exclude ) {
    const tags = util.exclude( $target, exclude );
    $target.find( tags ).remove();
}

/**
 * Special beautify html with other webiste, incldue:
 * - sspai.com, mzdm.com, infoq.com, douban.com, qdaily.com, huxiu.com
 * 
 * @param {jquery}
 */
async function specbeautify( $target ) {
    switch ( storage.current.site.name ) {
        case "sspai.com":
            $target.find( ".relation-apps" ).map( (index, item) => {
                // TO-DO
                $(item).remove();
            });
            break;
        case "smzdm.com":
            $target.find( "img.face, .insert-outer" ).map( (index, item) => {
                if ( $(item).is("img") ) {
                    $(item).addClass( "sr-rd-content-nobeautify" );
                } else {
                    $(item).find( "img" ).addClass( "sr-rd-content-nobeautify" );
                }
            });
            break;
        case "infoq.com":
            $target.find( "img" ).map( (index, item) => {
                if ( $(item).css("float") == "left" ) {
                    $(item).addClass( "sr-rd-content-nobeautify" );
                }
            });
            break;
        case "douban.com":
            $target.find( ".review-content" ).children().unwrap();
            $target.find( "table" ).addClass( "sr-rd-content-center" );
            break;
{'fraction_non_alphanumeric': 0.16330080200985603, 'fraction_numerical': 0.0015460430959512996, 'mean_word_length': 1.8838116466982446, 'pattern_counts': {'":': 12, '<': 31, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '185755', 'n_tokens_mistral': 3284, 'n_tokens_neox': 3183, 'n_words': 722}