Repository: michael-lynch/reading-time Branch: master Commit: 81742b215996 Files: 14 Total size: 45.8 KB Directory structure: gitextract_qtj90du5/ ├── .gitignore ├── LICENSE.md ├── README.md ├── bower.json ├── demo/ │ ├── articles/ │ │ ├── a.html │ │ ├── b.html │ │ └── c.html │ ├── index.html │ ├── remote-multiple.html │ └── remote.html ├── package.json ├── reading-time.jquery.json └── src/ ├── css/ │ └── style.css └── readingtime.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .DS_Store .idea/* ================================================ FILE: LICENSE.md ================================================ The MIT License Copyright (c) 2013 Michael Lynch Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # Reading Time [![CDNJS](https://img.shields.io/cdnjs/v/reading-time.svg)](https://cdnjs.com/libraries/reading-time) Inspired by [Medium](http://medium.com), Reading Time is a simple, lightweight jQuery plugin used to display an estimated time to read some text. See a demo See a demo using a remote file See a demo using multiple remote files ## Instructions Include jQuery and the plugin in the head or footer of your page. ```html ``` Create an element with the class of 'eta' where the estimated reading time will display. ```html
``` Optionally you can also create an element with whatever class or ID you want to display the total word count. The word count will only be displayed if you set the wordCountTarget parameter when initiating the plugin (see below). ```html
``` Initialize the plugin targeting the class, ID or element that contains the text in which you want to estimate the reading time of. ```js $('article').readingTime(); ``` #### Options
  1. readingTimeAsNumber: boolean
    If you want to take reading time as integer, you can use this (default: 'false').
  2. readingTimeTarget: "id / class / element"
    A string that defines the ID, class or element that will store the estimated reading time (default: 'eta').
  3. wordCountTarget: "id / class / element"
    A string that defines the ID, class or element that will store the total word count (default: '').
  4. remotePath: "path"
    A string that indicates the path to the remote file (default: null).
  5. remoteTarget: "id / class / element"
    A string that defines the ID, class or element in the remote file that contains the text in which you want to estimate the reading time of (default: null).
  6. wordsPerMinute: integer
    An integer that defines the words per minute at which to calculate the estimated reading time (default: 270).
  7. round: boolean
    A boolean value that indicates whether or not the estimated reading time should be rounded to the closest minute (default: true).
  8. lang: "en / fr / de / es / nl / sk / cz / ru / zh / kr"
    A two letter string that indicates the language to be used (default: "en").
  9. lessThanAMinuteString: string
    A string that changes the default "Less than a minute" copy (default: '').
  10. prependTimeString: string
    A string that is prepended before the estimated reading time (default: '').
  11. prependWordString: string
    A string that is prepended before the total word count (default: '').
  12. success: function(data) {}
    A callback function that runs if the plugin was successful (default: `function()`).
  13. error: function(data) {}
    A callback function that runs if the plugin fails (default: `function(message)`).
##### Example: ```js $(function() { $('article').readingTime({ readingTimeAsNumber: true, readingTimeTarget: $('.reading-time'), wordsPerMinute: 275, round: false, lang: 'fr', success: function(data) { console.log(data); }, error: function(data) { console.log(data.error); $('.reading-time').remove(); } }); }); ``` ##### Multiple Articles Often you will have multiple articles or excerpts on a single page, in which case you would want to iterate through each. ```js $('article').each(function() { let _this = $(this); _this.readingTime({ readingTimeTarget: _this.find('.reading-time') }); }); ``` ##### Using a Remote File If you want to display the estimated reading time of copy that lives in a remote file, you would initialize the plugin and use the remotePath and remoteTarget options. In this case, the plugin would display the amount of text contained in the element with the class of "my-article" in the file called "remote.html." ```js $('article').readingTime({ remotePath: 'path/to/remote/file.html', remoteTarget: '.my-article' }); ``` See a demo using a remote file ##### Using Multiple Remote Files If you want to display the estimated reading time of copy for multiple articles that live in remote files, you would want to iterate through each article on your page and use data attributes to declare the file and target for each article. Be sure to initialize the plugin on the body and use the remotePath and remoteTarget options. Here is what your markup might look like (notice the data-file and data-target attributes on each article): ```html

Magna Lorem Quam Nullam

By: Mike Lynch

( words)

Nullam id dolor id nibh ultricies vehicula ut id elit. Curabitur blandit tempus porttitor. Nulla vitae elit libero, a pharetra augue. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Read more

Justo Cursus Inceptos Ipsum

By: Mike Lynch

( words)

Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

Read more

Sem Vehicula Dapibus Malesuada

By: Mike Lynch

( words)

Nullam quis risus eget urna mollis ornare vel eu leo. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Nullam id dolor id nibh ultricies vehicula ut id elit. Nullam id dolor id nibh ultricies vehicula ut id elit.

Read more
``` Here is what your JS would look like: ```js $('article').each(function() { let _this = $(this); _this.readingTime({ readingTimeTarget: _this.find('.eta'), wordCountTarget: _this.find('.words'), remotePath: _this.attr('data-file'), remoteTarget: _this.attr('data-target') }); }); ``` See a demo using multiple remote files ================================================ FILE: bower.json ================================================ { "name": "reading-time", "version": "2.0.0", "homepage": "https://github.com/michael-lynch/reading-time", "authors": [ "Michael Lynch " ], "description": "A simple, lightweight jQuery plugin used to display an estimated time to read some text.", "main": "src/readingtime.js", "keywords": [ "reading", "time", "estimated", "eta" ], "license": "MIT", "ignore": [ "**/.*", "node_modules", "bower_components", "test", "tests" ] } ================================================ FILE: demo/articles/a.html ================================================ Reading Time jQuery Plugin

