MediaWiki:Common.js: Unterschied zwischen den Versionen
Erscheinungsbild
L (Diskussion | Beiträge) Lektoratsangabe erscheint automatisch auf allen Seiten der Kategorie Medikamente |
L (Diskussion | Beiträge) Lektoratsangabe: Kategorie auch in der mobilen Ansicht erkennen |
||
| Zeile 133: | Zeile 133: | ||
var haltbar = 60 * 60 * 1000; | var haltbar = 60 * 60 * 1000; | ||
if ( conf.wgNamespaceNumber !== 0 || conf.wgAction !== 'view' || !conf.wgIsArticle || conf.wgDiffNewId | if ( conf.wgNamespaceNumber !== 0 || conf.wgAction !== 'view' || !conf.wgIsArticle || conf.wgDiffNewId ) { | ||
return; | return; | ||
} | |||
/* Die mobile Ansicht liefert wgCategories nicht mit. Dort zählt die Kategorienzeile am Seitenende. */ | |||
function istMedikament() { | |||
if ( conf.wgCategories ) { | |||
return conf.wgCategories.indexOf( 'Medikamente' ) !== -1; | |||
} | |||
return $( '#catlinks a[title="Kategorie:Medikamente"]' ).length > 0; | |||
} | } | ||
| Zeile 147: | Zeile 154: | ||
} | } | ||
mw.hook( 'wikipage.content' ).add( function ( | mw.hook( 'wikipage.content' ).add( function () { | ||
var $ausgabe = $ | var $ausgabe = $( '#mw-content-text' ).find( '.mw-parser-output' ).first(); | ||
var gemerkt = null; | var gemerkt = null; | ||
if ( !$ausgabe.length || $ausgabe.find( '.lektorat, .kein-lektorat' ).length ) { | if ( !$ausgabe.length || !istMedikament() || $ausgabe.find( '.lektorat, .kein-lektorat' ).length ) { | ||
return; | return; | ||
} | } | ||
Aktuelle Version vom 6. Dezember 2026, 04:39 Uhr
/* Das folgende JavaScript wird für alle Benutzer geladen. */
jQuery( document ).ready(function() {
var name = jQuery('#firstHeading').text();
jQuery('#recentpages ul li strong').parent().hide();
});
/* Mobile Ansicht (MobileFrontend mit Vector 2022): Die Platzhalter verzögert geladener Bilder
werden sonst nie durch das Bild ersetzt. Hier werden sie in echte Bilder umgewandelt,
das verzögerte Laden übernimmt der Browser (loading="lazy"). */
( function () {
function ersetzeBildPlatzhalter( $content ) {
var root = ( $content && $content[ 0 ] ) || document;
var platzhalter = root.querySelectorAll( '.lazy-image-placeholder[data-src]' );
Array.prototype.forEach.call( platzhalter, function ( ph ) {
var img = document.createElement( 'img' );
var attr = { 'data-srcset': 'srcset', 'data-width': 'width', 'data-height': 'height', 'data-alt': 'alt', 'data-class': 'class', 'data-style': 'style' };
img.setAttribute( 'src', ph.getAttribute( 'data-src' ) );
Object.keys( attr ).forEach( function ( quelle ) {
var wert = ph.getAttribute( quelle );
if ( wert !== null ) {
img.setAttribute( attr[ quelle ], wert );
}
} );
if ( !img.hasAttribute( 'alt' ) ) {
img.setAttribute( 'alt', '' );
}
img.setAttribute( 'loading', 'lazy' );
img.setAttribute( 'decoding', 'async' );
ph.parentNode.replaceChild( img, ph );
} );
}
mw.hook( 'wikipage.content' ).add( ersetzeBildPlatzhalter );
}() );
/* Werbung: Google AdSense testet seit November 2026 „Ad intents“ und macht dabei Wörter im
Artikeltext zu Werbelinks (dazu Chips am Absatzende). In Bereichen mit der Klasse
google-anno-skip unterbleibt das, siehe https://support.google.com/adsense/answer/13844047.
Ausgenommen sind der Artikelbereich und der Banner oben. */
( function () {
function ohneWerbelinks() {
[ 'content', 'siteNotice' ].forEach( function ( id ) {
var el = document.getElementById( id );
if ( el ) {
el.classList.add( 'google-anno-skip' );
}
} );
}
ohneWerbelinks();
$( ohneWerbelinks );
}() );
/* ===== Hauptseite: neue Artikel und Artikelzahl aktuell halten =====
Besucher bekommen die Hauptseite aus dem Datei-Cache, also im Stand der letzten Änderung der Seite.
Dieses Skript holt die neuesten Artikel und die Artikelzahl frisch aus der API und tauscht beides aus.
Ohne JavaScript bleibt die Liste aus dem Wikitext stehen ({{Spezial:Neue Seiten}}). */
mw.loader.using( 'mediawiki.util' ).then( function () {
if ( !mw.config.get( 'wgIsMainPage' ) || mw.config.get( 'wgAction' ) !== 'view' ) {
return;
}
$( function () {
var box = document.querySelector( '.hpa-neu-auto' );
if ( !box || !window.fetch || !window.Intl ) {
return;
}
/* Anzahl wie im Wikitext eingestellt (data-anzahl), sonst so viele, wie schon in der Liste stehen */
var anzahl = parseInt( box.getAttribute( 'data-anzahl' ), 10 ) || box.querySelectorAll( 'li' ).length || 10;
var url = mw.util.wikiScript( 'api' ) + '?action=query&format=json&formatversion=2' +
'&list=recentchanges&rctype=new&rcnamespace=0&rcshow=!redirect&rcprop=title%7Ctimestamp&rclimit=' + anzahl +
'&meta=siteinfo&siprop=statistics&maxage=300&smaxage=300';
fetch( url ).then( function ( antwort ) {
return antwort.json();
} ).then( function ( daten ) {
var neu = ( daten.query && daten.query.recentchanges ) || [];
var statistik = daten.query && daten.query.statistics;
var zahl = document.querySelector( '.hpa-zahl-ziffer' );
if ( zahl && statistik && statistik.articles ) {
zahl.textContent = statistik.articles.toLocaleString( 'de-DE' );
}
if ( !neu.length ) {
return;
}
var alt = Array.prototype.map.call( box.querySelectorAll( '.mw-newpages-pagename' ), function ( a ) {
return a.textContent;
} ).join( '\n' );
var frisch = neu.map( function ( e ) {
return e.title;
} ).join( '\n' );
if ( alt === frisch ) {
return;
}
var datum = new Intl.DateTimeFormat( 'de-DE', { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'Europe/Berlin' } );
var teil = document.createDocumentFragment();
var tag = '';
var liste;
neu.forEach( function ( e ) {
var t = datum.format( new Date( e.timestamp ) );
if ( t !== tag ) {
tag = t;
var kopf = document.createElement( 'h4' );
kopf.className = 'mw-index-pager-list-header';
kopf.textContent = t;
teil.appendChild( kopf );
liste = document.createElement( 'ul' );
teil.appendChild( liste );
}
var li = document.createElement( 'li' );
var bdi = document.createElement( 'bdi' );
var a = document.createElement( 'a' );
a.className = 'mw-newpages-pagename';
a.href = mw.util.getUrl( e.title );
a.title = e.title;
a.textContent = e.title;
bdi.appendChild( a );
li.appendChild( bdi );
liste.appendChild( li );
} );
box.textContent = '';
box.appendChild( teil );
} ).catch( function () {} );
} );
} );
/* ===== Lektoratsangabe in Medikamentenartikeln =====
Jede Seite der Kategorie „Medikamente“ zeigt am Artikelanfang die Zeile aus Vorlage:Lektorat,
auch wenn die Vorlage (noch) nicht im Artikel steht. Der Text kommt immer aus der Vorlage
und wird hier nicht wiederholt. Ausnahme für einzelne Seiten: {{Lektorat|aus}} im Artikel. */
( function () {
var conf = mw.config.get( [ 'wgNamespaceNumber', 'wgAction', 'wgIsArticle', 'wgCategories', 'wgDiffNewId' ] );
var speicher = 'adhspedia-lektorat';
var haltbar = 60 * 60 * 1000;
if ( conf.wgNamespaceNumber !== 0 || conf.wgAction !== 'view' || !conf.wgIsArticle || conf.wgDiffNewId ) {
return;
}
/* Die mobile Ansicht liefert wgCategories nicht mit. Dort zählt die Kategorienzeile am Seitenende. */
function istMedikament() {
if ( conf.wgCategories ) {
return conf.wgCategories.indexOf( 'Medikamente' ) !== -1;
}
return $( '#catlinks a[title="Kategorie:Medikamente"]' ).length > 0;
}
function einsetzen( $ausgabe, html ) {
var $zeile = $( '<div>' ).append( $.parseHTML( html ) ).find( '.lektorat' ).first();
var $ziel = $ausgabe.children( 'section' ).first();
if ( !$zeile.length || $ausgabe.find( '.lektorat, .kein-lektorat' ).length ) {
return;
}
( $ziel.length ? $ziel : $ausgabe ).prepend( $zeile );
}
mw.hook( 'wikipage.content' ).add( function () {
var $ausgabe = $( '#mw-content-text' ).find( '.mw-parser-output' ).first();
var gemerkt = null;
if ( !$ausgabe.length || !istMedikament() || $ausgabe.find( '.lektorat, .kein-lektorat' ).length ) {
return;
}
try {
gemerkt = JSON.parse( window.sessionStorage.getItem( speicher ) || 'null' );
} catch ( e ) {}
if ( gemerkt && gemerkt.html && Date.now() - gemerkt.zeit < haltbar ) {
einsetzen( $ausgabe, gemerkt.html );
return;
}
mw.loader.using( 'mediawiki.api' ).then( function () {
return new mw.Api().get( {
action: 'parse',
text: '{{Lektorat}}',
contentmodel: 'wikitext',
prop: 'text',
wrapoutputclass: '',
disablelimitreport: 1,
formatversion: 2,
maxage: 3600,
smaxage: 3600
} );
} ).then( function ( daten ) {
var html = ( daten && daten.parse && daten.parse.text ) || '';
try {
window.sessionStorage.setItem( speicher, JSON.stringify( { html: html, zeit: Date.now() } ) );
} catch ( e ) {}
einsetzen( $ausgabe, html );
} );
} );
}() );