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]], alert you if an article was created within the last 15 minutes. This is so while new page patrolling, you can comply with the rule that you're not supposed to mess with people's articles until 15 minutes after they are created, as those folks may still be working on them.
*/
mw.loader.using('mediawiki.storage').then(function () {
mw.storage.session.set( 'client-error-opt-out', '1' );
});
$(function() {
function getArticleName() {
// returns the pagename, including the namespace name, but with spaces replaced by underscores
return mw.config.get('wgPageName');
}
function runScript(obj) {
$(obj).find('.mwe-pt-creation-date').each(function(i) {
let dateTimeString = $(this).html().trim();
let timestamp = Date.parse(dateTimeString)/1000;
if ( timestamp > fifteenMinutesAgo ) {
console.log("Within 15 minutes");
$(this).style("background-color: red !important;");
} else {
console.log("Not within 15 minutes");
}
});
}
let title = getArticleName();
if ( title != 'Special:NewPagesFeed' ) return;
// TODO: if drafts rather than articles selected as filter, return
let currentTimestamp = Math.floor(Date.now() / 1000);
let fifteenMinutesAgo = currentTimestamp - 60*15;
// run it once in case the NPP applet loaded BEFORE this script
$('.mwe-pt-list-item').each(function() {
console.log('$ running');
runScript(this);
});
// then run it again whenever a DOM node is inserted (the list refreshes as yous croll down, so this can be anytime you scroll down)
$('body').on('DOMNodeInserted', '.mwe-pt-list-item', function() {
console.log('DOM node inserted running');
runScript(this);
});
});
// </nowiki>