Magna Lorem Quam Nullam

By: Mike Lynch

( words)

Nullam id dolor id nibh ultricies vehicula ut id elit. Curabitur blandit tempus porttitor. Nulla vitae elit libero, a pharetra augue. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Donec id elit non mi porta gravida at eget metus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Curabitur blandit tempus porttitor. Aenean lacinia bibendum nulla sed consectetur. Etiam porta sem malesuada magna mollis euismod.

Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Curabitur blandit tempus porttitor. Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Cras mattis consectetur purus sit amet fermentum.

Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Donec ullamcorper nulla non metus auctor fringilla. Nullam quis risus eget urna mollis ornare vel eu leo. Donec sed odio dui. Aenean lacinia bibendum nulla sed consectetur. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.

================================================ FILE: demo/articles/b.html ================================================ Reading Time jQuery Plugin

Justo Cursus Inceptos Ipsum

By: Mike Lynch

( words)

Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Aenean lacinia bibendum nulla sed consectetur. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Maecenas sed diam eget risus varius blandit sit amet non magna.

Vestibulum id ligula porta felis euismod semper. Sed posuere consectetur est at lobortis. Nullam id dolor id nibh ultricies vehicula ut id elit. Aenean lacinia bibendum nulla sed consectetur. Donec id elit non mi porta gravida at eget metus. Curabitur blandit tempus porttitor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Maecenas sed diam eget risus varius blandit sit amet non magna. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Vestibulum id ligula porta felis euismod semper. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Leo risus, porta ac consectetur ac, vestibulum at eros. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

Risus, porta ac consectetur ac, vestibulum at eros. Aenean lacinia bibendum nulla sed consectetur. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Maecenas sed diam eget risus varius blandit sit amet non magna.

Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Aenean lacinia bibendum nulla sed consectetur. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Maecenas sed diam eget risus varius blandit sit amet non magna.

Vestibulum id ligula porta felis euismod semper. Sed posuere consectetur est at lobortis. Nullam id dolor id nibh ultricies vehicula ut id elit. Aenean lacinia bibendum nulla sed consectetur. Donec id elit non mi porta gravida at eget metus. Curabitur blandit tempus porttitor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Maecenas sed diam eget risus varius blandit sit amet non magna. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Vestibulum id ligula porta felis euismod semper. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Leo risus, porta ac consectetur ac, vestibulum at eros. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

Risus, porta ac consectetur ac, vestibulum at eros. Aenean lacinia bibendum nulla sed consectetur. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Maecenas sed diam eget risus varius blandit sit amet non magna.

================================================ FILE: demo/articles/c.html ================================================ Reading Time jQuery Plugin

Sem Vehicula Dapibus Malesuada

By: Mike Lynch

( words)

