User:Gary/minutes later for diff.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Gary/minutes later for diff. |
/*
MINUTES LATER FOR DIFF
Description: When viewing an edit diff, shows how many minutes have passed from the old edit and the new one.
Only appears if the difference is less than an hour.
*/
function convertTimestampStringToDate(id)
{
var timestamp = $('#' + id).children().first().children().first().text();
timestamp = timestamp.substring('Revision as of '.length).match(/(\d\d):(\d\d), (\d{1,2}) ([A-Z][a-z]+) (\d{4})/);
return new Date(timestamp[4] + ' ' + timestamp[3] + ', ' + timestamp[5] + ' ' + timestamp[1] + ':' + timestamp[2] + ':00');
}
function minutesLaterForDiff()
{
if (!$('#mw-diff-otitle1').length || !$('#mw-diff-ntitle1').length) return false;
var leftNode = $('#mw-diff-otitle1');;
var rightNode = $('#mw-diff-ntitle1');
var firstDate = convertTimestampStringToDate('mw-diff-otitle1');
var secondDate = convertTimestampStringToDate('mw-diff-ntitle1');
var timeDifference = secondDate.getTime() - firstDate.getTime();
var minutesAgo = Math.round(timeDifference / 1000 / 60);
if (minutesAgo >= 60) return false;
else if (minutesAgo < 1) minutesAgo = 'Less than a minute later';
else if (minutesAgo == 1) minutesAgo = 'One minute later';
else minutesAgo = minutesAgo + ' minutes later';
leftNode.prepend($('<span> </span><br />'));
rightNode.prepend($('<span></span>').append(minutesAgo).append('<br />'));
}
$(minutesLaterForDiff);