Melding:Gadget-show-bot-activity.js

Úr Wikipediu, frjálsa alfræðiritinu

Athugaðu: Eftir útgáfu kann að vera að þú þurfir að komast hjá skyndiminni vafrans þíns til að sjá breytingarnar.

  • Firefox / Safari: Haltu Shift samtímis og þú smellir á Endurhlaða (Reload), eða ýttu á annaðhvort Ctrl-F5 eða Ctrl-R (⌘-R á Mac)
  • Google Chrome: Ýttu á Ctrl-Shift-R (⌘-Shift-R á Mac)
  • Internet Explorer / Edge: Haltu Ctrl samtímis og þú smellir á Endurnýja (Refresh), eða ýttu á Ctrl-F5
  • Opera: Farðu í Verkfæri (Tools) → Stillingar (Preferences) og svo Friðhelgi og öryggi (Privacy & security) → Hreinsa vafragögn (Clear browsing data) → Myndir og skrár í skyndiminni (Chached images and files)
//
// This is a big nasty javascript which does a *lot* of callbacks. It will do numberofbots calls...
//
// By [[:no:Bruker:Stigmj]] - 2008
//
Date.prototype.setISO8601 = function (string) {
	var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
        "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
        "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
	var d = string.match(new RegExp(regexp));
 
	var offset = 0;
	var date = new Date(d[1], 0, 1);
 
	if (d[3]) { date.setMonth(d[3] - 1); }
	if (d[5]) { date.setDate(d[5]); }
	if (d[7]) { date.setHours(d[7]); }
	if (d[8]) { date.setMinutes(d[8]); }
	if (d[10]) { date.setSeconds(d[10]); }
	if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
	if (d[14]) {
		offset = (Number(d[16]) * 60) + Number(d[17]);
		offset *= ((d[15] == '-') ? 1 : -1);
	}
 
	offset -= date.getTimezoneOffset();
	time = (Number(date) + (offset * 60 * 1000));
	this.setTime(Number(time));
}

function getBotList() {
	var docobj = document.getElementById('bodyContent') || document.getElementById('mw_contentholder') || document.getElementById('content') || document.getElementsByTagName('body')[0]
	var numa = $(docobj).find( 'span.bot-activity' );
	if(numa.length > 0) {
		for(var i=0;i<numa.length;i++) {
			var username = _getTextB(numa[i]);
			numa[i].style.display = 'block';
			_remTextB(numa[i]);
			username = username.replace(/\s*(=|\(.*?\))\s*/g, '');
			processAllBots(eval('({"query":{"allusers":[{"name":"'+username+'"}]},"special":{"search":{"name":"'+username+'"}}})'));
		}
	}
	if (mw.config.get( 'wgPageName' ) == 'Wikipedia:Vélmenni/Staða') {
		var query = { action:'query', format:'json', 'continue': '' };
		var data = $.extend({}, query, { list:'allusers', augroup:'bot', aulimit:500})
		$.getJSON( mw.util.wikiScript( 'api' ), data, processAllBots );
	}
}
 
function _getTextB(obj) {
	if(obj.nodeType == 3) return obj.nodeValue;
	var txt = [];
	var i = 0;
	while(obj.childNodes[i]) {
		txt[txt.length] = _getTextB(obj.childNodes[i]);
		i++;
	}
	return txt.join('');
}

function _remTextB(obj) {
	while(obj.firstChild) obj.removeChild(obj.firstChild)
}

