Commit 91bc4f13 authored by Christian Sadilek's avatar Christian Sadilek
Browse files

Closes #2923: Remove moment.js from reader view web extension

parent 3bb3548e
......@@ -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: https://github.com/mozilla-mobile/android-components/issues/2923
// 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