User:Gary/comments in local time.js: Difference between revisions

Content deleted Content added
new code requested by User:YFdyh000
fixes
 
(16 intermediate revisions by 2 users not shown)
Line 1:
// Generated by CoffeeScript 1.8.0
 
/**
* COMMENTS IN LOCAL TIME
Line 11 ⟶ 9:
* [[Wikipedia:Comments in Local Time]]
*/
$(() => {
var CommentsInLocalTime, runScript;
/**
* Given a number, add a leading zero if necessary, so that the final number
* has two characters.
*
* @param {number} number Number
* @returns {string} The number with a leading zero, if necessary.
*/
function addLeadingZero(number) {
const numberArg = number;
 
if (numberArg < 10) {
CommentsInLocalTime = (function() {
return `0${numberArg}`;
var LocalComments, language;
}
 
return numberArg;
function CommentsInLocalTime() {}
}
 
function convertMonthToNumber(month) {
language = '';
return new Date(`${month} 1, 2001`).getMonth();
}
 
function getDates(time) {
LocalComments = {};
const [, oldHour, oldMinute, oldDay, oldMonth, oldYear] = time;
 
// Today
CommentsInLocalTime.settings = function() {
const today = new Date();
if (window.LocalComments != null) {
LocalComments = window.LocalComments;
}
 
/*/ Yesterday
const yesterday = new Date();
Language
LOCALIZING THIS SCRIPT
To localize this script, change the terms below,
to the RIGHT of the colons, to the correct term used in that language.
For example, in the French language,
'Today' : 'Today',
would be
'Today' : "Aujourd'hui",
*/
return LocalComments.language = {
 
yesterday.setDate(yesterday.getDate() - 1);
/* relative terms */
'Today': 'Today',
'Yesterday': 'Yesterday',
'Tomorrow': 'Tomorrow',
'last': 'last',
'this': 'this',
 
/*/ days of the week */Tomorrow
const tomorrow = new Date();
'Sunday': 'Sunday',
'Monday': 'Monday',
'Tuesday': 'Tuesday',
'Wednesday': 'Wednesday',
'Thursday': 'Thursday',
'Friday': 'Friday',
'Saturday': 'Saturday',
 
tomorrow.setDate(tomorrow.getDate() + 1);
/* months of the year */
'January': 'January',
'February': 'February',
'March': 'March',
'April': 'April',
'May': 'May',
'June': 'June',
'July': 'July',
'August': 'August',
'September': 'September',
'October': 'October',
'November': 'November',
'December': 'December',
 
// Set /*the differencedate words */entered.
const newTime = new Date();
'ago': 'ago',
'from now': 'from now',
 
newTime.setUTCFullYear(oldYear, convertMonthToNumber(oldMonth), oldDay);
/* date phrases */
newTime.setUTCHours(oldHour);
'year': 'year',
newTime.setUTCMinutes(oldMinute);
'years': 'years',
'month': 'month',
'months': 'months',
'day': 'day',
'days': 'days'
};
};
 
return { time: newTime, today, tomorrow, yesterday };
}
 
/**
* Determine whether to use the singular or plural word, and use that.
APPLICATION
*
* @param {string} term Original term
* @param {number} count Count of items
* @param {string} plural Pluralized term
* @returns {string} The word to use
*/
function pluralize(term, count, plural = null) {
let pluralArg = plural;
 
// No unique pluralized word is found, so just use a general one.
CommentsInLocalTime.init = function() {
if (!pluralArg) {
pluralArg = `${term}s`;
}
 
// There's only one item, so just use the singular word.
/*
if (count Settings=== 1) {
*/ return term;
var contentText, namespace, pageAction;
this.settings();
if (LocalComments.language == null) {
return false;
}
language = this.setDefaultSetting('language', LocalComments.language);
this.setDefaultSetting({
'dateDifference': true,
'dateFormat': 'dmy',
'dayOfWeek': true,
'dropDays': 0,
'dropMonths': 0,
'timeFirst': true,
'twentyFourHours': false
});
 
// There are multiple items, so use the plural word.
/*
return End SettingspluralArg;
*/}
if (mw.config.get('wgCanonicalNamespace') == '' || mw.config.get('wgCanonicalNamespace') == 'MediaWiki' || mw.config.get('wgCanonicalNamespace') == 'Special')
return;
 
class CommentsInLocalTime {
var disabled_urls = new Array('action=history'), unique_url = false, wikiPreview = new Array('action=edit', 'action=submit');
constructor() {
for (var i = 0; i < disabled_urls.length; i++)
this.language = '';
{
this.LocalComments = {};
if (document.___location.href.indexOf(disabled_urls[i]) != -1)
 
return;
/**
* Settings
*/
this.settings();
 
this.language = this.setDefaultSetting(
'language',
this.LocalComments.language
);
 
// These values are also reflected in the documentation:
// https://en.wikipedia.org/wiki/Wikipedia:Comments_in_Local_Time#Default_settings
this.setDefaultSetting({
dateDifference: true,
dateFormat: 'dmy',
dayOfWeek: true,
dropDays: 0,
dropMonths: 0,
timeFirst: true,
twentyFourHours: false,
});
}
 
adjustTime(originalTimestamp, search) {
for (var i = 0; i < wikiPreview.length; i++)
const { time, today, tomorrow, yesterday } = getDates(
{
originalTimestamp.match(search)
if (document.___location.href.indexOf(wikiPreview[i]) != -1)
);
unique_url = 'wikiPreview';
 
// A string matching the date pattern was found, but it cannot be
// converted to a Date object. Return it with no changes made.
if (Number.isNaN(time)) {
return [originalTimestamp, ''];
}
 
const date = this.determineDateText({
time,
today,
tomorrow,
yesterday,
});
 
const { ampm, hour } = this.getHour(time);
const minute = addLeadingZero(time.getMinutes());
const finalTime = `${hour}:${minute}${ampm}`;
 
// Determine the time offset.
const utcValue = (-1 * time.getTimezoneOffset()) / 60;
const utcOffset =
utcValue >= 0 ? `+${utcValue}` : `−${Math.abs(utcValue.toFixed(1))}`;
 
const utcPart = `(UTC${utcOffset})`;
 
const returnDate = this.LocalComments.timeFirst
? `${finalTime}, ${date} ${utcPart}`
: `${date}, ${finalTime} ${utcPart}`;
 
return returnDate;
}
 
convertNumberToMonth(number) {
var element_id = unique_url ? unique_url : 'bodyContent';
return [
contentText = document.getElementById(element_id);
this.language.January,
return this.replaceText(contentText, /(\d{1,2}):(\d{2}), (\d{1,2}) ([A-Z][a-z]+) (\d{4}) \(UTC\)/);
this.language.February,
};
this.language.March,
this.language.April,
this.language.May,
this.language.June,
this.language.July,
this.language.August,
this.language.September,
this.language.October,
this.language.November,
this.language.December,
][number];
}
 
createDateText({ day, month, time, today, year }) {
// Calculate day of week
const dayNames = [
this.language.Sunday,
this.language.Monday,
this.language.Tuesday,
this.language.Wednesday,
this.language.Thursday,
this.language.Friday,
this.language.Saturday,
];
const dayOfTheWeek = dayNames[time.getDay()];
let descriptiveDifference = '';
let last = '';
 
// Create a relative descriptive difference
if (this.LocalComments.dateDifference) {
({ descriptiveDifference, last } = this.createRelativeDate(
today,
time
));
}
 
const monthName = this.convertNumberToMonth(time.getMonth());
 
// Format the date according to user preferences
let formattedDate = '';
 
switch (this.LocalComments.dateFormat.toLowerCase()) {
case 'dmy':
formattedDate = `${day} ${monthName} ${year}`;
 
break;
case 'mdy':
formattedDate = `${monthName} ${day}, ${year}`;
 
break;
default:
formattedDate = `${year}-${month}-${addLeadingZero(day)}`;
}
 
const formattedDayOfTheWeek = this.LocalComments.dayOfWeek
? `, ${last}${dayOfTheWeek}`
: '';
 
return `${formattedDate}${formattedDayOfTheWeek}${descriptiveDifference}`;
CommentsInLocalTime.replaceText = function(node, search) {
var after, afterMatch, before, beforeMatch, child, children, length, match, matches, parent, parentNodeName, position, span, timeArray, timestamp, value, _i, _len, _results;
if (!node) {
return false;
}
 
if (node.nodeType === 3) {
/**
parent = node.parentNode;
* Create relative date data.
parentNodeName = parent.nodeName;
*
if (['CODE', 'PRE'].indexOf(parentNodeName) > -1) {
* @param {Date} returntoday false;Today
* @param {Date} time The timestamp from a comment
* @returns {Object.<string, *>} Relative date data
*/
createRelativeDate(today, time) {
/**
* The time difference from today, in milliseconds.
*
* @type {number}
*/
const millisecondsAgo = today.getTime() - time.getTime();
 
/**
* The number of days ago, that we will display. It's not necessarily the
* total days ago.
*
* @type {number}
*/
let daysAgo = Math.abs(Math.round(millisecondsAgo / 1000 / 60 / 60 / 24));
const { differenceWord, last } = this.relativeText({
daysAgo,
millisecondsAgo,
});
 
// This method of computing the years and months is not exact. However,
// it's better than the previous method that used 1 January + delta days.
// That was usually quite off because it mapped the second delta month to
// February, which has only 28 days. This method is usually not more than
// one day off, except perhaps over very distant dates.
 
/**
* The number of months ago, that we will display. It's not necessarily
* the total months ago.
*
* @type {number}
*/
let monthsAgo = Math.floor((daysAgo / 365) * 12);
 
/**
* The total amount of time ago, in months.
*
* @type {number}
*/
const totalMonthsAgo = monthsAgo;
 
/**
* The number of years ago that we will display. It's not necessarily the
* total years ago.
*
* @type {number}
*/
let yearsAgo = Math.floor(totalMonthsAgo / 12);
 
if (totalMonthsAgo < this.LocalComments.dropMonths) {
yearsAgo = 0;
} else if (this.LocalComments.dropMonths > 0) {
monthsAgo = 0;
} else {
monthsAgo -= yearsAgo * 12;
}
 
value = node.nodeValue;
if (daysAgo < this.LocalComments.dropDays) {
matches = value.match(search);
if (matches !=monthsAgo null)= {0;
matchyearsAgo = matches[0];
} else if (this.LocalComments.dropDays > 0 && totalMonthsAgo >= 1) {
position = value.search(search);
lengthdaysAgo = match.toString().length0;
} else {
beforeMatch = value.substring(0, position);
afterMatchdaysAgo -= valueMath.substringfloor(position(totalMonthsAgo * 365) +/ length12);
timeArray = this.adjustTime(match.toString(), search);
timestamp = timeArray[1] ? timeArray[1].getTime() : '';
span = document.createElement('span');
span.className = 'localcomments';
span.style.fontSize = '95%';
span.style.whiteSpace = 'nowrap';
span.setAttribute('timestamp', timestamp);
span.title = match;
span.appendChild(document.createTextNode(timeArray[0]));
parent = node.parentNode;
parent.replaceChild(span, node);
before = document.createElement('span');
before.className = 'before-localcomments';
before.appendChild(document.createTextNode(beforeMatch));
after = document.createElement('span');
after.className = 'after-localcomments';
after.appendChild(document.createTextNode(afterMatch));
parent.insertBefore(before, span);
return parent.insertBefore(after, span.nextSibling);
}
 
} else {
childrenconst descriptiveParts = [];
 
child = node.childNodes[0];
// There is years text to add.
while (child) {
if children.push(childyearsAgo > 0); {
child = childdescriptiveParts.nextSibling;push(
`${yearsAgo} ${pluralize(
this.language.year,
yearsAgo,
this.language.years
)}`
);
}
 
_results = [];
// There is months text to add.
for (_i = 0, _len = children.length; _i < _len; _i++) {
if (monthsAgo child> =0) children[_i];{
_resultsdescriptiveParts.push(this.replaceText(child, search));
`${monthsAgo} ${pluralize(
this.language.month,
monthsAgo,
this.language.months
)}`
);
}
return _results;
}
};
 
// There is days text to add.
CommentsInLocalTime.adjustTime = function(originalTimestamp, search) {
if (daysAgo > 0) {
var ampm, date, day, dayNames, dayOfTheWeek, descriptiveDifference, finalTime, formattedDate, formattedDayOfTheWeek, hour, last, minute, month, monthName, oldDay, oldHour, oldMinute, oldMonth, oldYear, returnDate, time, today, tomorrow, utcOffset, year, yesterday, _ref, _ref1;
descriptiveParts.push(
time = originalTimestamp.match(search);
`${daysAgo} ${pluralize(
_ref = [time[1], time[2], time[3], time[4], time[5]], oldHour = _ref[0], oldMinute = _ref[1], oldDay = _ref[2], oldMonth = _ref[3], oldYear = _ref[4];
this.language.day,
today = new Date();
yesterday = new Date(); daysAgo,
this.language.days
tomorrow = new Date();
)}`
yesterday.setDate(yesterday.getDate() - 1);
);
tomorrow.setDate(tomorrow.getDate() + 1);
time = new Date();}
 
time.setUTCFullYear(oldYear, this.convertMonthToNumber(oldMonth), oldDay);
return {
time.setUTCHours(oldHour);
descriptiveDifference: ` (${descriptiveParts.join(
time.setUTCMinutes(oldMinute);
if (isNaN(time)) { ', '
)} ${differenceWord})`,
return [originalTimestamp, ''];
last,
};
}
 
utcOffset = -1 * time.getTimezoneOffset() / 60;
determineDateText({ time, today, tomorrow, yesterday }) {
utcOffset = utcOffset >= 0 ? '+' + utcOffset : '−' + Math.abs(utcOffset);
// Set the date bits to output.
year = time.getFullYear();
month const year = this.addLeadingZero(time.getMonthgetFullYear() + 1);
day const month = addLeadingZero(time.getDategetMonth() + 1);
hour const day = parseInt(time.getHoursgetDate());
 
minute = this.addLeadingZero(time.getMinutes());
// Return 'today' or 'yesterday' if that is the case
ampm = '';
if (
if (LocalComments.twentyFourHours) {
hour year === thistoday.addLeadingZerogetFullYear(hour); &&
month === addLeadingZero(today.getMonth() + 1) &&
} else {
ampm = hourday <=== 11 ? ' am' : ' pm';today.getDate()
if (hour > 12) {
hourreturn -= 12this.language.Today;
} else if (hour === 0) {
hour = 12;
}
 
if (
year === yesterday.getFullYear() &&
month === addLeadingZero(yesterday.getMonth() + 1) &&
day === yesterday.getDate()
) {
return this.language.Yesterday;
}
 
if (
year === tomorrow.getFullYear() &&
month === addLeadingZero(tomorrow.getMonth() + 1) &&
day === tomorrow.getDate()
) {
return this.language.Tomorrow;
}
 
return this.createDateText({ day, month, time, today, year });
}
 
if (year === today.getFullYear() && month === this.addLeadingZero(today.getMonth() + 1) && day === today.getDate()) {
getHour(time) {
date = language['Today'];
let ampm;
} else if (year === yesterday.getFullYear() && month === this.addLeadingZero(yesterday.getMonth() + 1) && day === yesterday.getDate()) {
let hour = Number.parseInt(time.getHours(), 10);
date = language['Yesterday'];
 
} else if (year === tomorrow.getFullYear() && month === this.addLeadingZero(tomorrow.getMonth() + 1) && day === tomorrow.getDate()) {
if (this.LocalComments.twentyFourHours) {
date = language['Tomorrow'];
} else { ampm = '';
hour = addLeadingZero(hour);
dayNames = [language['Sunday'], language['Monday'], language['Tuesday'], language['Wednesday'], language['Thursday'], language['Friday'], language['Saturday']];
} else {
dayOfTheWeek = dayNames[time.getDay()];
// Output am or pm depending on the date.
descriptiveDifference = '';
last ampm = hour <= 11 ? ' am' : ' pm';
 
if (LocalComments.dateDifference) {
if (hour > 12) {
_ref1 = this.createRelativeDate(today, time), descriptiveDifference = _ref1.descriptiveDifference, last = _ref1.last;
hour -= 12;
} else if (hour === 0) {
hour = 12;
}
}
 
formattedDate = '';
return { ampm, hour };
monthName = this.convertNumberToMonth(time.getMonth());
}
formattedDate = (function() {
 
switch (LocalComments.dateFormat.toLowerCase()) {
relativeText({ daysAgo, millisecondsAgo }) {
case 'dmy':
let differenceWord = '';
return day + ' ' + monthName + ' ' + year;
let last case= 'mdy':;
 
return monthName + ' ' + day + ', ' + year;
// The date is default:in the past.
if (millisecondsAgo >= 0) {
return year + '-' + month + '-' + this.addLeadingZero(day);
differenceWord = this.language.ago;
 
if (daysAgo <= 7) {
last = `${this.language.last} `;
}
 
// The date is in the future.
} else {
differenceWord = this.language['from now'];
 
if (daysAgo <= 7) {
last = `${this.language.this} `;
}
}).call(this);
formattedDayOfTheWeek = '';
if (LocalComments.dayOfWeek) {
formattedDayOfTheWeek = ', ' + last + dayOfTheWeek;
}
 
date = formattedDate + formattedDayOfTheWeek + descriptiveDifference;
return { differenceWord, last };
}
finalTime = hour + ':' + minute + ampm;
if (LocalComments.timeFirst) {
returnDate = finalTime + ', ' + date + ' (UTC' + utcOffset + ')';
} else {
returnDate = date + ', ' + finalTime + ' (UTC' + utcOffset + ')';
}
return [returnDate, time];
};
 
replaceText(node, search) {
CommentsInLocalTime.createRelativeDate = function(today, time) {
if (!node) {
var daysAgo, descriptiveParts, differenceWord, fmtDays, fmtMonths, fmtYears, last, millisecondsAgo, monthsAgo, totalMonthsAgo, yearsAgo;
return;
millisecondsAgo = today.getTime() - time.getTime();
daysAgo = Math.abs(Math.round(millisecondsAgo / 1000 / 60 / 60 / 24));
differenceWord = '';
last = '';
if (millisecondsAgo >= 0) {
differenceWord = language['ago'];
if (daysAgo <= 7) {
last = language['last'] + ' ';
}
 
} else {
// Check if this is a text node.
differenceWord = language['from now'];
if (daysAgonode.nodeType <=== 73) {
last// = language[Don't continue if this'] +text node's ';parent tag is one of these.
if (['CODE', 'PRE'].includes(node.parentNode.nodeName)) {
return;
}
 
const value = node.nodeValue;
const matches = value.match(search);
 
if (matches) {
// Only act on the first timestamp we found in this node. This is for
// the rare occassion that there is more than one timestamp in the
// same text node.
const [match] = matches;
const position = value.search(search);
const stringLength = match.toString().length;
 
// Grab the text content before and after the matching timestamp,
// which we'll then wrap in their own SPAN nodes.
const beforeMatch = value.slice(0, position);
const afterMatch = value.slice(position + stringLength);
const returnDate = this.adjustTime(match.toString(), search);
 
// Create the code to display the new local comments content.
const $span = $(
`<span class="localcomments" style="font-size: 95%;" title="${match}">${returnDate}</span>`
);
 
// Replace the existing text node in the page with our new local
// comments node.
$(node).replaceWith($span);
 
// Replace the text content that appears before the timestamp.
if (beforeMatch) {
$span.before(
`<span class="before-localcomments">${beforeMatch}</span>`
);
}
 
// Replace the text content that appears after the timestamp.
if (afterMatch) {
$span.after(
`<span class="after-localcomments">${afterMatch}</span>`
);
}
}
} else {
const children = [];
let child;
 
[child] = node.childNodes;
 
while (child) {
children.push(child);
child = child.nextSibling;
}
 
// Loop through children and run this func on it again, recursively.
children.forEach((child2) => {
this.replaceText(child2, search);
});
}
}
monthsAgo = Math.floor(daysAgo / 365 * 12);
totalMonthsAgo = monthsAgo;
yearsAgo = Math.floor(monthsAgo / 12);
if (monthsAgo < LocalComments.dropMonths) {
yearsAgo = 0;
} else if (LocalComments.dropMonths > 0) {
monthsAgo = 0;
} else {
monthsAgo = monthsAgo - yearsAgo * 12;
}
if (daysAgo < LocalComments.dropDays) {
monthsAgo = 0;
yearsAgo = 0;
} else if (LocalComments.dropDays > 0) {
daysAgo = 0;
} else {
daysAgo = daysAgo - Math.floor(totalMonthsAgo * 365 / 12);
}
descriptiveParts = [];
if (yearsAgo > 0) {
fmtYears = yearsAgo + ' ' + this.pluralize(language['year'], yearsAgo, language['years']);
descriptiveParts.push(fmtYears);
}
if (monthsAgo > 0) {
fmtMonths = monthsAgo + ' ' + this.pluralize(language['month'], monthsAgo, language['months']);
descriptiveParts.push(fmtMonths);
}
if (daysAgo > 0) {
fmtDays = daysAgo + ' ' + this.pluralize(language['day'], daysAgo, language['days']);
descriptiveParts.push(fmtDays);
}
return {
descriptiveDifference: ' (' + descriptiveParts.join(', ') + ' ' + differenceWord + ')',
last: last
};
};
 
run() {
if (
['', 'MediaWiki', 'Special'].includes(
mw.config.get('wgCanonicalNamespace')
)
) {
return;
}
 
// Check for disabled URLs.
/*
const isDisabledUrl = ['action=history'].some((disabledUrl) =>
HELPERS
document.___location.href.includes(disabledUrl)
*/
);
 
if (isDisabledUrl) {
CommentsInLocalTime.addLeadingZero = function(number) {
if (number < 10) {return;
number = '0' + number;}
 
this.replaceText(
document.querySelector('.mw-body-content .mw-parser-output'),
/(\d{1,2}):(\d{2}), (\d{1,2}) ([A-Z][a-z]+) (\d{4}) \(UTC\)/
);
}
return number;
};
 
setDefaultSetting(...args) {
CommentsInLocalTime.convertMonthToNumber = function(month) {
// There are no arguments.
return (new Date(month + ' 1, 2001')).getMonth();
if (args.length === 0) {
};
return false;
}
 
// The first arg is an object, so just set that data directly onto the
CommentsInLocalTime.convertNumberToMonth = function(number) {
// settings object. like {setting 1: true, setting 2: false}
return [language['January'], language['February'], language['March'], language['April'], language['May'], language['June'], language['July'], language['August'], language['September'], language['October'], language['November'], language['December']][number];
if (typeof args[0] === 'object') {
};
const [settings] = args;
 
// Loop through each setting.
CommentsInLocalTime.pluralize = function(term, count, plural) {
Object.keys(settings).forEach((name) => {
if (plural === null) {
plural = term + 's'const value = settings[name];
}
if (count === 1) {
return term;
} else {
return plural;
}
};
 
if (typeof this.LocalComments[name] === 'undefined') {
CommentsInLocalTime.setDefaultSetting = function() {
this.LocalComments[name] = value;
var defaultSetting, name, settings;
}
if (!arguments.length) {
return false });
 
}
return settings;
if (typeof arguments[0] === 'object') {
settings = arguments[0];
for (name in settings) {
defaultSetting = settings[name];
if (LocalComments[name] == null) {
LocalComments[name] = defaultSetting;
}
}
 
return settings;
// The first arg is a string, so use the first arg as the settings key,
} else if (typeof arguments[0] === 'string') {
// and the second arg as the value to set it to.
name = arguments[0];
const [name, setting] = args;
defaultSetting = arguments[1];
 
if (LocalComments[name] == null) {
if (typeof this.LocalComments[name] === 'undefined') defaultSetting;{
this.LocalComments[name] = setting;
}
 
return LocalComments[name];
return this.LocalComments[name];
}
};
 
/**
return CommentsInLocalTime;
* Set the script's settings.
*
* @returns {undefined}
*/
settings() {
// The user has set custom settings, so use those.
if (window.LocalComments) {
this.LocalComments = window.LocalComments;
}
 
/**
})();
* Language
*
* LOCALIZING THIS SCRIPT
* To localize this script, change the terms below,
* to the RIGHT of the colons, to the correct term used in that language.
*
* For example, in the French language,
*
* 'Today' : 'Today',
*
* would be
*
* 'Today' : "Aujourd'hui",
*/
this.LocalComments.language = {
// Relative terms
Today: 'Today',
Yesterday: 'Yesterday',
Tomorrow: 'Tomorrow',
last: 'last',
this: 'this',
 
// Days of the week
checkScript = function() {
Sunday: 'Sunday',
if (window.___location.href.indexOf('&disable=loco') === -1) {
Monday: 'Monday',
return CommentsInLocalTime.init();
Tuesday: 'Tuesday',
Wednesday: 'Wednesday',
Thursday: 'Thursday',
Friday: 'Friday',
Saturday: 'Saturday',
 
// Months of the year
January: 'January',
February: 'February',
March: 'March',
April: 'April',
May: 'May',
June: 'June',
July: 'July',
August: 'August',
September: 'September',
October: 'October',
November: 'November',
December: 'December',
 
// Difference words
ago: 'ago',
'from now': 'from now',
 
// Date phrases
year: 'year',
years: 'years',
month: 'month',
months: 'months',
day: 'day',
days: 'days',
};
}
}
}
 
// Check if we've already ran this script.
runScript = function() {
if (window.commentsInLocalTimeWasRun) {
mw.hook('wikipage.content').add( function ( $content ) {
return;
setTimeout("checkScript();", 0);
});
 
return $(window).load(function() {
window.commentsInLocalTimeWasRun = true;
return checkScript();
 
});
const commentsInLocalTime = new CommentsInLocalTime();
};
 
commentsInLocalTime.run();
if (typeof waitForScripts === 'function') {
});
waitForScripts(runScript);
} else {
runScript();
}