更改

跳转至: 导航搜索

Widget:TimeSinceLastEdit

添加2,507字节, 2017年1月16日 (一) 15:35
创建页面,内容为“<noinclude>仅供{{tl|TimeSinceLastEdit}}使用</noinclude><includeonly><!--{if !isset($wgTimeSinceLastEdit) || !$wgTimeSinceLastEdit}--><!--{assign var="wgTimeSince...”
<noinclude>仅供{{tl|TimeSinceLastEdit}}使用</noinclude><includeonly><!--{if !isset($wgTimeSinceLastEdit) || !$wgTimeSinceLastEdit}--><!--{assign var="wgTimeSinceLastEdit" value=true scope="global"}--><script>
window.RLQ = window.RLQ || [];
window.RLQ.push(function(){
mw.loader.implement("widgetTimeSinceLastEdit",function($, jQuery){
window.setInterval(function() {
$('.lastEditTime').each(function() {
var lastEditTime = Math.floor(new Date().getTime() / 1000) - +this.dataset.lastEditTime + 8 * 60 * 60; //mw返回的是UTC……
var year = Math.floor(lastEditTime / 365 / 24 / 60 / 60); //这里js有个奇怪的bug:parseInt(1 / 365 / 24 / 60 / 60) === 3;所以我选择Math.floor
lastEditTime %= 365 * 24 * 60 * 60;
var month = Math.floor(lastEditTime / 30 / 24 / 60 / 60);
lastEditTime %= 30 * 24 * 60 * 60;
var day = Math.floor(lastEditTime / 24 / 60 / 60);
lastEditTime %= 24 * 60 * 60;
var hour = Math.floor(lastEditTime / 60 / 60);
lastEditTime %= 60 * 60;
var minute = Math.floor(lastEditTime / 60);
var second = lastEditTime % 60;
var html = '';
/* jshint ignore:start *///不给我hack一下……
switch (true) {
case !!year:
html += complement(year) + '年';
case !!month:
html += complement(month) + '月';
case !!day:
html += complement(day) + '日';
case !!hour:
html += complement(hour) + '时';
case !!minute:
html += complement(minute) + '分';
case !!second:
html += complement(second) + '秒';
}
/* jshint ignore:end */
if (!html) html = '0秒';
$(this).html(html);
});
}, 1000);
//辅助函数
function complement(n, l) {
if(!l) l = 2;
n += '';
if (n.length >= l) return n;
var b = '<span style="speak:none;visibility:hidden;color:transparent;">',
c = '';
while (l > (n + c).length) c += '0';
return b + c + '</span>' + n;
}
});
});</script><!--{/if}--></includeonly>
1,819
个编辑

导航菜单