Utilisateur:EDUCA33E/axe.js
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.//AXE 1.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 pageName;
var AXEpageName = 'User:EDUCA33E/test';
var section = '1';
var vandal;
var reason;
function addlilinkAXE(url, name, id){
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
li.id = id;
li.appendChild(na);
tabs.appendChild(li);
return li;
}
function AXE(){
if (document.title.indexOf("Discussion Utilisateur:") != -1){
username = location.href.split(':')[2];
if(!username){
username = document.getElementsByTagName('h1')[0].innerHTML.split(':')[1];
}
if (username.indexOf("&action=edit") != -1){
//remove &action=edit from username, only happens when editing user talk
username = username.split('&')[0];
}
else if (username.indexOf("&action=submit") != -1){
//remove &action=submit from username, only happens after giving user a warning.
username = username.split('&')[0];
}
if (username.indexOf("#") != -1){
//this removes any ancor that could possibly be in the URL bar, where we fetch the username from.
username = username.split('#')[0];
}
//if there is an & in there, lets get rid of it
if (username.indexOf("&") != -1){
username = username.split('&')[0];
}
var test = username.split('.');
if(test[3]) {
addlilinkAXE('javascript:AXEandal("' + username + '")', 'Axe IP', 'td-report');
}
else {
addlilinkAXE('javascript:AXEandal("' + username + '")', 'Axe', 'td-report');
}
}
if (document.title.indexOf("Contributions de cet utilisateur") != -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];
}
}
addlilinkAXE('javascript:AXEandal("' + username + '")', 'Axe.', 'td-report');
}
}
function AXEandal(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 = '<br />Patientez' + '...';
gml_xmlhttp = HTTPClient();
if (!gml_xmlhttp)
return;
document.getElementById('bodyContent').innerHTML += '<br />Récupération de la page...';
gml_xmlhttp.open('GET', 'http://fr.wikipedia.org/w/index.php?title=' + AXEpageName + '&action=edit' + '§ion=' + section + '', true);
gml_xmlhttp.onreadystatechange = AXEMore;
gml_xmlhttp.send(null);
}
function AXEMore() {
if (gml_xmlhttp.readyState != 4){
document.getElementById('bodyContent').innerHTML += '.';
return
}
var form, newform, l;
// Insert the downloaded form in our current page, using
// only hidden form inputs.
doc = gml_XMLParse(gml_xmlhttp.responseText);
form = doc.getElementById('editform');
var x;
var t = form.wpTextbox1.value;
// myArray = t.split(" ");
var add;
add = true;
document.getElementById('bodyContent').innerHTML += '<br />Recherche si le pattern existe ...';
//var test = "*{{vandal|" + vandal + "}}";
//for (x in myArray)
//{
// myArray2 = myArray[x].split(/\n/);
// for (y in myArray2){
// if(myArray2[y] == '{{vandal|' + vandal + '}}'){
// add = false;
// }
// if(myArray2[y] == test){
// add = false;
// }
// if(myArray2[y] == '{{IPvandal|' + vandal + '}}'){
// add = false;
// }
// }
//}
add = false; // always
if(t.indexOf(reason) == -1){
add = true;
}
if(add == true){
document.getElementById('bodyContent').innerHTML += '<br />No report found, adding...';
}
else{
//alert('CSD tag found');
document.getElementById('bodyContent').innerHTML += '<br />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 += '*{{IPvandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
}
else {
form.wpTextbox1.value += '*{{vandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
}
form.wpSummary.value = 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[WP:ARV|ARV 2.1]].';
newform = document.createElement('form');
l = form.getElementsByTagName('textarea');
for (i = l.length; i--; ) {
var t = document.createElement('input');
t.type = 'hidden';
t.name = l[i].name;
t.value = l[i].value;
newform.appendChild(t);
}
l = form.getElementsByTagName('input');
for (i = l.length; i--; ) {
if (l[i].name == 'wpSummary') {
l[i].value = 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[WP:ARV|ARV 2.1]].';
} else if (l[i].name == 'wpMinoredit') {
l[i].value = '1';
} else if (l[i].name == 'wpWatchthis') {
if (!l[i].checked)
continue;
l[i].value = "on";
} else if (l[i].name == 'wpPreview') {
continue;
} else if (l[i].name == 'wpDiff') {
continue;
}
l[i].type = 'hidden';
newform.appendChild(l[i]);
}
newform.name = form.name;
newform.method = form.method;
newform.id = form.id;
newform.action = form.action;
document.getElementById('bodyContent').innerHTML += '<br />Submitting form...';
document.getElementById('bodyContent').appendChild(newform);
// Submit the form
newform.submit();
}
$(AXE);