User:Gary/mark todays edits.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/mark todays edits. |
/*
MARK TODAY'S EDITS
Description: Marks edits on contributions pages that were made today.
*/
if (typeof(unsafeWindow) != 'undefined')
{
mw = unsafeWindow.mw;
}
$(markTodaysEdits);
function markTodaysEdits()
{
if (!mw.config.get('wgPageName').match('Special:Contributions') && mw.config.get('wgAction') != 'history') return false;
var today = new Date();
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var firstMatchedNode, lastMatchedNode;
var maxTime = 1000 * 60 * 60 * 24;
$('#bodyContent ul:last').children().each(function()
{
var edit = $(this);
if (edit[0].nodeType == 3) return true;
if (edit.contents().length <= 3) edit = edit.children().first();
if (mw.config.get('wgPageName').match('Special:Contributions')) var date = new Date(edit.children().first().text());
else if (mw.config.get('wgAction') == 'history') var date = new Date(edit.children().eq(3).text());
// Revision's date is less than 24 hours
if ((today.getTime() - date.getTime()) < maxTime)
{
if (firstMatchedNode) lastMatchedNode = edit;
else firstMatchedNode = lastMatchedNode = edit;
}
});
if (firstMatchedNode && lastMatchedNode)
{
if (mw.config.get('wgPageName').match('Special:Contributions'))
{
firstMatchedNode = firstMatchedNode.children().first();
lastMatchedNode = lastMatchedNode.children().first();
}
else if (mw.config.get('wgAction') == 'history')
{
firstMatchedNode = firstMatchedNode.children().eq(3);
lastMatchedNode = lastMatchedNode.children().eq(3);
}
var firstColorRatio = calculateColorRatio(maxTime, 70, 95, new Date(firstMatchedNode.text()));
var lastColorRatio = calculateColorRatio(maxTime, 70, 95, new Date(lastMatchedNode.text()));
firstMatchedNode.css('background-color', 'rgb(' + firstColorRatio + '%, ' + firstColorRatio + '%, 100%)');
lastMatchedNode.css('background-color', 'rgb(' + lastColorRatio + '%, ' + lastColorRatio + '%, 100%)');
}
}
function calculateColorRatio(maxTime, minPercentage, maxPercentage, timestamp)
{
var today = new Date();
minPercentage = minPercentage / 100;
maxPercentage = maxPercentage / 100;
var colorRatio = ((maxPercentage - minPercentage) * (1 - (today.getTime() - timestamp.getTime()) / maxTime) + minPercentage) * 100;
if (colorRatio < minPercentage) colorRatio = minPercentage;
return colorRatio;
}