User:Frankou/Friendly/friendlyclock.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// If FriendlyConfig aint exist.
if( typeof( FriendlyConfig ) == 'undefined' ) {
FriendlyConfig = {};
}
/**
FriendlyConfig.enableClock ( boolean )
*/
if( typeof( FriendlyConfig.enableClock ) == 'undefined' ) {
FriendlyConfig.enableClock = true;
}
/**
FriendlyConfig.clockStyle ( String )
*/
if( typeof( FriendlyConfig.clockStyle ) == 'undefined' ) {
FriendlyConfig.clockStyle = 'dynamic';
}
/**
FriendlyConfig.clockLocal ( boolean )
*/
if( typeof( FriendlyConfig.clockLocal ) == 'undefined' ) {
FriendlyConfig.clockLocal = true;
}
friendlyclock = {
showClock: function() {
var query = {
'action': 'purge',
'title': wgPageName
};
friendlyclock.clockNode = mw.util.addPortletLink( 'p-personal', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( query ), '--:--:-- UTC', 'friendly-clock', 'Purge this page', '' );
friendlyclock.clockNode.style.fontSize = 'normal';
friendlyclock.clockNode.style.fontWeight = 'bold';
friendlyclock.clockNode.style.textTransform = 'uppercase';
friendlyclock.updateTime();
if( FriendlyConfig.clockStyle != 'static' ) {
friendlyclock.intervalId = window.setInterval(friendlyclock.updateTime, 1000);
}
},
updateTime: function() {
if( !friendlyclock.clockNode ) {
return;
}
var now = new Date();
if( FriendlyConfig.clockLocal ) {
var hh = now.getHours();
var mm = now.getMinutes();
var ss = now.getSeconds();
var time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss) + ' Local';
}
else {
var hh = now.getUTCHours();
var mm = now.getUTCMinutes();
var ss = now.getUTCSeconds();
var time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss) + ' UTC';
}
friendlyclock.clockNode.firstChild.innerHTML = time;
}
}
$( function() {
if( FriendlyConfig.enableClock ) {
friendlyclock.showClock();
}
}
);