„MediaWiki:Common.js” változatai közötti eltérés

Palotasb (vitalap | szerkesztései)
a -)
Palotasb (vitalap | szerkesztései)
fájlok utolsó módosítási idejének megjelenítése
948. sor: 948. sor:


// GOOGLE ANALYTICS VÉGE
// GOOGLE ANALYTICS VÉGE
// ===============================================================================================
// FÁJLOK UTOLSÓ MÓDOSÍTÁSI IDEJÉNEK MEGJELENÍTÉSE
(function ($, mw) {
var filelinks = $('a[href^="/images"]');
var batchsize = 50;
var prefix = 'Fájl:'
var fileurls = [[]];
var datenotecss = {
    'font-size': 'x-small',
    'color': '#555',
    'padding-left': '3px'
};
var datenotelinkcss = {
    'color': '#555'
};
$('.datenote').remove();
filelinks.each( function ( index, elem ) {
    if ( fileurls[ fileurls.length - 1 ].length > batchsize)
        fileurls.push( [] );
       
    fileurls[ fileurls.length - 1 ].push(
        decodeURIComponent($(elem).prop('href').replace( /.*\// , prefix ))
    );
} );
var getelapsedtime = function(sec) {
    if ( sec < 60 )
        return 'most';
    if ( sec / 60 < 60)
        return Math.round(sec * 60).toString() + ' perce';
    if ( sec / 3600 < 24 )
        return Math.round(sec / 3600).toString() + ' órája';
    if ( sec / (3600 * 24) < 7 )
        return Math.round(sec / (3600 * 24)).toString() + ' napja';
    if ( sec / (3600 * 24 * 7) < 6 )
        return Math.round(sec / (3600 * 24 * 7)).toString() + ' hete';
    return Math.round(sec / (3600 * 24 * 30)).toString() + ' hónapja';
};
var addfiledate = function(filename, date) {
    var links = filelinks.filter(function(index) {
        if (mw.config.values.wgNamespaceNumber == 6)
            return false;
        return ($(this).prop('href').replace( /.*\//, '') == filename);
    });
   
    var d = new Date(date);
    var now = new Date();
    var diff = Math.floor((now.getTime() - d.getTime()) / 1000);
   
    var datenote = $(document.createElement('SUP'));
    var datenotelink = $(document.createElement('A'));
    datenote.addClass('datenote');
    datenote.prop('title', 'Ennyi ideje volt feltöltve vagy utoljára módosítva a fájl (' + decodeURIComponent(filename.replace(/_/g, ' ')) + ')');
    datenote.css(datenotecss);
    datenotelink.text(getelapsedtime(diff));
    datenotelink.prop('href', '/Fájl:' + filename);
    datenotelink.css(datenotelinkcss);
    datenote.append('[');
    datenote.append(datenotelink);
    datenote.append(']');
    links.after(datenote);
};
var getDenormalizedFilename = function (normalizedName, normalizationTable) {
    for ( var i = 0; i != normalizationTable.length; i++ ) {
        var f = normalizationTable[ i ];
        if ( f.to == normalizedName )
            return encodeURIComponent(f.from.replace( /.*:/ , ''));
    }
    return encodeURIComponent(normalizedName.replace( /.*:/ , ''));
};
var ajaxcallback = function(res, status, xhr) {
    for ( var prop in res.query.pages ) {
        addfiledate(
            getDenormalizedFilename( res.query.pages[ prop ].title, res.query.normalized),
            res.query.pages[ prop ].touched
        );
    }
};
var ajaxSettings = {
    url: '/api.php',
    type: 'post',
    success: ajaxcallback,
    dataType: 'json',
    data: {
        action: 'query',
        format: 'json',
        prop: 'info',
        titles: '',
    }
};
for ( var i = 0; i != fileurls.length; i++ ) {
    var batchsettings = ajaxSettings;
    batchsettings.data.titles = fileurls[ i ].join('|');
    $.ajax(batchsettings);
}
}).call(window, jQuery, mediaWiki);
// Fájlok utoldó módosítási idejének megjelenítése -- vége
A lap eredeti címe: „https://vik.wiki/MediaWiki:Common.js