User:Novem Linguae/Scripts/NotSoFast.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. |
![]() | This user script seems to have a documentation page at User:Novem Linguae/Scripts/NotSoFast. |
// <nowiki>
/*
In [[Special:NewPagesFeed]], this script highlights articles newer than 15 minutes RED, and articles newer than 1 hour YELLOW. This is to remind you not to patrol those articles yet. [[WP:NPP]] says that articles should not be patrolled until at least 15 minutes have elapsed. This is to give the writer time to work on the article without getting CSD tagged, maintenance tagged, edit conflicted, etc.
*/
$(function() {
function getArticleName() {
// returns the pagename, including the namespace name, but with spaces replaced by underscores
return mw.config.get('wgPageName');
}
function checkAndHighlight(obj) {
$(obj).find('.mwe-pt-creation-date').each(function(i) {
let dateTimeString = $(this).html().trim();
let timestamp = Date.parse(dateTimeString)/1000;
if ( timestamp > fifteenMinutesAgo ) {
$(this).css("background-color", "#F79C8F");
} else if ( timestamp > oneHourAgo ) {
$(this).css("background-color", "#F5F591");
}
});
}
function inAFCMode() {
return $('#mwe-pt-radio-afc').is(':checked');
}
let title = getArticleName();
if ( title != 'Special:NewPagesFeed' ) return;
let currentTimestamp = Math.floor(Date.now() / 1000);
let fifteenMinutesAgo = currentTimestamp - 60*15;
let oneHourAgo = currentTimestamp - 60*60;
// run it once in case the NPP applet loaded BEFORE this script (race condition)
$('.mwe-pt-list-item').each(function() {
if ( ! inAFCMode() ) {
checkAndHighlight(this);
}
});
// then run it again whenever a DOM node is inserted (the list refreshes as you scroll down, so this can be anytime you scroll down). could also be because this script loads BEFORE the the NPP applet (race condition)
$('body').on('DOMNodeInserted', '.mwe-pt-list-item', function() {
if ( ! inAFCMode() ) {
checkAndHighlight(this);
}
});
});
// </nowiki>