Support » Plugin: Chinese Word Count » WP 4.3 totally changed the implementation of word-count.js

  • 4.3 totally change word-count.js. This plug-in is no longer compatible.

    Here is my fix to word-count.js

    ( function() {
    function WordCounter( settings ) {
    var key,
    shortcodes;

    if ( settings ) {
    for ( key in settings ) {
    if ( settings.hasOwnProperty( key ) ) {
    this.settings[ key ] = settings[ key ];
    }
    }
    }

    shortcodes = this.settings.l10n.shortcodes;

    if ( shortcodes && shortcodes.length ) {
    this.settings.shortcodesRegExp = new RegExp( ‘\\[\\/?(?:’ + shortcodes.join( ‘|’ ) + ‘)[^\\]]*?\\]’, ‘g’ );
    }
    }

    WordCounter.prototype.settings = {
    HTMLRegExp: /<\/?[a-z][^>]*?>/gi,
    HTMLcommentRegExp: /<!–[\s\S]*?–>/g,
    spaceRegExp: / | /gi,
    HTMLEntityRegExp: /&\S+?;/g,
    connectorRegExp: /–|\u2014/g,
    EastAsiaRegExp : /[\u3100-\u312F\u31A0-\u31BF\u4E00-\u9FCF\u3400-\u4DBF\uF900-\uFAFF\u2F00-\u2FDF\u2E80-\u2EFF\u31C0-\u31EF\u2FF0-\u2FFF\u1100-\u11FF\uA960-\uA97F\uD780-\uD7FF\u3130-\u318F\uFFA0-\uFFDC\uAC00-\uD7AF\u3040-\u309F\u30A0-\u30FF\u31F0-\u31FF\uFF65-\uFF9F\u3190-\u319F\uA4D0-\uA4FF\uA000-\uA48F\uA490-\uA4CF]/g,
    removeRegExp: new RegExp( [
    ‘[‘,
    // Basic Latin (extract)
    ‘\u0021-\u0040\u005B-\u0060\u007B-\u007E’,
    // Latin-1 Supplement (extract)
    ‘\u0080-\u00BF\u00D7\u00F7’,
    // General Punctuation
    // Superscripts and Subscripts
    // Currency Symbols
    // Combining Diacritical Marks for Symbols
    // Letterlike Symbols
    // Number Forms
    // Arrows
    // Mathematical Operators
    // Miscellaneous Technical
    // Control Pictures
    // Optical Character Recognition
    // Enclosed Alphanumerics
    // Box Drawing
    // Block Elements
    // Geometric Shapes
    // Miscellaneous Symbols
    // Dingbats
    // Miscellaneous Mathematical Symbols-A
    // Supplemental Arrows-A
    // Braille Patterns
    // Supplemental Arrows-B
    // Miscellaneous Mathematical Symbols-B
    // Supplemental Mathematical Operators
    // Miscellaneous Symbols and Arrows
    ‘\u2000-\u2BFF’,
    // Supplemental Punctuation
    ‘\u2E00-\u2E7F’,
    ‘]’
    ].join( ” ), ‘g’ ),
    astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
    wordsRegExp: /\S\s+/g,
    characters_excluding_spacesRegExp: /\S/g,
    characters_including_spacesRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g,
    l10n: window.wordCountL10n || {}
    };

    WordCounter.prototype.count = function( text, type ) {
    var count = 0;
    var tc = 0;

    type = type || this.settings.l10n.type;

    if ( type !== ‘characters_excluding_spaces’ && type !== ‘characters_including_spaces’ ) {
    type = ‘words’;
    }

    if ( text ) {
    text = text + ‘\n’;

    text = text.replace( this.settings.HTMLRegExp, ‘\n’ );
    text = text.replace( this.settings.HTMLcommentRegExp, ” );

    if ( this.settings.shortcodesRegExp ) {
    text = text.replace( this.settings.shortcodesRegExp, ‘\n’ );
    }

    text = text.replace( this.settings.spaceRegExp, ‘ ‘ );

    if ( type === ‘words’ ) {
    text = text.replace( this.settings.HTMLEntityRegExp, ” );
    text = text.replace( this.settings.connectorRegExp, ‘ ‘ );
    text = text.replace( this.settings.removeRegExp, ” );
    } else {
    text = text.replace( this.settings.HTMLEntityRegExp, ‘a’ );
    text = text.replace( this.settings.astralRegExp, ‘a’ );
    }

    // count east asia chars
    text = text.replace( this.settings.EastAsiaRegExp, function(){ tc++; return ”; } );

    text = text.match( this.settings[ type + ‘RegExp’ ] );

    if ( text ) {
    count = text.length;
    }
    }

    return (count + tc);
    };

    window.wp = window.wp || {};
    window.wp.utils = window.wp.utils || {};
    window.wp.utils.WordCounter = WordCounter;
    } )();

    https://wordpress.org/plugins/chinese-word-count/

  • The topic ‘WP 4.3 totally changed the implementation of word-count.js’ is closed to new replies.