User:Joeytje50/ChatLogger.js

//import this using importScript('User:Joeytje50/ChatLogger.js') //To set an interval of submitting logs, put var logInterval = (amount of milliseconds); above the import. Default is 5 minutes.

if (wgCanonicalSpecialPageName=="Chat" && skin=="oasis") {

var logInterval = logInterval?logInterval:300000;

function getLog { //Getting arrays with messages and senders var allmsgs = document.getElementsByClassName('Chat')[0].getElementsByClassName('message'); var message = allmsgs[0].innerHTML; var msguser = allmsgs[0].parentNode.getAttribute('data-user'); var msgtime = allmsgs[0].parentNode.getElementsByClassName('time')[0].innerHTML; for (i=1;allmsgs[i];i++) { message += '<|>'+allmsgs[i].innerHTML; msguser += '<|>'+allmsgs[i].parentNode.getAttribute('data-user'); msgtime += '<|>'+allmsgs[i].parentNode.getElementsByClassName('time')[0].innerHTML; } message = message.split('<|>') msguser = msguser.split('<|>') msgtime = msgtime.split('<|>') //Turning the format into a log instead of arrays var ChatLog=''; for (i=0;message[i];i++) { if (message[i].replace(/^\s+/, '')) { ChatLog += '['+msgtime[i]+'] <'+msguser[i]+'> '+message[i].replace(/^\s+/, '')+'\n' } } var wikilinks = new RegExp('([^<]*)','g') ChatLog = ChatLog.replace(/( |	){2,}/g, ' ').replace(/]*>/, '$1').replace(wikilinks, '$2').replace(/\[\[([^|]*)\|\1]]/g, '$1').replace(/[^<]*<\/a>/g, '$1').replace(''+wgServer+'/wiki/', wgServer+'/wiki/') //HTML img and a tag fixes return ''+ChatLog+' ' }

function callAPI(data, method, callback) { data['format'] = 'json'; $.ajax({		data: data,		dataType: 'json',		url: wgScriptPath + '/api.php',		type: method,		success: function(response) {			if (response.error)				showError('API error: ' + response.error.info);			else 				callback(response);		},		error: function(xhr, error) { showError('AJAX error: ' + error); }	}); }

var d = new Date var monthNames = ["January","February","March","April","May","June","July","August","September","October","November","December"]; var date = d.getDate + '_' + monthNames[d.getMonth] + '_' + d.getFullYear;

function submitLog { callAPI({	'action': 'query',	'prop': 'info|revisions',	'intoken': 'edit',	'titles': 'Joeytje50_wiki:Chat/Logs/'+date,	'rvprop': 'content',	'rvlimit': '1',	'indexpageids': 'true', }, 'GET', function(response) {	var page = response.query.pages[response.query.pageids[0]];

callAPI({		'minor': 'yes',		'summary': 'Adding to chatlog',		'action': 'edit',		'title': 'Project:Chat/Logs/'+date,		'startimestamp': page.starttimestamp,		'token': page.edittoken,		'text': getLog	}, 'POST', function(response) {	}); }); }

setInterval('submitLog', logInterval)

}