User:WhitePhosphorus/js/PagePatroller.js

/** * Showing patroller on the bottom of the page. * * @version 0.0 (2017-05-05) * @author User:WhitePhosphorus */

(function($, mw) {

'use strict';

if (mw.config.get('wgNamespaceNumber') < 0) return null;

var weekdays = ['日', '一', '二', '三', '四', '五', '六']; var $patroller = $('' + 	wgUVS('正在加载本页面的巡查者……', '正在加載本頁面的巡查者……') + ''); $('#footer-info').prepend($patroller);

$.ajax({	url: mw.util.wikiScript('api'),	data: {		action: 'query',		list: 'logevents',		letype: 'patrol',		letitle: mw.config.get('wgPageName'),		format: 'json'	} }).done(function (data) {	var user, ts, action, html = '';	if (data.query && data.query.logevents && data.query.logevents.length) {		var log = data.query.logevents[0];		user = log.user;		ts = log.timestamp;		action = log.action;		var date = new Date(ts);		ts = date.getUTCFullYear + '年' + (date.getUTCMonth+1) + '月' +			date.getUTCDate + '日 (' + weekdays[date.getDay] + ') ' +			('0'+date.getHours).slice(-2) + ':' +			('0'+date.getMinutes).slice(-2) + ' (UTC)';		var p = mw.config.get('wgArticlePath');		user = '' + user + '（' +			'' +			wgUVS('讨论', '討論') + '' + ' | ' +			'' + wgUVS('贡献', '貢獻') + '' + ' | ' + '' + '封禁' + '' + '）'; if (action === 'patrol') { html = wgUVS('本页面于', '本頁面於') + ts + '由' + user + '巡查. ';		} else if (action === 'autopatrol') { html = wgUVS('本页面于', '本頁面於') + ts + '由' + user + wgUVS('自动标为已巡查. ', '自動標爲已巡查'); }	}	if (html !== '') { $patroller.html(html); } else { $patroller.html(wgUVS('本页面尚未被巡查. ', '本頁面尚未被巡查. '));	} }).fail(function(jqXHR, textStatus, errorThrown) { console.log('Error when loading patroller: ' + errorThrown); $patroller.html(wgUVS('查找巡查者时出现错误. ', '查找巡查者時出現錯誤. ')); });

})(jQuery, mw);