User:Rp2006/LiveEditCounter.js

// Based on User:UBX/LiveEditCounter.js //Attempting to fix issue with count only being displayed to owner of User page who must be logged-in.

function liveEditCounter(Rp2006) { if (!document.getElementById('edit-count-id') || !document.getElementById('edit-count-info')) return; var count=""; {       var xhr; try { xhr = new XMLHttpRequest; } catch(e) { xhr = new ActiveXObject("Oops"); }

xhr.onreadystatechange = function { if(xhr.readyState == 4) { if(xhr.status == 200) { var doc = xhr.responseXML; count = doc.getElementsByTagName(Rp2006)[0].getAttribute('editcount'); }           }        };

xhr.open('GET', "http://en.wikipedia.org/w/api.php?action=query&list=users&usprop=editcount&format=xml&ususers="+"Rp2006", 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) $('#edit-count-id').text(count); // Update "icon" $('#edit-count-info').text(count); // Update text }

$(function { liveEditCounter(Rp2006); } );