User:Synoman Barris/common.js

$(document).ready(AIV);

var AIVpageName = 'User_talk:Synoman_Barris'; var section = '0'; var vandal; var reason; var username;

function addlilinkAIV(url, name, id){ mw.util.addPortletLink( 'p-cactions', url, name, id, null, null ); }

function AIV{ if (document.title.indexOf("User talk:") != -1){ username = encodeURIComponent( mw.config.get('wgTitle') ); var test = username.split('.'); if(test[3]) { addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report IP', 'td-report'); }   else { addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report', 'td-report'); } }  if (document.title.indexOf("User contributions") != -1){ username = location.href.split('/')[5]; if(username == undefined || username == ""){ //if this is the case, then something is up     if(location.href.indexOf("&target=")){ //it looks like we came here from a target link, lets just take the username from that username = location.href.split('=')[2]; }   }    addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report', 'td-report'); } }

function AIVandal(vandalU){ vandal = vandalU; if(vandal == document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML){ alert('You don\'t want to report yourself, do you?'); return; } reason = prompt('Reason?:'); if(!reason) return; document.getElementById('bodyContent').innerHTML = 'Please wait' + '...'; document.getElementById('bodyContent').innerHTML += ' Grabbing page...';

$.ajax({     type: 'GET',      url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&prop=info|revisions&format=xml&intoken=edit&rvprop=content&titles=' + AIVpageName + '&rvsection=' + section,      dataType: "xml",      success: function(xml){        var pagetext = $(xml).find('rev').text;        var edittoken = $(xml).find('page').attr('edittoken');        PageReady(pagetext, edittoken);      },      error: function{        document.getElementById('bodyContent').innerHTML += ' Error reading page: ' + AIVpageName;      }  }); }

function PageReady(pagetext, edittoken){

var x; var myArray = pagetext.split(" "); var add = true; document.getElementById('bodyContent').innerHTML += ' Searching for existing report...'; for (x=0; x < myArray.length; x++) {   var myArray2 = myArray[x].split(/\n/); var y;   for (y=0; y < myArray2.length; y++ ){ if(myArray2[y] ==  ||       myArray2[y] == '*' ||        myArray2[y] ==  ||        myArray2[y] == '*'){ add = false; }   }  }  if(add){ document.getElementById('bodyContent').innerHTML += ' No report found, adding...'; } else{ //alert('CSD tag found'); document.getElementById('bodyContent').innerHTML += ' Report found, will not add...'; return; } //let's do something expiremntal, to see if it's an IP address var test = username.split('.'); if(test[3]) { pagetext += '\n* - ' + reason + ' --~' + '~' + '~' + '~'; }   else { pagetext += '\n* - ' + reason + ' --~' + '~' + '~' + '~'; }

var params = { action : 'edit', title : AIVpageName, section : section, summary : 'Reporting ' + vandal + ' using ARV 2.2.', minor : null, text : pagetext, token : edittoken }

document.getElementById('bodyContent').innerHTML += ' Submitting form...';

var xmlhttp = sajax_init_object; xmlhttp.overrideMimeType('application/json'); xmlhttp.open( 'POST', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php', true); xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); xmlhttp.send( AIVparams(params) ); }

function AIVparams( arr ) { var resarr = Array; for( var i in arr ) { if( typeof arr[i] == 'undefined' ) { continue; }       var res; if( arr[i] instanceof Array ){ var v = Array; for(var j = 0; j < arr[i].length; ++j ) { v[j] = encodeURIComponent( arr[i][j] ); }           res = v.join('|'); } else { res = encodeURIComponent( arr[i] ); }       resarr.push( encodeURIComponent( i ) + '=' + res ); }   return resarr.join('&'); }