function processAllBots(obj) {
	// Get the bodyContent-container to construct the table
	var docobj = document.getElementById('bodyContent') || document.getElementById('mw_contentholder');
	if (obj['special']) {
		var searchName = obj['special']['search']['name'].replace(/\s/g, '_');
		docobj = document.getElementById('bot-activity-'+searchName);
	}
	if (obj['query'] && docobj) {
		var header = new Array('Nafn','Síðasta breyting','Fjarlægja vélmennaréttindi','Spjallsíða');
		var types = new Array('name','lastedit','removebot','discpage');
		var itemlist = obj['query']['allusers'];
		// Create a table object
		var table = document.createElement('table');
		table.setAttribute('class', 'wikitable')
		var thead = document.createElement('thead');
		var tfoot = document.createElement('tfoot');
		var tbody = document.createElement('tbody');
		var hr = document.createElement('tr');
		for (var i=0; i<header.length; i++) {
			var tc = document.createElement('th');
			tc.appendChild(document.createTextNode(header[i]));
			hr.appendChild(tc);
		}
		thead.appendChild(hr);
		table.appendChild(thead);
		hr = document.createElement('tr');
		tc = document.createElement('td');
		tc.setAttribute('style', 'font-size:x-small');
		tc.appendChild(document.createTextNode('Alle kolonner viser tidspunktet for siste utførelse av handlingen'));
		tc.setAttribute('colSpan', header.length);
		hr.appendChild(tc);
		tfoot.appendChild(hr);
		table.appendChild(tfoot);
		table.appendChild(tbody);
		docobj.appendChild(table);
		for(var i=0;i<itemlist.length;i++) {
			hr = document.createElement('tr');
			for (var j=0; j<types.length; j++) {
				var tc = document.createElement('td');
				tc.setAttribute('id', 'td-'+types[j]+'-' + itemlist[i]['name']);
				tc.style.backgroundColor = '#cccccc';
				tc.appendChild(document.createTextNode((j==0?itemlist[i]['name']:'n/a')));
				hr.appendChild(tc);
			}
			tbody.appendChild(hr);
			processBot(itemlist[i]['name'], null);
		}
	}
}
 
 
function processBot(obj) {
	var query = { action:'query', format:'json', 'continue': '' };
	var data = $.extend({}, query, { 'list':'usercontribs', 'ucuser':obj, 'uclimit':1})
	$.getJSON( mw.util.wikiScript( 'api' ), data, getLastEditB );
}
 
function getLastEditB(obj) {
	// Did we get something?
	if (obj['query']) {
		// Let's get the username
		var name = obj['query']['usercontribs'][0]['user']
		// and the timestamp
		var ts = obj['query']['usercontribs'][0]['timestamp']
		// let's find the table-cell
		var tc = document.getElementById('td-lastedit-' + name);
		// now calculate the color of the cell
		var tsDate = new Date();
		tsDate.setISO8601(ts);
		var date = new Date();
		var days = (date - tsDate) / 86400000
		if (days < 1) {
			tc.innerHTML = 'í dag';
		} else if (days < 2) {
			tc.innerHTML = 'í gær';
		} else {
			tc.innerHTML = Math.ceil(days) + ' dagar síðan';
		}
		date.setDate(date.getDate()-180);
		if (tsDate>date) {
			tc.style.backgroundColor = '#00ff33';
		} else {
			date.setDate(date.getDate()-180);
			if (tsDate>date) {
				tc.style.backgroundColor = '#00ccff';
				// Now, let's make the link to the discussionpage
				tc = document.getElementById('td-discpage-' + name);
				a = document.createElement('a');
				a.setAttribute('href', mw.util.wikiScript( 'index' ) + '?action=edit&preload=Wikipedia:Vélmenni/Fjarlægja-botta-snið&section=new&title=Notandaspjall:'+name);
				a.appendChild(document.createTextNode('spjallsíða'));
				tc.replaceChild(a,tc.firstChild);
			} else {
				tc.style.backgroundColor = '#ff3300';
				// Now, let's make the link to userrights
				tc = document.getElementById('td-removebot-' + name);
				var a = document.createElement('a');
				a.setAttribute('href', mw.util.wikiScript( 'index' ) + '?title=Kerfissíða:Notandaréttindi&user=' + name);
				a.appendChild(document.createTextNode('go go gadget link'));
				tc.replaceChild(a,tc.firstChild);
				// Now, let's make the link to the discussionpage
				tc = document.getElementById('td-discpage-' + name);
				a = document.createElement('a');
				a.setAttribute('href', mw.util.wikiScript( 'index' ) + '?action=edit&preload=Wikipedia:Vélmenni/Fjarlægja-botta-snið&section=new&title=Notandaspjall:'+name);
				a.appendChild(document.createTextNode('spjallsíða'));
				tc.replaceChild(a,tc.firstChild);
			}
 
		}
	}
}

var isDiffB = (document.location.search && (document.location.search.indexOf("diff=") != -1 || document.location.search.indexOf("oldid=") != -1));

if ((mw.config.get('wgAction') =='view') && !isDiffB && ((mw.config.get( 'wgNamespaceNumber' )>=2)&&(mw.config.get( 'wgNamespaceNumber' )<=5))) {
	jQuery( document ).ready(getBotList);
}