Nullam quis risus eget urna mollis ornare vel eu leo. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Nullam id dolor id nibh ultricies vehicula ut id elit. Nullam id dolor id nibh ultricies vehicula ut id elit.

Etiam porta sem malesuada magna mollis euismod. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Vestibulum id ligula porta felis euismod semper. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam quis risus eget urna mollis ornare vel eu leo. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Sed posuere consectetur est at lobortis.

Nullam quis risus eget urna mollis ornare vel eu leo. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Nullam id dolor id nibh ultricies vehicula ut id elit. Nullam id dolor id nibh ultricies vehicula ut id elit.

Etiam porta sem malesuada magna mollis euismod. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Vestibulum id ligula porta felis euismod semper. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam quis risus eget urna mollis ornare vel eu leo. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Sed posuere consectetur est at lobortis.

Nullam quis risus eget urna mollis ornare vel eu leo. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Nullam id dolor id nibh ultricies vehicula ut id elit. Nullam id dolor id nibh ultricies vehicula ut id elit.

Etiam porta sem malesuada magna mollis euismod. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Vestibulum id ligula porta felis euismod semper. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam quis risus eget urna mollis ornare vel eu leo. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Sed posuere consectetur est at lobortis.

Nullam quis risus eget urna mollis ornare vel eu leo. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Nullam id dolor id nibh ultricies vehicula ut id elit. Nullam id dolor id nibh ultricies vehicula ut id elit.

Etiam porta sem malesuada magna mollis euismod. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Vestibulum id ligula porta felis euismod semper. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam quis risus eget urna mollis ornare vel eu leo. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Sed posuere consectetur est at lobortis.

Nullam quis risus eget urna mollis ornare vel eu leo. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Nullam id dolor id nibh ultricies vehicula ut id elit. Nullam id dolor id nibh ultricies vehicula ut id elit.

Etiam porta sem malesuada magna mollis euismod. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Vestibulum id ligula porta felis euismod semper. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Nullam quis risus eget urna mollis ornare vel eu leo. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Sed posuere consectetur est at lobortis.

================================================ FILE: demo/index.html ================================================ Reading Time jQuery Plugin

Dethroning King Coal

By: Peter Singer

( words)

Earlier this year, the concentration of carbon dioxide in the atmosphere reached 400 parts per million (ppm). The last time there was that much CO2 in our atmosphere was three million years ago, when sea levels were 24 meters higher than they are today. Now sea levels are rising again. Last September, Arctic sea ice covered the smallest area ever recorded. All but one of the ten warmest years since 1880, when global records began to be kept, have occurred in the twenty-first century.

Some climate scientists believe that 400 ppm of CO2 in the atmosphere is already enough to take us past the tipping point at which we risk a climate catastrophe that will turn billions of people into refugees. They say that we need to get the amount of atmospheric CO2 back down to 350 ppm. That figure lies behind the name taken by 350.org, a grassroots movement with volunteers in 188 countries trying to solve the problem of climate change.

Other climate scientists are more optimistic: they argue that if we allow atmospheric CO2 to rise to 450 ppm, a level associated with a two-degree Celsius temperature rise, we have a 66.6% chance of avoiding catastrophe. That still leaves a one-in-three chance of catastrophe – worse odds than playing Russian roulette. And we are forecast to surpass 450 ppm by 2038.

One thing is clear: if we are not to be totally reckless with our planet’s climate, we cannot burn all the coal, oil, and natural gas that we have already located. About 80% of it – especially the coal, which emits the most CO2 when burned – will have to stay in the ground.

In June, US President Barack Obama told students at Georgetown University that he refused to condemn them and their children and grandchildren to “a planet that’s beyond fixing.” Saying that climate change cannot wait for Congress to overcome its “partisan gridlock,” he announced measures using his executive power to limit CO2 emissions, first from new fossil-fuel power plants, and then from existing ones.

Obama also called for an end to public financing of new coal plants overseas, unless they deploy carbon-capture technologies (which are not yet economically viable), or else there is, he said, “no other viable way for the poorest countries to generate electricity.”

According to Daniel Schrag, Director of Harvard University’s Center for the Environment and a member of a presidential science panel that has helped to advise Obama on climate change, “Politically, the White House is hesitant to say they’re having a war on coal. On the other hand, a war on coal is exactly what’s needed.”

