User:Andrea105/monobook.js

importScript('User:Lupin/recent2.js');

function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); }	return null; }

function createCookie(name,value,days) { if (days) { var date = new Date; date.setTime(date.getTime+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString; }	else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; }

function eraseCookie(name) { createCookie(name,"",-1); }

function warningtab { document.getElementById('column-one').getElementsByTagName('div')[0].getElementsByTagName('ul')[0].appendChild(tnaddlilink("javascript:markpage", "pt")); if(document.URL.indexOf("User_talk") != -1 && document.URL.indexOf("edit") != -1) {    document.getElementById('column-one').getElementsByTagName('div')[0].getElementsByTagName('ul')[0].appendChild(tnaddlilink("javascript:uwtest1", "t1")); document.getElementById('column-one').getElementsByTagName('div')[0].getElementsByTagName('ul')[0].appendChild(tnaddlilink("javascript:uwvand2", "w2")); document.getElementById('column-one').getElementsByTagName('div')[0].getElementsByTagName('ul')[0].appendChild(tnaddlilink("javascript:uwvand4", "w4")); } if( ((document.URL.indexOf("&from=") != -1) && (document.URL.indexOf("&token=") != -1)) || (document.URL.indexOf("&autoclick=wpSave") != -1) ) {   markpage; } }

function uwtest1 { document.editform.wpTextbox1.value += ( "\n===" + "{" + "{" + "subst:" + "CURRENTMONTHNAME" + "}" + "}" + " {" + "{" + "subst:" + "CURRENTYEAR" + "}" + "}" + "===" ); document.editform.wpTextbox1.value += ( "\n" + "{" + "{" + "subst:" + "uw-test1\|" + readCookie("pageattacked") + "}" + "}" + " ~" + "~" + "~" + "~" ); document.editform.wpSummary.value = "uw-test1"; document.editform.wpSave.click; }

function uwvand2 { document.editform.wpTextbox1.value += ( "\n===" + "{" + "{" + "subst:" + "CURRENTMONTHNAME" + "}" + "}" + " {" + "{" + "subst:" + "CURRENTYEAR" + "}" + "}" + "===" ); document.editform.wpTextbox1.value += ( "\n" + "{" + "{" + "subst:" + "uw-vand2\|" + readCookie("pageattacked") + "}" + "}" + " ~" + "~" + "~" + "~" ); document.editform.wpSummary.value = "uw-vand2"; document.editform.wpSave.click; }

function uwvand4 { document.editform.wpTextbox1.value += ( "\n===" + "{" + "{" + "subst:" + "CURRENTMONTHNAME" + "}" + "}" + " {" + "{" + "subst:" + "CURRENTYEAR" + "}" + "}" + "===" ); document.editform.wpTextbox1.value += ( "\n" + "{" + "{" + "subst:" + "uw-vand4\|" + readCookie("pageattacked") + "}" + "}" + " ~" + "~" + "~" + "~" ); document.editform.wpSummary.value = "uw-vand4"; document.editform.wpSave.click; }

function markpage { createCookie("pageattacked", wgPageName.replace(/_/g, ' '), 2); }

$(warningtab);

function tnaddlilink(url, name) { var na = document.createElement('a'); na.setAttribute('href', url); var txt = document.createTextNode(name); na.appendChild(txt); var li = document.createElement('li'); li.appendChild(na); return li; }

//ARV 2.0 // - // XMLHttpRequest support // - if (document.implementation.createDocument) { var gml_xmlparser = new DOMParser; }

function gml_XMLParse(string) { if (document.implementation.createDocument) { return gml_xmlparser.parseFromString(string, "text/xml"); } else if (window.ActiveXObject) { var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM"); gml_xmldoc.async = "false"; ret = gml_xmldoc.loadXML(string); if (!ret) return null; return gml_xmldoc.documentElement; } return null; }

var gml_xmlhttp;

function HTTPClient { var gml_http; if(window.XMLHttpRequest) { gml_http = new XMLHttpRequest; } else if (window.ActiveXObject) { try { gml_http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { gml_http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { gml_http = false; }   }  }  return gml_http; } var AIVpageName = 'Wikipedia:Administrator_intervention_against_vandalism'; var section = '1'; var vandal; var reason;

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

function AIV{ if (document.title.indexOf("User talk:") != -1){ username = encodeURIComponent( 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' + '...'; gml_xmlhttp = HTTPClient; if (!gml_xmlhttp) return; document.getElementById('bodyContent').innerHTML += ' Grabbing page...'; gml_xmlhttp.open('GET', 'http://en.wikipedia.org/w/index.php?title=' + AIVpageName + '&action=edit' + '&section=' + section + '', true); gml_xmlhttp.onreadystatechange = AIVMore; gml_xmlhttp.send(null); }

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('&'); }

function AIVMore { if (gml_xmlhttp.readyState != 4){ document.getElementById('bodyContent').innerHTML += '.'; return }

// Insert the downloaded form in our current page, using // only hidden form inputs. var doc = gml_XMLParse(gml_xmlhttp.responseText); var form = doc.getElementById('editform');

var x; var t = form.wpTextbox1.value; var myArray = t.split(" "); var add = true; document.getElementById('bodyContent').innerHTML += ' Searching for existing report...'; var test = "*"; 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] == ''){ add = false; }     if(myArray2[y] == test){ add = false; }     if(myArray2[y] == ''){ add = false; }   }  }  if(add == true){ 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]) { form.wpTextbox1.value += '* - ' + reason + ' --~' + '~' + '~' + '~'; }   else { form.wpTextbox1.value += '* - ' + reason + ' --~' + '~' + '~' + '~'; }

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

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) ); }

$(AIV);