User:Shizhao/talktips.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
//文档见[[User:Shizhao/talktips]]
mw.loader.using( 'mediawiki.Title','mw.Api' ).then( function () {
var t = new mw.Title(mw.config.get('wgPageName'));
//排除用户及用户对话页
if (t.canHaveTalkPage() && (![2,3].includes(mw.config.get('wgNamespaceNumber')))) {
talk_title = mw.Title.makeTitle( t.getTalkPage().namespace,t.getTalkPage().title).getPrefixedText();
//console.log( talk_title );
var api = new mw.Api();
api.get( {
action: 'parse',
page: talk_title,
prop: 'sections'
} ).done( function ( data ) {
//console.log('sections');
//章节数
talk_n = data.parse.sections.length;
//console.log( data.parse.sections.length );
txt = $("<b></b>").text("("+talk_n+")");
$("li#ca-talk>a>span").append(txt);
//获取对话页最新修订版的修订时间
var timeapi = new mw.Api();
timeapi.get( {
action: 'query',
titles: talk_title,
prop: 'revisions',
rvlimit: 1,
rvprop: 'timestamp'
} ).done( function ( data ) {
d = data.query.pages;
//最新修订时间与当前时间的差
var delta = Date.now() - Date.parse(d[Object.keys(d)[0]].revisions[0].timestamp);
//console.log( d[Object.keys(d)[0]].revisions[0].timestamp );
//console.log( delta );
if (delta <= (60*60*24*1000*7)){
$("li#ca-talk>a>span").css("background-color","var(--background-color-error-subtle)");
} else if ((delta > (60*60*24*1000*7)) && (delta <= (60*60*24*1000*30) )){
$("li#ca-talk>a>span").css("background-color","var(--background-color-warning-subtle)");
}
});
} );
}
});