Schrag is right. His university, like mine and many others, has a plan to reduce its greenhouse-gas emissions. Yet most of them, including Schrag’s and mine, continue to invest part of their multi-billion-dollar endowments in companies that extract and sell coal.

But pressure on educational institutions to stop investing in fossil fuels is beginning to build. Student groups have formed on many campuses, and a handful of colleges and universities have already pledged to end their investment in fossil fuels. Several US cities, including San Francisco and Seattle, have agreed to do the same.

Now financial institutions, too, are coming under fire for their involvement with fossil fuels. In June, I was part of a group of prominent Australians who signed an open letter to the heads of the country’s biggest banks asking them to stop lending to new fossil-fuel extraction projects, and to sell their stakes in companies engaged in such activities.

Speaking at Harvard earlier this year, former US Vice President Al Gore praised a student group that was pushing the university to sell its investments in fossil-fuel companies, and compared their activities to the divestment campaign in the 1980’s that helped to end South Africa’s racist apartheid policy.

How fair is that comparison? The dividing lines may be less sharp than they were with apartheid, but our continued high level of greenhouse-gas emissions protects the interests of one group of humans – mainly affluent people who are alive today – at the cost of others. (Compared to most of the world’s population, even the American and Australian coal miners who would lose their jobs if the industry shut down are affluent.) Our behavior disregards most of the world’s poor, and everyone who will live on this planet in centuries to come.

Worldwide, the poor leave a very small carbon footprint, but they will suffer the most from climate change. Many live in hot places that are getting even hotter, and hundreds of millions of them are subsistence farmers who depend on rainfall to grow their crops. Rainfall patterns will vary, and the Asian monsoon will become less reliable. Those who live on this planet in future centuries will live in a hotter world, with higher sea levels, less arable land, and more extreme hurricanes, droughts, and floods.

In these circumstances, to develop new coal projects is unethical, and to invest in them is to be complicit in this unethical activity. While this applies, to some extent, to all fossil fuels, the best way to begin to change our behavior is by reducing coal consumption. Replacing coal with natural gas does reduce greenhouse-gas emissions, even if natural gas itself is not sustainable in the long term. Right now, ending investment in the coal industry is the right thing to do.

================================================ FILE: demo/remote-multiple.html ================================================ Reading Time jQuery Plugin

Magna Lorem Quam Nullam

By: Mike Lynch

( words)

Nullam id dolor id nibh ultricies vehicula ut id elit. Curabitur blandit tempus porttitor. Nulla vitae elit libero, a pharetra augue. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Read more

Justo Cursus Inceptos Ipsum

By: Mike Lynch

( words)

Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

Read more

Sem Vehicula Dapibus Malesuada

By: Mike Lynch

( words)

Nullam quis risus eget urna mollis ornare vel eu leo. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Nullam id dolor id nibh ultricies vehicula ut id elit. Nullam id dolor id nibh ultricies vehicula ut id elit.

Read more
================================================ FILE: demo/remote.html ================================================ Reading Time jQuery Plugin

Dethroning King Coal

By: Peter Singer

( words)

Earlier this year, the concentration of carbon dioxide in the atmosphere reached 400 parts per million (ppm). The last time there was that much CO2 in our atmosphere was three million years ago, when sea levels were 24 meters higher than they are today. Now sea levels are rising again. Last September, Arctic sea ice covered the smallest area ever recorded. All but one of the ten warmest years since 1880, when global records began to be kept, have occurred in the twenty-first century.

