配置 Mediawiki UTCLiveClock 小工具
Configuring Mediawiki UTCLiveClock Gadget
我正在使用 MediaWiki 的 UTCLiveClock.js,我正在尝试将其配置为在 PST/PDT 中显示显示时间。我以为我解决了这个问题,但是当午夜 UTC 命中 (00:00:00) 时,它将我的时间输出更改为 0-7:00:00。我需要正确显示,以便在出现 UTC 00:00:00 - 07:00:00 时,我的时间显示看起来不会一团糟。我通过 mediawiki 使用的小工具可以在 https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.js
找到
是的,我是菜鸟。我没有任何正式的编程知识。我只是想为一个服务器存在于 PST/PDT 和 运行 的游戏构建一个 wiki 来解决这个问题。谷歌搜索过去 3 小时的关键字搜索让我一无所获。请帮忙。
*/
/*global mw, $, UTCLiveClockConfig:true */
mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.notify']).then( function () {
var $target;
function showTime( $target ) {
var now = new Date();
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 );
$target.text( time );
var ms = now.getUTCMilliseconds();
setTimeout( function () {
showTime( $target );
}, 1100 - ms );
}
function liveClock() {
mw.util.addCSS( '#utcdate a { font-weight:bolder; font-size:120%; }' );
if ( !window.UTCLiveClockConfig ) {
UTCLiveClockConfig = {};
}
var portletId = UTCLiveClockConfig.portletId || 'p-personal';
var nextNode = UTCLiveClockConfig.nextNodeId ? document.getElementById( UTCLiveClockConfig.nextNodeId ) : undefined;
var node = mw.util.addPortletLink(
portletId,
mw.util.getUrl( null, { action: 'purge' } ),
'',
'utcdate',
null,
null,
nextNode
);
if ( !node ) {
return;
}
$( node ).on( 'click', function ( e ) {
new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then( function () {
location.reload();
}, function () {
mw.notify( 'Purge failed', { type: 'error' } );
} );
e.preventDefault();
} );
showTime( $( node ).find( 'a:first' ) );
}
$( liveClock );
} );
编辑:
我最初解决问题的方法是在小时部分添加 -7:
var hh = now.getUTCHours()-7;
看起来这是一个非常简单的小工具,仅限于 UTC 时间。选项很少。
- 寻找更好的支持时区的脚本。
- 根据这个写自己的脚本。
要自己写脚本,关键是
function get_PST_PDT_offset() {
/* You have to rewrite this function from time to time. */
var now = new Date();
var change = new Date(2016, 11, 5, 19, 0); /* 2016-11-06 2:00 PST */
if (now >= change) {
return -8;
} else {
return -7;
}
}
function showTime( $target ) {
var now = new Date();
var hh = now.getUTCHours();
var offset = get_PST_PDT_offset();
hh = (hh + offset + 24) % 24;
var mm = now.getUTCMinutes();
/* ... */
我正在使用 MediaWiki 的 UTCLiveClock.js,我正在尝试将其配置为在 PST/PDT 中显示显示时间。我以为我解决了这个问题,但是当午夜 UTC 命中 (00:00:00) 时,它将我的时间输出更改为 0-7:00:00。我需要正确显示,以便在出现 UTC 00:00:00 - 07:00:00 时,我的时间显示看起来不会一团糟。我通过 mediawiki 使用的小工具可以在 https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.js
找到是的,我是菜鸟。我没有任何正式的编程知识。我只是想为一个服务器存在于 PST/PDT 和 运行 的游戏构建一个 wiki 来解决这个问题。谷歌搜索过去 3 小时的关键字搜索让我一无所获。请帮忙。
*/
/*global mw, $, UTCLiveClockConfig:true */
mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.notify']).then( function () {
var $target;
function showTime( $target ) {
var now = new Date();
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 );
$target.text( time );
var ms = now.getUTCMilliseconds();
setTimeout( function () {
showTime( $target );
}, 1100 - ms );
}
function liveClock() {
mw.util.addCSS( '#utcdate a { font-weight:bolder; font-size:120%; }' );
if ( !window.UTCLiveClockConfig ) {
UTCLiveClockConfig = {};
}
var portletId = UTCLiveClockConfig.portletId || 'p-personal';
var nextNode = UTCLiveClockConfig.nextNodeId ? document.getElementById( UTCLiveClockConfig.nextNodeId ) : undefined;
var node = mw.util.addPortletLink(
portletId,
mw.util.getUrl( null, { action: 'purge' } ),
'',
'utcdate',
null,
null,
nextNode
);
if ( !node ) {
return;
}
$( node ).on( 'click', function ( e ) {
new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then( function () {
location.reload();
}, function () {
mw.notify( 'Purge failed', { type: 'error' } );
} );
e.preventDefault();
} );
showTime( $( node ).find( 'a:first' ) );
}
$( liveClock );
} );
编辑:
我最初解决问题的方法是在小时部分添加 -7:
var hh = now.getUTCHours()-7;
看起来这是一个非常简单的小工具,仅限于 UTC 时间。选项很少。
- 寻找更好的支持时区的脚本。
- 根据这个写自己的脚本。
要自己写脚本,关键是
function get_PST_PDT_offset() {
/* You have to rewrite this function from time to time. */
var now = new Date();
var change = new Date(2016, 11, 5, 19, 0); /* 2016-11-06 2:00 PST */
if (now >= change) {
return -8;
} else {
return -7;
}
}
function showTime( $target ) {
var now = new Date();
var hh = now.getUTCHours();
var offset = get_PST_PDT_offset();
hh = (hh + offset + 24) % 24;
var mm = now.getUTCMinutes();
/* ... */