MediaWiki:Common.js
Página de la interfaz de MediaWiki
Más acciones
Nota: Después de publicar, quizás necesite actualizar la caché de su navegador para ver los cambios.
- Firefox/Safari: Mantenga presionada la tecla Shift mientras pulsa el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
- Google Chrome: presione Ctrl+Shift+R (⌘+Shift+R en Mac)
- Edge: mantenga presionada Ctrl mientras pulsa Actualizar, o presione Ctrl+F5
/* MundoConan Wiki — JavaScript para todos los usuarios */
/* Portada: últimos temas del foro (feed Atom de phpBB, mismo dominio) */
( function () {
var caja = document.getElementById( 'mc-foro-feed' );
if ( !caja || !window.fetch || !window.DOMParser ) {
return;
}
function hace( fecha ) {
var s = Math.floor( ( Date.now() - fecha.getTime() ) / 1000 );
if ( s < 3600 ) {
return 'hace ' + Math.max( 1, Math.floor( s / 60 ) ) + ' min';
}
if ( s < 86400 ) {
return 'hace ' + Math.floor( s / 3600 ) + ' h';
}
if ( s < 86400 * 30 ) {
var d = Math.floor( s / 86400 );
return 'hace ' + d + ( d === 1 ? ' día' : ' días' );
}
return fecha.toLocaleDateString( 'es-ES' );
}
fetch( '/foro/app.php/feed/topics', { credentials: 'omit' } )
.then( function ( r ) {
return r.ok ? r.text() : Promise.reject( r.status );
} )
.then( function ( xml ) {
var doc = new DOMParser().parseFromString( xml, 'application/xml' );
var entradas = Array.prototype.slice.call( doc.getElementsByTagName( 'entry' ), 0, 6 );
caja.textContent = '';
if ( !entradas.length ) {
caja.textContent = 'Aún no hay temas en el foro. ¡Abre el primero!';
return;
}
var ul = document.createElement( 'ul' );
entradas.forEach( function ( e ) {
var titulo = ( e.getElementsByTagName( 'title' )[ 0 ] || {} ).textContent || '';
var enlace = e.getElementsByTagName( 'link' )[ 0 ];
var autor = e.querySelector( 'author name' );
var fecha = e.getElementsByTagName( 'published' )[ 0 ] || e.getElementsByTagName( 'updated' )[ 0 ];
var seccion = '';
if ( titulo.indexOf( ' • ' ) !== -1 ) {
seccion = titulo.split( ' • ' )[ 0 ];
titulo = titulo.split( ' • ' ).slice( 1 ).join( ' • ' );
}
var href = enlace ? enlace.getAttribute( 'href' ) : '/foro/';
// Solo enlaces del propio sitio
if ( !/^https:\/\/wiki\.mundoconan\.com\/foro\//.test( href ) ) {
href = '/foro/';
}
var li = document.createElement( 'li' );
var a = document.createElement( 'a' );
a.className = 'mc-foro__tema';
a.href = href;
a.textContent = titulo;
li.appendChild( a );
var meta = document.createElement( 'span' );
meta.className = 'mc-foro__meta';
var partes = [];
if ( seccion ) {
partes.push( seccion );
}
if ( autor ) {
partes.push( autor.textContent );
}
if ( fecha ) {
partes.push( hace( new Date( fecha.textContent ) ) );
}
meta.textContent = partes.join( ' · ' );
li.appendChild( meta );
ul.appendChild( li );
} );
caja.appendChild( ul );
} )
.catch( function () {
caja.textContent = 'No se pudo cargar el foro ahora mismo.';
} );
}() );