VOOZH about

URL: https://minecraft.wiki/w/MediaWiki:Gadget-discussions.js

⇱ MediaWiki:Gadget-discussions.js – Minecraft Wiki


MediaWiki:Gadget-discussions.js

From Minecraft Wiki
Jump to navigation Jump to search
In other languages

Note: After saving, you have to bypass your browser's cache to see the changes.

Google Chrome, Firefox, Microsoft Edge, and Safari: Hold down the key and click the Reload toolbar button.
For details and instructions about other browsers, see Wikipedia:Bypass your cache.

mw.loader.using('mediawiki.DateFormatter').then(require=>{
if(!$('body').hasClass('ext-discussiontools-visualenhancements-enabled'))return;
constDateFormatter=require('mediawiki.DateFormatter');
consti18n={
en:{
now:'just now',
timezone:' ($1)'
},
de:{
now:'gerade eben'
},
zh:{
timezone:'($1)'
}
};
constlang=mw.config.get('wgUserLanguage');
constgetTranslation=key=>i18n[lang]&&i18n[lang][key]||i18n.en[key];
constinterval=60*1000;// 1 minute
functionconvertTimestampToDate(timestampStr,timestampLink){
// If the content language is English, we can use a straightforward method for getting the date
if(lang=='en'){
timestampStr=timestampStr.replace('(UTC)','UTC').replace(',','');
returnnewDate(timestampStr);
}
// Otherwise, try to parse from the link to this comment
// New DiscussionTools timestamp format: YYYYMMDDhhmmss
lettimestamp=timestampLink.match(
/-(?<year>20\d{2})(?<month>[0-1]\d)(?<day>[0-3]\d)(?<hour>[0-2]\d)(?<min>[0-5]\d)(?<sec>[0-5]\d)(?:-|$)/
);
if(timestamp!=null)returnnewDate(Date.UTC(
timestamp.groups.year,
timestamp.groups.month-1,
timestamp.groups.day,
timestamp.groups.hour,
timestamp.groups.min,
timestamp.groups.sec,
));
// Old DiscussionTools timestamp format: YYYY-MM-DDThh:mm:ss.uuuuZ (aka ISO date)
timestamp=timestampLink.match(
/-((?<year>20\d{2})-(?<month>[0-1]\d)-(?<day>[0-3]\d)T(?<hour>[0-2]\d):(?<min>[0-5]\d):(?<sec>[0-5]\d).(?<ms>\d{3}Z))(?:-|$)/
);
if(timestamp!=null)returnnewDate(timestamp[1]);
returnnull;
}
functionupdateTimestamps(){
$('.ext-discussiontools-init-timestamplink').each((i,e)=>{
const$e=$(e);
if(!$e.attr('data-time')){
consttimestampLink=$e.attr('href');
constdate=convertTimestampToDate(e.innerText,timestampLink);
if(date==null)return;
$e.attr('data-time',date.toISOString());
}
/* TODO: enable switching of relative/absolute time (tooltip<->html) via theme settings */
constdate=newDate($e.attr('data-time'));
letrelativeDate=DateFormatter.formatRelativeTimeOrDate(date);
if(newDate()-date<interval){
relativeDate=getTranslation('now');
}
constformatter=DateFormatter.forUser();
$(e).attr('title',relativeDate)
.text(formatter.formatTimeAndDate(date)
+getTranslation('timezone').replace('$1',formatter.getShortZoneName(date))
);
});
}
setInterval(updateTimestamps,interval);
updateTimestamps();
});
Retrieved from "https://minecraft.wiki/w/MediaWiki:Gadget-discussions.js?oldid=3503714"

Navigation menu