Commit abdcd18b authored by MozLando's avatar MozLando
Browse files

Merge #4760

4760: Closes #2923: Remove moment.js from reader view web extension r=Amejia481 a=csadilek

Removes moment.js from reader view, and uses [Intl.RelativeTimeFormat](

) instead to construct a localized reading time string.

Tested this with various sites in Spanish, Arabic, German, and English to verify this works as before. We could improve this more later to detect the language if the article doesn't specify but that's a separate issue (which also doesn't work in Fennec currently).
Co-authored-by: default avatarChristian Sadilek <>
parents bb3a591f 91bc4f13
......@@ -5,7 +5,7 @@
"content_scripts": [
"matches": ["*://*/*"],
"js": ["readability/readability-0.2.0.js", "readability/readability-readerable-0.2.0.js", "moment/moment-2.24.0.js", "readerview.js"],
"js": ["readability/readability-0.2.0.js", "readability/readability-readerable-0.2.0.js", "readerview.js"],
"css": ["readerview.css"],
"run_at": "document_idle"
......@@ -191,15 +191,23 @@ class ReaderView {
const readingTimeMinsSlow = Math.ceil(length / charactersPerMinuteLow);
const readingTimeMinsFast = Math.ceil(length / charactersPerMinuteHigh);
// TODO remove moment.js:
// We only want to show minutes and not have it converted to hours.
moment.relativeTimeThreshold('m', Number.MAX_SAFE_INTEGER);
if (readingTimeMinsSlow == readingTimeMinsFast) {
return moment.duration(readingTimeMinsFast, 'minutes').locale(lang).humanize();
// Construct a localized and "humanized" reading time in minutes.
// If we have both a fast and slow reading time we'll show both e.g.
// "2 - 4 minutes", otherwise we'll just show "4 minutes".
var parts = new Intl.RelativeTimeFormat(lang).formatToParts(readingTimeMinsSlow, 'minute');
if (parts.length == 3) {
// No need to use part[0] which represents the literal "in".
var readingTime = parts[1].value; // reading time in minutes
var minutesLiteral = parts[2].value; // localized singular or plural literal of 'minute'
var readingTimeString = `${readingTime} ${minutesLiteral}`;
if (readingTimeMinsSlow != readingTimeMinsFast) {
readingTimeString = `${readingTimeMinsFast} - ${readingTimeString}`;
return readingTimeString;
return `${readingTimeMinsFast} - ${moment.duration(readingTimeMinsSlow, 'minutes').locale(lang).humanize()}`;
return "";
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment