Jump to content

User:Novem Linguae/Scripts/NotSoFast.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Novem Linguae (talk | contribs) at 08:10, 10 July 2021 (debug). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <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 = $(obj).html().trim();
			let timestamp = Date.parse(dateTimeString)/1000;
			if ( timestamp > fifteenMinutesAgo ) {
				console.log("Within 15 minutes");
			} 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>