User:ZhaoFJx/common.js

mw.loader.load('https://cdn.jsdelivr.net/npm/wikiplus-core');/*Wikiplus*/ mw.loader.load('https://cdn.jsdelivr.net/npm/wikiplus-highlight');/*Wikiplus Highlight*/ mw.loader.load('https://www.mediawiki.org/w/index.php?title=XTools/ArticleInfo.js&action=raw&ctype=text/javascript'); /* XTools */ /** * Showing patroller on the bottom of the page. * * @version 0.1 (2017-05-06) * @author User:WhitePhosphorus */

(function($, mw) { mw.loader.using('ext.gadget.site-lib').then(function {

'use strict';

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

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

// 针对有巡查权限的用户优化，如果页面上能看到巡查按钮，那一定没被巡查过. if ($('.patrollink').length) { $patroller.html(wgUVS('本页面尚未被巡查. ', '本頁面尚未被巡查. '));	return null; }

$.ajax({	url: mw.util.wikiScript('api'),	data: {		action: 'query',		titles: mw.config.get('wgPageName'),		prop: 'revisions',		rvprop: 'timestamp',		rvlimit: 1,		rvdir: 'newer',		list: 'logevents',		letype: 'patrol',		letitle: mw.config.get('wgPageName'),		format: 'json'	} }).done(function (data) {	var user, ts, cts, 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);		if (data.query.pages) {			for (var id in data.query.pages) {				var page = data.query.pages[id];				if (page && page.revisions && page.revisions.length) {					cts = page.revisions[0].timestamp;					break;				}			}		}		if (cts && new Date(cts) > date) {			html = ;		} else {			ts = date.getUTCFullYear + '年' + (date.getUTCMonth+1) + '月' +				date.getUTCDate + '日 (' + weekdays[date.getUTCDay] + ') ' + ('0'+date.getUTCHours).slice(-2) + ':' + ('0'+date.getUTCMinutes).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);