Coder Social home page Coder Social logo

jquery-readingstats's Introduction

=========================== jQuery reading stats plugin

jQuery reading stats plugin, v1.0

Use it to calculate and display time to read a piece of text, eg a blog post.

How to use it?

There are two arguments and both are optional. The first is options object with which you can customize reading speed (in words per minute) and formatter funtion to display the result.

  • readingSpeed, default value is 200 words per minute
  • format, formatter function that takes a number (of seconds) and returns a string like 2 min 45 sec

There are two ways to call it. First is to get result directly, like this:

var rs = $('#my-content').readingStats({
    readingSpeed: 100,
    format: function (x) {return x.toString() + ' sec';}
});

console.log(rs.wordCount); // word count
console.log(rs.secondsToRead); // number of seconds
console.log(rs.format()); // formatted output

If you want to do something else with selector, you can specify callback function as second argument and chain whatever jQuery methods after it.

$('#my-content').readingStats({readingSpeed: 240}, function (stats) {
        console.log(stats);
        // do something with stats object
    }
).fadeOut().fadeIn();

Licence

The code is MIT licensed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.