Read more
================================================ FILE: package.json ================================================ { "name": "reading-time", "version": "2.0.0", "homepage": "https://github.com/michael-lynch/reading-time", "author": "Michael Lynch ", "description": "A simple, lightweight jQuery plugin used to display an estimated time to read some text.", "main": "build/readingtime.min.js", "license": "MIT", "keywords": [ "reading", "time", "estimated", "eta" ] } ================================================ FILE: reading-time.jquery.json ================================================ { "name": "reading-time", "title": "Reading Time", "description": "A simple, lightweight jQuery plugin used to display an estimated time to read some text.", "keywords": [ "reading", "time", "estimated", "eta" ], "version": "2.0.0", "author": { "name": "Michael Lynch", "url": "http://michaelynch.com" }, "licenses": [ { "type": "MIT", "url": "https://raw.github.com/michael-lynch/reading-time/master/LICENSE.md" } ], "dependencies": { "jquery": ">=1.8" } } ================================================ FILE: src/css/style.css ================================================ body { font: 18px Georgia, Times, "Times New Roman", serif; line-height: 28px; color: #333; margin: 80px 10%; max-width: 800px; width: 80%; } article { margin: 0 0 40px 0; } h1 { font: 36px "Gill Sans", "Gill Sans MT", Calibri, sans-serif; margin: 0; } a { text-decoration: none; color: #333; } a:hover { color: crimson; } small { font: 14px "Gill Sans", "Gill Sans MT", Calibri, sans-serif; text-transform: uppercase; } p { margin: 0 0 15px 0; } .btn { font: 18px "Gill Sans", "Gill Sans MT", Calibri, sans-serif; text-transform: uppercase; display: inline-block; background: gainsboro; margin: 10px 0; padding: 15px; } .btn:hover { background: crimson; color: white; } ================================================ FILE: src/readingtime.js ================================================ /*! Name: Reading Time Dependencies: jQuery Author: Michael Lynch Author URL: http://michaelynch.com Date Created: August 14, 2013 Date Updated: April 30, 2018 Licensed under the MIT license */ ;(function($) { $.fn.readingTime = function(options) { // define default parameters const defaults = { readingTimeTarget: '.eta', readingTimeAsNumber: false, wordCountTarget: null, wordsPerMinute: 270, round: true, lang: 'en', lessThanAMinuteString: '', prependTimeString: '', prependWordString: '', remotePath: null, remoteTarget: null, success: function() {}, error: function() {} }; const plugin = this; const el = $(this); let wordsPerSecond; let lessThanAMinute; let minShortForm; let totalWords; let totalReadingTimeSeconds; let readingTimeMinutes; let readingTimeSeconds; let readingTime; let readingTimeObj; // merge defaults and options plugin.settings = $.extend({}, defaults, options); // define vars const s = plugin.settings; const setTime = function(o) { if(o.text !== '') { if (s.lang == "zh") { let text = o.text.trim(); // step 1: count the number of Chinese characters const charArray = text.match(/[\u4e00-\u9fa5]/g); let charCount = 0; if (charArray != null) { charCount = charArray.length; } // step 2: replace all the Chinese characters with blank text = text.replace(/[\u4e00-\u9fa5]/g, " "); // step 3:replace newlines with blank text = text.replace(/[\r\n]/g, " "); // step 4:replace special characters with blank text = text.replace(/\W+/g, " "); // step 5: count the number of total English words const totalEnWords = text.trim().split(/\s+/g).length; totalWords = totalEnWords + charCount; } else { //split text by spaces to define total words totalWords = o.text.trim().split(/\s+/g).length; } //define words per second based on words per minute (s.wordsPerMinute) wordsPerSecond = s.wordsPerMinute / 60; //define total reading time in seconds totalReadingTimeSeconds = totalWords / wordsPerSecond; // define reading time readingTimeMinutes = Math.floor(totalReadingTimeSeconds / 60); // define remaining reading time seconds readingTimeSeconds = Math.round(totalReadingTimeSeconds - (readingTimeMinutes * 60)); // format reading time readingTime = `${readingTimeMinutes}:${readingTimeSeconds}`; // if s.round if(s.round) { // if minutes are greater than 0 if(readingTimeMinutes > 0) { // set reading time by the minute $(s.readingTimeTarget).text(s.prependTimeString + readingTimeMinutes + ((!s.readingTimeAsNumber) ? ' ' + minShortForm : '')); } else { // set reading time as less than a minute $(s.readingTimeTarget).text((!s.readingTimeAsNumber) ? s.prependTimeString + lessThanAMinute : readingTimeMinutes); } } else { // set reading time in minutes and seconds $(s.readingTimeTarget).text(s.prependTimeString + readingTime); } // if word count container isn't blank or undefined if(s.wordCountTarget !== '' && s.wordCountTarget !== undefined) { // set word count $(s.wordCountTarget).text(s.prependWordString + totalWords); } readingTimeObj = { wpm: s.wordsPerMinute, words: totalWords, eta: { time: readingTime, minutes: readingTimeMinutes, seconds: totalReadingTimeSeconds } }; // run success callback s.success.call(this, readingTimeObj); } else { // run error callback s.error.call(this, { error: 'The element does not contain any text' }); } }; // if no element was bound if(!this.length) { // run error callback s.error.call(this, { error: 'The element could not be found' }); // return so chained events can continue return this; } // Use switch instead of ifs switch (s.lang) { // if s.lang is Arabic case 'ar': lessThanAMinute = s.lessThanAMinuteString || "أقل من دقيقة"; minShortForm = 'دقيقة'; break; // if s.lang is Czech case 'cz': lessThanAMinute = s.lessThanAMinuteString || "Méně než minutu"; minShortForm = 'min'; break; // if s.lang is Danish case 'da': lessThanAMinute = s.lessThanAMinuteString || "Mindre end et minut"; minShortForm = 'min'; break; // if s.lang is German case 'de': lessThanAMinute = s.lessThanAMinuteString || "Weniger als eine Minute"; minShortForm = 'min'; break; // if s.lang is Spanish case 'es': lessThanAMinute = s.lessThanAMinuteString || "Menos de un minuto"; minShortForm = 'min'; break; // if s.lang is French case 'fr': lessThanAMinute = s.lessThanAMinuteString || "Moins d'une minute"; minShortForm = 'min'; break; // if s.lang is Hungarian case 'hu': lessThanAMinute = s.lessThanAMinuteString || "Kevesebb mint egy perc"; minShortForm = 'perc'; break; // if s.lang is Icelandic case 'is': lessThanAMinute = s.lessThanAMinuteString || "Minna en eina mínútu"; minShortForm = 'min'; break; // if s.lang is Italian case 'it': lessThanAMinute = s.lessThanAMinuteString || "Meno di un minuto"; minShortForm = 'min'; break; // if s.lang is Dutch case 'nl': lessThanAMinute = s.lessThanAMinuteString || "Minder dan een minuut"; minShortForm = 'min'; break; // if s.lang is Norwegian case 'no': lessThanAMinute = s.lessThanAMinuteString || "Mindre enn ett minutt"; minShortForm = 'min'; break; // if s.lang is Polish case 'pl': lessThanAMinute = s.lessThanAMinuteString || "Mniej niż minutę"; minShortForm = 'min'; break; // if s.lang is Russian case 'ru': lessThanAMinute = s.lessThanAMinuteString || "Меньше минуты"; minShortForm = 'мин'; break; // if s.lang is Slovak case 'sk': lessThanAMinute = s.lessThanAMinuteString || "Menej než minútu"; minShortForm = 'min'; break; // if s.lang is Swedish case 'sv': lessThanAMinute = s.lessThanAMinuteString || "Mindre än en minut"; minShortForm = 'min'; break; // if s.lang is Turkish case 'tr': lessThanAMinute = s.lessThanAMinuteString || "Bir dakikadan az"; minShortForm = 'dk'; break; // if s.lang is Ukrainian case 'uk': lessThanAMinute = s.lessThanAMinuteString || "Менше хвилини"; minShortForm = 'хв'; break; // if s.lang is Greek case 'el': lessThanAMinute = s.lessThanAMinuteString || 'Λιγότερο από λεπτό'; minShortForm = 'λεπτά'; break; // if s.lang is Portuguese case 'pt-BR': lessThanAMinute = s.lessThanAMinuteString || 'Menos de um minuto'; minShortForm = 'min'; break; // if s.lang is Korean case 'kr': lessThanAMinute = s.lessThanAMinuteString || '1분 이하'; minShortForm = '분'; break; // default s.lang in english default: lessThanAMinute = s.lessThanAMinuteString || 'Less than a minute'; minShortForm = 'min'; } // for each element el.each(function(index) { // if s.remotePath and s.remoteTarget aren't null if(s.remotePath != null && s.remoteTarget != null) { // get contents of remote file $.get(s.remotePath, function(data) { let wrapper = document.createElement('div'); wrapper.innerHTML = data; // set time using the remote target found in the remote file setTime({ text: $(wrapper).find(s.remoteTarget).text() }); }); } else { // set time using the targeted element setTime({ text: el.text() }); } }); return true; } })(jQuery);