Користувач:Krupski Oleg/seen.js
Перейти до навігації
Перейти до пошуку
Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.
- Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
- Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
- Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5.
// Autor: [[pl:User:Beau]]
var seenGadget = {
version: 2,
init: function() {
if ( mw.config.get( 'wgNamespaceNumber' ) != 2 && mw.config.get( 'wgNamespaceNumber' ) != 3 ) {
return;
}
if ( mw.util.getParamValue('printable') == 'yes' ) {
return;
}
this.username = mw.config.get( 'wgTitle' ).replace(/\/.*$/, '');
var that = this;
var request = {
action: 'query',
list: 'usercontribs',
ucuser: this.username,
ucdir: 'older',
uclimit: 1,
ucprop: 'timestamp',
format: 'json',
requestid: new Date().getTime()
};
jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function(result) {
jQuery(document).ready(function() {
if (result) {
that.showResults(result);
}
});
});
},
padZeros: function(number, length) {
number = new String(number);
while (number.length < length) {
number = "0" + number;
}
return number;
},
formatDate: function(timestamp) {
var date = new Date();
date.setTime(timestamp);
return this.padZeros(date.getFullYear(), 4) + '-' +
this.padZeros(date.getMonth() + 1, 2) + '-' +
this.padZeros(date.getDate(), 2) + ' ' +
this.padZeros(date.getHours(), 2) + ':' +
this.padZeros(date.getMinutes(), 2) + ':' +
this.padZeros(date.getSeconds(), 2);
},
showResults: function(data) {
data = data.query.usercontribs[0];
if (!data || data.user != this.username)
return;
var firstHeading;
var headers = document.getElementsByTagName( 'h1' );
for ( var i = 0; i < headers.length; i++ ) {
var header = headers[i];
if(header.className == "firstHeading" || header.id == "firstHeading" || header.className == "pagetitle") {
firstHeading = header; break;
}
}
if( !firstHeading ) {
firstHeading = document.getElementById("section-0");
}
if( !firstHeading ) {
return;
}
var html = 'Цей користувач';
var timestamp;
var utc = Date.parse(data.timestamp);
if (isNaN(utc)) {
timestamp = data.timestamp;
}
else {
timestamp = this.formatDate(utc);
}
html += ' останнє редагування виконав ' + timestamp + '.';
var div = document.createElement("div");
div.style.cssText = "font-size:0.5em;line-height:1em";
div.className = 'plainlinks';
div.innerHTML = html;
if ( mw.config.get( 'skin' ) == 'modern' ) {
div.style.marginLeft = "10px";
div.style.display = "inline-block";
}
firstHeading.appendChild(div);
}
};
seenGadget.init();