Korisnik:Edinwiki/js/live-brojač-izmjena.js

S Wikipedije, slobodne enciklopedije

Napomena: Nakon što objavite izmjene, možda ćete morati osvježiti keš preglednika da biste vidjeli izmjene.

  • Firefox / Safari: Držite Shift i kliknite na Reload ili pritisnite Ctrl-F5 ili Ctrl-R (⌘-R na Macu)
  • Google Chrome: Pritisnite Ctrl-Shift-R (⌘-Shift-R na Macu)
  • Internet Explorer / Edge: Držite Ctrl i kliknite na Refresh ili pritisnite Ctrl-F5
  • Opera: Pritisnite Ctrl-F5.
// <pre>
// [[User:Henrik/js/live-edit-counter]] - Please include this line
// Adapted by: [[:bs:User:Edinwiki]]
function liveEditCounter(username) {
    var xhr;
    try {
		xhr = new XMLHttpRequest();
    }
    catch(e) {
      xhr = new ActiveXObject(Microsoft.XMLHTTP);
    }
    if (!document.getElementById('edit-count1') || !document.getElementById('edit-count2'))
        return;
 
    xhr.onreadystatechange  = function() {
		if (xhr.readyState  == 4) {
			if (xhr.status  == 200) {
				var doc = xhr.responseXML; 
				var element = doc.getElementsByTagName('user').item(0);
				var count = element.getAttribute("editcount");
				var intCount = parseInt(count);
				var color = '';
				var roundCount = 0;

				if (intCount < 10) {
					color = 'FF33FF';
				} else if (intCount < 25) {
					roundCount = 10;
					color = 'FFCCCC';
				} else if (intCount < 50) {
					roundCount = 25;
					color = '006600';
				} else if (intCount < 100) {
					roundCount = 50;
					color = '006600';
				} else if (intCount < 150) {
					roundCount = 100;
					color = '006600';
             	} else if (intCount < 200) {
					roundCount = 150;
					color = '006600';
             	} else if (intCount < 250) {
					roundCount = 200;
					color = '006600';
             	} else if (intCount < 300) {
					roundCount = 250;
					color = 'FF9933';
             	} else if (intCount < 400) {
					roundCount = 300;
					color = '007BA7';
             	} else if (intCount < 500) {
					roundCount = 400;
					color = '006600';
             	} else if (intCount < 600) {
					roundCount = 500;
					color = 'FF3333';
             	} else if (intCount < 700) {
					roundCount = 600;
					color = '3399FF';
             	} else if (intCount < 800) {
					roundCount = 700;
					color = '9900CC';
             	} else if (intCount < 900) {
					roundCount = 800;
					color = '6A5ACD';
             	} else if (intCount < 1000) {
					roundCount = 900;
					color = '006699';
             	} else if (intCount < 1100) {
					roundCount = 1000;
					color = 'FF3399';
             	} else if (intCount < 1200) {
					roundCount = 1100;
					color = '6A5ACD';
             	} else if (intCount < 1500) {
					roundCount = 1200;
					color = '678';
             	} else if (intCount < 2000) {
					roundCount = 1500;
					color = 'FF3300';
             	} else if (intCount < 2500) {
					roundCount = 2000;
					color = '006699';
             	} else if (intCount < 3000) {
					roundCount = 2500;
					color = '9900CC';
             	} else if (intCount < 3500) {
					roundCount = 3000;
					color = '3CC';
             	} else if (intCount < 4000) {
					roundCount = 3500;
					color = '1560BD';
             	} else if (intCount < 4500) {
					roundCount = 4000;
					color = '2E8B57';
             	} else if (intCount < 5000) {
					roundCount = 4500;
					color = 'FF0000';
             	} else if (intCount < 5500) {
					roundCount = 5000;
					color = '33F';
             	} else if (intCount < 6000) {
					roundCount = 5000;
					color = 'CCFFFF';
             	} else if (intCount < 7000) {
					roundCount = 6000;
					color = '6A5ACD';
             	} else if (intCount < 8000) {
					roundCount = 7000;
					color = 'ADD8E6';
             	} else if (intCount < 9000) {
					roundCount = 8000;
					color = '3399FF';
             	} else if (intCount < 10000) {
					roundCount = 9000;
					color = '808080';
             	} else if (intCount < 11000) {
					roundCount = 10000;
					color = '809080';
             	} else if (intCount < 12000) {
					roundCount = 11000;
					color = '33FFFF';
             	} else if (intCount < 13000) {
					roundCount = 12000;
					color = '0000FF';
             	} else if (intCount < 14000) {
             		roundCount = 13000;
					color = 'FF8888';
             	} else if (intCount < 15000) {
             		roundCount = 14000;
					color = 'FFFF00';
             	} else if (intCount < 16000) {
             		roundCount = 15000;
					color = '0000FF';
             	} else if (intCount < 17000) {
             		roundCount = 16000;
					color = '006600';
             	} else if (intCount < 18000) {
             		roundCount = 17000;
					color = '000066';
             	} else if (intCount < 19000) {
             		roundCount = 18000;
					color = 'FFCC33';
             	} else if (intCount < 20000) {
             		roundCount = 19000;
					color = '006600';
             	} else if (intCount < 21000) {
             		roundCount = 20000;
					color = '99FF33';
             	} else if (intCount < 22000) {
             		roundCount = 21000;
					color = 'DEB887';
             	} else if (intCount < 23000) {
             		roundCount = 22000;
					color = 'FFA07A';
             	} else if (intCount < 24000) {
             		roundCount = 23000;
					color = 'FFA07A';
             	} else if (intCount < 25000) {
             		roundCount = 24000;
					color = '000066';
             	} else if (intCount < 30000) {
             		roundCount = 25000;
					color = 'FFCC33';
             	} else if (intCount < 35000) {
             		roundCount = 30000;
					color = '33FF33';
             	} else if (intCount < 40000) {
             		roundCount = 35000;
					color = 'DDA0DD';
             	} else if (intCount < 45000) {
             		roundCount = 40000;
					color = 'FF00FF';
             	} else if (intCount < 50000) {
             		roundCount = 45000;
					color = 'DA70D6';
             	} else if (intCount < 55000) {
             		roundCount = 50000;
					color = 'EE82EE';
             	} else if (intCount < 60000) {
             		roundCount = 55000;
					color = 'EE82EE';
             	} else if (intCount < 65000) {
             		roundCount = 60000;
					color = 'EE82EE';
             	} else if (intCount < 70000) {
             		roundCount = 65000;
					color = 'EE82EE';
             	} else if (intCount < 75000) {
             		roundCount = 70000;
					color = 'EE82EE';
             	} else if (intCount < 80000) {
             		roundCount = 75000;
					color = 'EE82EE';
             	} else if (intCount < 85000) {
             		roundCount = 80000;
					color = 'EE82EE';
             	} else if (intCount < 90000) {
             		roundCount = 85000;
					color = 'EE82EE';
             	} else if (intCount < 95000) {
             		roundCount = 90000;
					color = 'EE82EE';
             	} else if (intCount < 100000) {
             		roundCount = 95000;
					color = 'EE82EE';
             	} else if (intCount >= 100000) {
             		roundCount = Math.floor(count/10000)*10000;
					color = '000';
             	}
             	
             	// zaokruženi brojevi
				document.getElementById('edit-count1').innerHTML=roundCount;
				document.getElementById('edit-count2').innerHTML=roundCount;
				
				// boja
				$('#edit-count1').closest('td').css('background', '#'+color);
				
			}
		}
	}; 
 
   xhr.open('GET', "//bs.wikipedia.org/w/api.php?action=query&list=users&ususers="+username+"&usprop=editcount&format=xml",  true); 
   xhr.send(null); 
} 
 
jQuery( document ).ready( function( $ ) {
  //if (wgTitle.indexOf("/") != -1 || document.title.indexOf("- Historija -") != -1)  //no subpages or history
  //   return;
  if (mw.config.get('wgCanonicalNamespace') == "User" || mw.config.get('wgCanonicalNamespace') == "User_talk") {
     var username = encodeURIComponent( mw.config.get('wgTitle') );
     liveEditCounter(username);
  }
});
//<pre>