Pengguna:Yassiramry/LiveEditCounter.js
Catatan: Setelah menyimpan, Anda harus memintas tembolok (cache) peramban Anda untuk melihat perubahannya. Google Chrome, Firefox, Microsoft Edge dan Safari: Tahan tombol ⇧ Shift dan klik Muat ulang (Reload) di tombol bilah alat. Untuk detail dan instruksi tentang peramban lain, lihat halaman menghapus singgahan (Inggris).
// Based on [[en:W:User:Henrik/js/live-edit-counter]], improved by [[en:W:User/UBX]]
function liveEditCounter(username)
{
if (!document.getElementById('edit-count-id') || !document.getElementById('edit-count-info'))
return;
var count="";
if (mw.config.get('wgUserName') == mw.config.get('wgTitle')) // If a user is viewing their own page, the data has already been loaded, no need to make a XHR
{
count = mw.config.get('wgUserEditCount');
}
else
{
var xhr;
try { xhr = new XMLHttpRequest(); }
catch(e)
{
xhr = new ActiveXObject(Microsoft.XMLHTTP);
}
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200) {
var doc = xhr.responseXML;
count = doc.getElementsByTagName('user')[0].getAttribute('editcount')
}
}
};
xhr.open('GET', "http://wiki-indonesia.club/w/api.php?action=query&list=users&usprop=editcount&format=xml&ususers="+username, true);
xhr.send(null);
}
if(!count) count="0"; // Cater to zero edit counts
count = (count+'').replace(/(?=(?:\d{3})+$)(?!^)/g, ','); // Add commas as thousand separators (hat tip to http://jsperf.com/number-format)
document.getElementById('edit-count-id').innerHTML=count; // Update "icon"
document.getElementById('edit-count-info').innerHTML=count; // Update text
}
$(function() {
if ($.inArray(mw.config.get('wgCanonicalNamespace'), ["User" , "User_talk"]) !== -1) {
var username = encodeURIComponent( mw.config.get('wgTitle').split("/")[0] );
liveEditCounter(username);
}
});