User:WhitePhosphorus/js/PagePatroller.js: Difference between revisions
Content added Content deleted
mNo edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
* Showing patroller on the bottom of the page. |
* Showing patroller on the bottom of the page. |
||
* |
* |
||
* @version 0. |
* @version 0.1 (2017-05-06) |
||
* @author [[User:WhitePhosphorus]] |
* @author [[User:WhitePhosphorus]] |
||
*/ |
*/ |
||
(function($, mw) { |
(function($, mw) { |
||
wgUVS = function(a, b) { |
|||
return a; |
|||
}; |
|||
'use strict'; |
'use strict'; |
||
Line 26: | Line 22: | ||
data: { |
data: { |
||
action: 'query', |
action: 'query', |
||
titles: mw.config.get('wgPageName'), |
|||
prop: 'revisions', |
|||
rvprop: 'timestamp', |
|||
rvlimit: 1, |
|||
rvdir: 'newer', |
|||
list: 'logevents', |
list: 'logevents', |
||
letype: 'patrol', |
letype: 'patrol', |
||
Line 32: | Line 33: | ||
} |
} |
||
}).done(function (data) { |
}).done(function (data) { |
||
var user, ts, action, html = ''; |
var user, ts, cts, action, html = ''; |
||
if (data.query && data.query.logevents && data.query.logevents.length) { |
if (data.query && data.query.logevents && data.query.logevents.length) { |
||
var log = data.query.logevents[0]; |
var log = data.query.logevents[0]; |
||
Line 39: | Line 40: | ||
action = log.action; |
action = log.action; |
||
var date = new Date(ts); |
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; |
|||
} |
|||
} |
|||
} |
|||
ts = date.getUTCFullYear() + '年' + (date.getUTCMonth()+1) + '月' + |
ts = date.getUTCFullYear() + '年' + (date.getUTCMonth()+1) + '月' + |
||
date.getUTCDate() + '日 (' + weekdays[date.getDay()] + ') ' + |
date.getUTCDate() + '日 (' + weekdays[date.getDay()] + ') ' + |
||
Line 51: | Line 61: | ||
'<a href="' + p.replace('$1', 'Special:BlockUser/' + user) + '">' + |
'<a href="' + p.replace('$1', 'Special:BlockUser/' + user) + '">' + |
||
'封禁' + '</a>' + ')'; |
'封禁' + '</a>' + ')'; |
||
if ( |
if (cts && new Date(cts) > ts) { |
||
html = ''; |
|||
} else if (action === 'patrol') { |
|||
html = wgUVS('本页面于', '本頁面於') + ts + '由' + user + '巡查。'; |
html = wgUVS('本页面于', '本頁面於') + ts + '由' + user + '巡查。'; |
||
} else if (action === 'autopatrol') { |
} else if (action === 'autopatrol') { |