打开主菜单
首页
随机
登录
设置
关于Akarin
免责声明
Akarin
搜索
查看“MediaWiki:Gadget-UTCP8LiveClock.js”的源代码
←
MediaWiki:Gadget-UTCP8LiveClock.js
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
此页提供此wiki软件的界面文字,并受到保护以防止滥用。如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
/** * Warning! Global gadget file! * * This gadget adds a clock in the personal toolbar that shows the current time * in UTC+8, and also provides a link to purge the current page. * * Based on Gadget-UTCLiveClock.js (revision November 2017) with tweaks to get UTC+8 time * Revision: June 2020 * Original Source: https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.js * * Still require other dependencies as UTCLiveClock; not designed to run cocurrently with UTCLiveClock. */ /*global mw, $ */ mw.loader.using( ['mediawiki.util', 'mediawiki.api'] ).then( function () { function padWithZeroes( num ) { // Pad a number with zeroes. The number must be an integer where // 0 <= num < 100. return num < 10 ? '0' + num.toString() : num.toString(); } function showTime( $target ) { var now = new Date(); // Set the time. var hh = (now.getUTCHours() + 8); while(hh > 24) {hh -= 24;} var mm = now.getUTCMinutes(); var ss = now.getUTCSeconds(); var time = padWithZeroes( hh ) + ':' + padWithZeroes( mm ) + ':' + padWithZeroes( ss ) + ' UTC+8'; $target.text( time ); // Schedule the next time change. // // We schedule the change for 100 ms _after_ the next clock tick. The delay // from setTimeout is not precise, and if we aim exactly for the tick, there // is a chance that the function will run slightly before it. If this // happens, we will display the same time for two seconds in a row - not // good. By scheduling 100 ms after the tick, we will always be about 100 ms // late, but we are also very likely to display a new time every second. var ms = now.getUTCMilliseconds(); setTimeout( function () { showTime( $target ); }, 1100 - ms ); } function liveClock() { // Set CSS styles. We do this here instead of on the CSS page because some // wikis load this page directly, without loading the accompanying CSS. mw.util.addCSS( '#utcdate { width: 6.8em; }' ); mw.util.addCSS( '#utcdate a { font-weight:bolder; }' ); // Reset whitespace that was set in the peer CSS gadget; this prevents the // effect of the p-personal menu jumping to the left when the JavaScript // loads. $( '.client-js > body.skin-vector #p-personal ul' ).css( 'margin-right', 'initial' ); $( '.client-js > body.skin-monobook #p-personal ul' ).css( 'margin-right', 'initial' ); // Add the portlet link. var node = mw.util.addPortletLink( 'p-personal', mw.util.getUrl( null, { action: 'purge' } ), '', 'utcdate' ); if ( !node ) { return; } // Purge the page when the clock is clicked. We have to do this through the // API, as purge URLs now make people click through a confirmation screen. $( node ).on( 'click', function ( e ) { new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then( function () { location.reload(); }, function () { mw.notify( '刷新失败', { type: 'error' } ); } ); e.preventDefault(); } ); // Show the clock. showTime( $( node ).find( 'a:first' ) ); } $( liveClock ); } );
返回至
MediaWiki:Gadget-UTCP8LiveClock.js
。