Медијавики:Gadget-LocalLiveClock.js — разлика између измена
Изглед
м 1 измена увезена |
Promena koda |
||
| Ред 1: | Ред 1: | ||
mw.loader. | mw.loader.using( [ 'mediawiki.util', 'jquery' ] ).then( function () { | ||
function pad2( n ) { return ( n < 10 ? '0' : '' ) + n; } | |||
function formatTime( d ) { | |||
return pad2(d.getHours()) + ':' + pad2(d.getMinutes()) + ':' + pad2(d.getSeconds()); | |||
} | |||
function insertClock() { | |||
// Vector/MonoBook/Legacy: personal portlet | |||
var $ul = $('#p-personal ul'); | |||
// Vector 2022 fallback: still usually has #p-personal, but just in case | |||
if ( !$ul.length ) { | |||
$ul = $('#p-personal').find('ul').first(); | |||
} | |||
// If still not found, put it in the top header area | |||
if ( !$ul.length ) { | |||
$ul = $('#mw-head').find('ul').first(); | |||
} | |||
if ( !$ul.length ) { | |||
return; // nowhere to insert | |||
} | |||
// Avoid duplicates | |||
if ( $('#pt-local-live-clock').length ) { | |||
return; | |||
} | |||
var $li = $('<li>', { id: 'pt-local-live-clock' }); | |||
var $span = $('<span>', { | |||
id: 'local-live-clock', | |||
css: { 'padding-left': '8px', 'font-weight': 'bold' }, | |||
text: formatTime(new Date()) | |||
}); | |||
$li.append( $span ); | |||
$ul.append( $li ); | |||
// Update every second | |||
setInterval( function () { | |||
$('#local-live-clock').text( formatTime(new Date()) ); | |||
}, 1000 ); | |||
} | |||
$( insertClock ); | |||
} ); | |||
Тренутна верзија на датум 7. фебруар 2026. у 00:04
mw.loader.using( [ 'mediawiki.util', 'jquery' ] ).then( function () {
function pad2( n ) { return ( n < 10 ? '0' : '' ) + n; }
function formatTime( d ) {
return pad2(d.getHours()) + ':' + pad2(d.getMinutes()) + ':' + pad2(d.getSeconds());
}
function insertClock() {
// Vector/MonoBook/Legacy: personal portlet
var $ul = $('#p-personal ul');
// Vector 2022 fallback: still usually has #p-personal, but just in case
if ( !$ul.length ) {
$ul = $('#p-personal').find('ul').first();
}
// If still not found, put it in the top header area
if ( !$ul.length ) {
$ul = $('#mw-head').find('ul').first();
}
if ( !$ul.length ) {
return; // nowhere to insert
}
// Avoid duplicates
if ( $('#pt-local-live-clock').length ) {
return;
}
var $li = $('<li>', { id: 'pt-local-live-clock' });
var $span = $('<span>', {
id: 'local-live-clock',
css: { 'padding-left': '8px', 'font-weight': 'bold' },
text: formatTime(new Date())
});
$li.append( $span );
$ul.append( $li );
// Update every second
setInterval( function () {
$('#local-live-clock').text( formatTime(new Date()) );
}, 1000 );
}
$( insertClock );
} );