<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://compusofia.com/w/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AGadget-UTCLiveClock.js</id>
	<title>MediaWiki:Gadget-UTCLiveClock.js - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://compusofia.com/w/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AGadget-UTCLiveClock.js"/>
	<link rel="alternate" type="text/html" href="https://compusofia.com/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&amp;action=history"/>
	<updated>2026-04-26T07:51:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://compusofia.com/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&amp;diff=1865&amp;oldid=prev</id>
		<title>Majestix: 1 revision imported: Initial Setup</title>
		<link rel="alternate" type="text/html" href="https://compusofia.com/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&amp;diff=1865&amp;oldid=prev"/>
		<updated>2026-04-09T08:49:44Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported: Initial Setup&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 10:49, 9 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikiNonStop:diff:1.41:old-1864:rev-1865 --&gt;
&lt;/table&gt;</summary>
		<author><name>Majestix</name></author>
	</entry>
	<entry>
		<id>https://compusofia.com/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&amp;diff=1864&amp;oldid=prev</id>
		<title>en&gt;Pppery: Add ampm per request on talk</title>
		<link rel="alternate" type="text/html" href="https://compusofia.com/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&amp;diff=1864&amp;oldid=prev"/>
		<updated>2025-12-26T05:53:13Z</updated>

		<summary type="html">&lt;p&gt;Add ampm per request on talk&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;/**&lt;br /&gt;
 * Warning! Global gadget file!&lt;br /&gt;
 * &lt;br /&gt;
 * This gadget adds a clock in the personal toolbar that shows the current time&lt;br /&gt;
 * in UTC (or a different timezone of your choosing), and also provides a link&lt;br /&gt;
 * to purge the current page.&lt;br /&gt;
 *&lt;br /&gt;
 * Source: https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.js&lt;br /&gt;
 *&lt;br /&gt;
 * Installation:&lt;br /&gt;
 * &lt;br /&gt;
 * 1. Copy the JS page at https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.js&lt;br /&gt;
 * to the page [[MediaWiki:Gadget-UTCLiveClock.js]] on your wiki.&lt;br /&gt;
 * &lt;br /&gt;
 * 2. Copy the CSS page at https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.css&lt;br /&gt;
 * to the page [[MediaWiki:Gadget-UTCLiveClock.css]] on your wiki.&lt;br /&gt;
 * &lt;br /&gt;
 * 3. Copy the CSS page at https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock-pagestyles.css&lt;br /&gt;
 * to the page [[MediaWiki:Gadget-UTCLiveClock-pagestyles.css]] on your wiki.&lt;br /&gt;
 * &lt;br /&gt;
 * 4. Add a description of the gadget to the page [[MediaWiki:Gadget-UTCLiveClock]]&lt;br /&gt;
 * on your wiki. You can use https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock&lt;br /&gt;
 * as a template.&lt;br /&gt;
 * &lt;br /&gt;
 * 5. Add the following code to your wiki&amp;#039;s [[MediaWiki:Gadgets-definition]]:&lt;br /&gt;
 * &lt;br /&gt;
 *     * UTCLiveClock[ResourceLoader|type=general|dependencies=mediawiki.util,mediawiki.api,user|peers=UTCLiveClock-pagestyles]|UTCLiveClock.js|UTCLiveClock.css&lt;br /&gt;
 *     * UTCLiveClock-pagestyles[hidden|skins=vector,monobook]|UTCLiveClock-pagestyles.css&lt;br /&gt;
 * &lt;br /&gt;
 * &lt;br /&gt;
 * To set the timezone used to one other than UTC, set window.LiveClockTimeZone to&lt;br /&gt;
 * the desired timezone. For example, adding the following to your common.js&lt;br /&gt;
 *      window.LiveClockTimeZone = &amp;#039;America/Los_Angeles&amp;#039;;&lt;br /&gt;
 * would result in the local time in Los Angeles being shown. See&lt;br /&gt;
 * [[:w:List of tz database time zones]] for valid options (use the TZ database name).&lt;br /&gt;
 * &lt;br /&gt;
 * If you find a seconds counter distracting, set:&lt;br /&gt;
 *		window.LiveClockHideSeconds = true;&lt;br /&gt;
  * To display the clock in AM/PM format set:&lt;br /&gt;
 *		window.LiveClockAMPM = true;&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
mw.loader.using( [&amp;#039;mediawiki.util&amp;#039;, &amp;#039;mediawiki.api&amp;#039;, &amp;#039;user&amp;#039;] ).then( function () {&lt;br /&gt;
&lt;br /&gt;
function padWithZeroes( num ) {&lt;br /&gt;
	// Pad a number with zeroes. The number must be an integer where&lt;br /&gt;
	// 0 &amp;lt;= num &amp;lt; 100.&lt;br /&gt;
	return num &amp;lt; 10 ? &amp;#039;0&amp;#039; + num.toString() : num.toString(); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function showTime( $target ) {&lt;br /&gt;
	var now = new Date();&lt;br /&gt;
	&lt;br /&gt;
	var timezone = window.LiveClockTimeZone || &amp;#039;UTC&amp;#039;;&lt;br /&gt;
	var hideSeconds = window.LiveClockHideSeconds || false;&lt;br /&gt;
	var ampm =  window.LiveClockAMPM || false;&lt;br /&gt;
&lt;br /&gt;
	// Set the time.&lt;br /&gt;
	var hh, mm, ss;&lt;br /&gt;
	if ( timezone === &amp;quot;UTC&amp;quot; ) {&lt;br /&gt;
		hh = now.getUTCHours();&lt;br /&gt;
		mm = now.getUTCMinutes();&lt;br /&gt;
		ss = now.getUTCSeconds();&lt;br /&gt;
	} else if ( timezone === &amp;quot;local&amp;quot; ) {&lt;br /&gt;
		hh = now.getHours();&lt;br /&gt;
		mm = now.getMinutes();&lt;br /&gt;
		ss = now.getSeconds();&lt;br /&gt;
	} else {&lt;br /&gt;
		var newNow;&lt;br /&gt;
		try {&lt;br /&gt;
			newNow = new Date(&lt;br /&gt;
				now.toLocaleString(&lt;br /&gt;
					&amp;quot;en-US&amp;quot;,&lt;br /&gt;
					{ timeZone: timezone }&lt;br /&gt;
				)&lt;br /&gt;
			);&lt;br /&gt;
			hh = newNow.getHours();&lt;br /&gt;
			mm = newNow.getMinutes();&lt;br /&gt;
			ss = newNow.getSeconds();&lt;br /&gt;
		} catch ( err ) {&lt;br /&gt;
			console.log( &amp;quot;LiveClock - error creating Date object with timezone &amp;#039;&amp;quot; + timezone + &amp;quot;&amp;#039;: &amp;quot; + err.name);&lt;br /&gt;
			timezone = &amp;quot;UTC&amp;quot;;&lt;br /&gt;
			newNow = now;&lt;br /&gt;
			hh = now.getUTCHours();&lt;br /&gt;
			mm = now.getUTCMinutes();&lt;br /&gt;
			ss = now.getUTCSeconds();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	var time;&lt;br /&gt;
    if ( ampm ) {&lt;br /&gt;
		const suffix = hh &amp;gt;= 12 ? &amp;#039;PM&amp;#039; : &amp;#039;AM&amp;#039;;&lt;br /&gt;
		const hour12 = hh % 12 || 12; // Convert 0 to 12 for midnight&lt;br /&gt;
&lt;br /&gt;
		if ( hideSeconds ) {&lt;br /&gt;
			time = `${hour12}:${ padWithZeroes( mm )} ${suffix}`;&lt;br /&gt;
		} else {&lt;br /&gt;
			time = `${hour12}:${ padWithZeroes( mm )}:${ padWithZeroes( ss )} ${suffix}`;&lt;br /&gt;
		}&lt;br /&gt;
	} else if ( hideSeconds ) {&lt;br /&gt;
		time = `${hh}:${ padWithZeroes( mm )}`;&lt;br /&gt;
	} else {&lt;br /&gt;
		time = `${hh}:${ padWithZeroes( mm )}:${ padWithZeroes( ss )}`;&lt;br /&gt;
	}&lt;br /&gt;
	$target.text( time );&lt;br /&gt;
&lt;br /&gt;
	// Schedule the next time change.&lt;br /&gt;
	// &lt;br /&gt;
	// We schedule the change for 100 ms _after_ the next clock tick. The delay&lt;br /&gt;
	// from setTimeout is not precise, and if we aim exactly for the tick, there&lt;br /&gt;
	// is a chance that the function will run slightly before it. If this&lt;br /&gt;
	// happens, we will display the same time for two seconds in a row - not&lt;br /&gt;
	// good. By scheduling 100 ms after the tick, we will always be about 100 ms&lt;br /&gt;
	// late, but we are also very likely to display a new time every second.&lt;br /&gt;
	var ms = now.getUTCMilliseconds();&lt;br /&gt;
	setTimeout( function () {&lt;br /&gt;
		showTime( $target );&lt;br /&gt;
	}, 1100 - ms );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function liveClock() {&lt;br /&gt;
	// Set CSS styles. We do this here instead of on the CSS page because some&lt;br /&gt;
	// wikis load this page directly, without loading the accompanying CSS.&lt;br /&gt;
	mw.util.addCSS( &amp;#039;#utcdate a { font-weight:bolder; font-size:120%; }&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
	// Reset whitespace that was set in the peer CSS gadget; this prevents the&lt;br /&gt;
	// effect of the p-personal menu jumping to the left when the JavaScript&lt;br /&gt;
	// loads.&lt;br /&gt;
	$( &amp;#039;.client-js &amp;gt; body.skin-vector #p-personal ul&amp;#039; ).css( &amp;#039;margin-right&amp;#039;, &amp;#039;initial&amp;#039; );&lt;br /&gt;
	$( &amp;#039;.client-js &amp;gt; body.skin-monobook #p-personal ul&amp;#039; ).css( &amp;#039;margin-right&amp;#039;, &amp;#039;initial&amp;#039; );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// We are experimenting with different locations for this in Vector 2022 based on feedback&lt;br /&gt;
	// so currently this is limited to MediaWiki.org&lt;br /&gt;
	var location = window.UTCLiveClockLocation || &amp;#039;inside&amp;#039;;&lt;br /&gt;
	var showOutsideDropdown = location === &amp;#039;outside&amp;#039;;&lt;br /&gt;
	var clockLocation = document.getElementById( &amp;#039;p-vector-user-menu-overflow&amp;#039; ) &amp;amp;&amp;amp; showOutsideDropdown ?&lt;br /&gt;
		&amp;#039;p-vector-user-menu-overflow&amp;#039; : &amp;#039;p-personal&amp;#039;;&lt;br /&gt;
	addLiveClockInstance( clockLocation );&lt;br /&gt;
	addLiveClockInstance( &amp;#039;p-personal-sticky-header&amp;#039; );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function addLiveClockInstance( clockLocation ) {&lt;br /&gt;
	// Add the portlet link.&lt;br /&gt;
	var node = mw.util.addPortletLink(&lt;br /&gt;
		clockLocation,&lt;br /&gt;
		mw.util.getUrl( null, { action: &amp;#039;purge&amp;#039; } ),&lt;br /&gt;
		&amp;#039;&amp;#039;,&lt;br /&gt;
		&amp;#039;utcdate&amp;#039;&lt;br /&gt;
	);&lt;br /&gt;
	if ( !node ) {&lt;br /&gt;
		return;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// Purge the page when the clock is clicked. We have to do this through the&lt;br /&gt;
	// API, as purge URLs now make people click through a confirmation screen.&lt;br /&gt;
	$( node ).on( &amp;#039;click&amp;#039;, function ( e ) {&lt;br /&gt;
		new mw.Api({userAgent: &amp;#039;Gadget-UTCLiveClock/2025&amp;#039;}).post( { action: &amp;#039;purge&amp;#039;, titles: mw.config.get( &amp;#039;wgPageName&amp;#039; ) } ).then( function () {&lt;br /&gt;
			location.reload();&lt;br /&gt;
		}, function () {&lt;br /&gt;
			mw.notify( &amp;#039;Purge failed&amp;#039;, { type: &amp;#039;error&amp;#039; } );&lt;br /&gt;
		} );&lt;br /&gt;
		e.preventDefault();&lt;br /&gt;
	} );&lt;br /&gt;
&lt;br /&gt;
	// Show the clock.&lt;br /&gt;
	showTime( $( node ).find( &amp;#039;a&amp;#039; ).first() );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$( liveClock );&lt;br /&gt;
} );&lt;/div&gt;</summary>
		<author><name>en&gt;Pppery</name></author>
	</entry>
</feed>