미디어위키:UTCLiveClock.js: 두 판 사이의 차이

모든 지식의 총합을 위한 자유지식위키, 리프위키
잔글 (판 1개를 가져왔습니다: 소도구 적용)
잔글편집 요약 없음
 
1번째 줄: 1번째 줄:
mw.loader.load( '//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400' );
/**
* Warning! Global gadget file!
*
* Usage:
*
*    mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&action=raw&ctype=text/javascript');
*
*/
/*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 );
} );

2017년 7월 8일 (토) 21:30 기준 최신판

/**
 * Warning! Global gadget file!
 *
 * Usage:
 *
 *     mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&action=raw&ctype=text/javascript');
 *
 */
/*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 );
} );