MediaWiki:Monobook.js: Difference between revisions

no edit summary
mNo edit summary
No edit summary
 
Line 8: Line 8:
  * by Patrick Westerhoff [poke]
  * by Patrick Westerhoff [poke]
  */
  */
addOnloadHook(function ()
$(document).ready(function ()
{
{
  if ( typeof( timerDisplay ) !== 'undefined' && timerDisplay === false )
    if ( typeof( timerDisplay ) !== 'undefined' && timerDisplay === false )
    return;
        return;
 
 
  var date;
    var date;
  var timerParent = document.getElementById( 'p-personal' ).getElementsByTagName( 'ul' )[0];
    var timerParent = document.getElementById( 'p-personal' ).getElementsByTagName( 'ul' )[0];
  var timerLink  = document.createElement( 'a' );
    var timerLink  = document.createElement( 'a' );
  var timerObj    = document.createElement( 'li' );
    var timerObj    = document.createElement( 'li' );
  timerLink.href              = '/wiki/' + wgPageName + '?action=purge';
    timerLink.href              = '/wiki/' + mw.config.get("wgPageName") + '?action=purge';
  timerLink.title              = 'Purge the server cache and update the contents of this page.'
    timerLink.title              = 'Purge the server cache and update the contents of this page.'
  timerObj.id                  = 'pt-timer';
    timerObj.id                  = 'pt-timer';
  timerObj.style.textTransform = 'none';
    timerObj.style.textTransform = 'none';
  timerObj.style.fontWeight    = 'bold';
    timerObj.style.fontWeight    = 'bold';
  timerObj.style.fontSize      = '100%';
    timerObj.style.fontSize      = '100%';
  timerObj.appendChild( timerLink );
    timerObj.appendChild( timerLink );
  timerParent.insertBefore( timerObj, timerParent.firstChild );
    timerParent.insertBefore( timerObj, timerParent.firstChild );
 
 
  function actualizeUTC ()
    function actualizeUTC ()
  {
    {
    timerDate          = new Date();
        timerDate          = new Date();
    timerLink.innerHTML = ( timerDate.getUTCHours()  < 10 ? '0' : '' ) + timerDate.getUTCHours()  + ':'
        timerLink.innerHTML = ( timerDate.getUTCHours()  < 10 ? '0' : '' ) + timerDate.getUTCHours()  + ':'
                        + ( timerDate.getUTCMinutes() < 10 ? '0' : '' ) + timerDate.getUTCMinutes() + ':'
            + ( timerDate.getUTCMinutes() < 10 ? '0' : '' ) + timerDate.getUTCMinutes() + ':'
                        + ( timerDate.getUTCSeconds() < 10 ? '0' : '' ) + timerDate.getUTCSeconds() + ' (UTC)';
            + ( timerDate.getUTCSeconds() < 10 ? '0' : '' ) + timerDate.getUTCSeconds() + ' (UTC)';
  }
    }
 
 
  function actualizeCustom ()
    function actualizeCustom ()
  {
    {
    timerDate          = new Date();
        timerDate          = new Date();
    timerDate.setMinutes( timerDate.getMinutes() + timerDate.getTimezoneOffset() + timerTimezone * 60 );
        timerDate.setMinutes( timerDate.getMinutes() + timerDate.getTimezoneOffset() + timerTimezone * 60 );
    timerLink.innerHTML = ( timerDate.getHours()  < 10 ? '0' : '' ) + timerDate.getHours()  + ':'
        timerLink.innerHTML = ( timerDate.getHours()  < 10 ? '0' : '' ) + timerDate.getHours()  + ':'
                        + ( timerDate.getMinutes() < 10 ? '0' : '' ) + timerDate.getMinutes() + ':'
            + ( timerDate.getMinutes() < 10 ? '0' : '' ) + timerDate.getMinutes() + ':'
                        + ( timerDate.getSeconds() < 10 ? '0' : '' ) + timerDate.getSeconds()
            + ( timerDate.getSeconds() < 10 ? '0' : '' ) + timerDate.getSeconds()
                        + ' (UTC' + ( timerTimezone < 0 ? '' : '+' ) + timerTimezone + ')';
            + ' (UTC' + ( timerTimezone < 0 ? '' : '+' ) + timerTimezone + ')';
  }
    }
 
 
  // start
    // start
  if ( typeof( timerTimezone ) !== 'number' )
    if ( typeof( timerTimezone ) !== 'number' )
  {
    {
    actualizeUTC();
        actualizeUTC();
    setInterval( actualizeUTC, 1000 );
        setInterval( actualizeUTC, 1000 );
  }
    }
  else
    else
  {
    {
    actualizeCustom();
        actualizeCustom();
    setInterval( actualizeCustom, 1000 );
        setInterval( actualizeCustom, 1000 );
  }
    }
});
});
/*</nowiki>*/
/*</nowiki>*/