Note: After saving, you have to
bypass your browser's cache to see the changes.
Internet Explorer: press
Ctrl-F5 ,
Mozilla: hold down
Shift while clicking
Reload (or press
Ctrl-Shift-R ),
Opera/Konqueror: press
F5 ,
Safari: hold down
Shift + Alt while clicking
Reload ,
Chrome: hold down
Shift while clicking
Reload .
//<nowiki>
var colors = [ '#FFFFFF' , '#C6ECAE' , '#94C9A9' , '#AEECEF' , '#18d2db' , '#69abd1' ];
$ ( document ). ready ( function () {
if ( mw . config . get ( 'wgNamespaceNumber' ) == 14 ){
for ( var i = 0 ; i < $ ( '.galleryfilename' ). length ; i ++ ) {
colorFile ( $ ( '.galleryfilename' )[ i ]. innerText );
}
}
});
function colorFile ( filename ){
var params = { 'titles' : 'File:' + filename , 'action' : 'query' , 'format' : 'json' , 'prop' : 'categories|imageinfo' , 'clshow' : '!hidden' , 'iiprop' : 'extmetadata' };
$ . getJSON ( 'https://commons.wikimedia.org/w/api.php' , params ). done ( function ( data ) {
data = data . query . pages [ Object . keys ( data . query . pages )[ 0 ]];
var title = data . title . replace ( 'File:' , '' );
var image = $ ( $ ( "div.gallerytext:contains(\"" + title + "\")" )[ 0 ]);
var color ;
if ( typeof data . categories === 'undefined' ){
color = '#DCDCDC' ; //grey
}
else if ( data . categories . length > colors . length ){
color = '#7b84d4' ;
}
else {
color = colors [ data . categories . length - 1 ];
}
image . css ( "background-color" , color );
if ( typeof data . imageinfo !== 'undefined' ) {
var pubDate = document . createElement ( "p" );
var t = document . createTextNode ( getSafe (() => data . imageinfo [ 0 ][ 'extmetadata' ][ 'DateTimeOriginal' ][ 'value' ], "" ). replace ( /<.+>/g , "" ));
pubDate . appendChild ( t );
image . append ( pubDate );
}
});
}
function getSafe ( fn , defaultVal ) {
try {
return fn ();
} catch ( e ) {
return defaultVal ;
}
}
//</nowiki>