MediaWiki:WikiInfo.js

/** * @name           WikiInfo * @description    Provides wiki information from user inputs * @author         KhangND */ (function {   var targetClass = '.wi';

if(window.WikiStatsLoaded|| !$(targetClass).length) { // load protections // return; } window.WikiStatsLoaded = true;

var id = mw.config.get('wgCityId'), apiURL = 'https://community.fandom.com/api/v1', alias = { creation_date: 'created', founding_user_id: 'founder', wam_score: 'wam' };

function formatDate(dateString, format) { if(!format || !/dd|mm|yyyy/g.test(format)) return '';

var date = new Date(dateString); const month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; format = format.indexOf('mmm') >= 0 ? format.replace('mmm', month[date.getUTCMonth]) : format.replace('mm',               date.getUTCMonth < 10                    ? '0' + (date.getUTCMonth + 1)                    : date.getUTCMonth + 1                ); date = format .replace('yyyy', date.getUTCFullYear) .replace('dd', date.getUTCDate); return date; }

$.get(apiURL + '/Wikis/Details', {       ids: id    }).done(function(data){        var items = data.items[id];        $(targetClass).each(function { var info = $(this).attr('class').split(/\s/g)[1]; for(var a in alias) { if(info === alias[a]) { $(this).text(                       $(this).data('formatdate') && info === 'created'                            ? formatDate(items[a], $(this).data('formatdate'))                            : items[a]                        ); return; }           }            $(this).text(items[info] || items.stats[info] || ''); });   }); });