MediaWiki:InactiveUsers/code.js
Revision as of 15:27, 24 September 2018 by >HexUseMe (Created page with "/** * InactiveUsers * * documentation at: https://dev.wikia.com/wiki/InactiveUsers * © Peter Coester, 2012 * * continued as UserTags: https://dev.wikia.com/wiki/UserTa...")
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/** * InactiveUsers * * documentation at: https://dev.wikia.com/wiki/InactiveUsers * © Peter Coester, 2012 * * continued as UserTags: https://dev.wikia.com/wiki/UserTags */ /*jshint curly:false laxbreak:true es5:true jquery:true */ (function (module, $, mw) { 'use strict'; if (!$('#UserProfileMasthead').exists() || window.InactiveUsersLoaded) { return; } window.InactiveUsersLoaded = true; // Polyfill for ECMAScript 5 function (so it works in older browsers) if (!Date.prototype.toISOString) Date.prototype.toISOString = function() { function pad(s) { return (s += '').length < 2 ? '0' + s : s; } return this.getUTCFullYear() + '-' + pad(this.getUTCMonth() + 1) + '-' + pad(this.getUTCDate()) + 'T' + pad(this.getUTCHours()) + ':' + pad(this.getUTCMinutes()) + ':' + pad(this.getUTCSeconds()) + '.' + (this.getUTCMilliseconds() / 1000).toFixed(3).substr(-3) + 'Z'; }; function isoDateNDaysAgo(days) { return new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString(); } function labelAsInactive() { var $container = $('#UserProfileMasthead hgroup'), css = $container.find('.tag').length ? { marginLeft: '10px' } : {}; $container.append( $('<span>', { 'class': 'tag inactive-user', 'css': css, text: module.text }) ); mw.hook('dev.inactiveusers').fire(); } module = $.extend({ text: 'inactive', gone: [], months: 1 }, module); var user = $('#UserProfileMasthead h1[itemprop="name"]').text(); if (module.gone.indexOf(user) === -1) { mw.loader.using('mediawiki.api').then(function() { new mw.Api().get({ action: 'query', list: 'usercontribs', uclimit: 1, ucprop: 'title|timestamp', ucuser: user, ucstart: isoDateNDaysAgo(0), ucend: isoDateNDaysAgo(30 * Math.max(parseInt(module.months, 10) || 1, 1)) }).done(function(result) { if ( result && result.query && result.query.usercontribs && !result.query.usercontribs.length ) { labelAsInactive(); } }); }); } else { labelAsInactive(); } } (window.InactiveUsers = window.InactiveUsers || {}, jQuery, mediaWiki));