User:Shane/bsgbook.js/autoreport.js: Difference between revisions
From Battlestar Wiki, the free, open content Battlestar Galactica encyclopedia and episode guide
More actions
< User:Shane | bsgbook.js
removed this function here |
updated :) |
||
| Line 7: | Line 7: | ||
var reason; | var reason; | ||
addOnloadHook(AIV); | |||
function AIV(){ | function AIV(){ | ||
| Line 52: | Line 42: | ||
} | } | ||
} | } | ||
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; | |||
var l = addlilink(tabs, "javascript:AIVandal("' + username + '")", 'report user', ''); | |||
l.lastChild.title = "Report this user to BW:AN"; | |||
} | } | ||
} | } | ||
| Line 151: | Line 143: | ||
newform.submit(); | newform.submit(); | ||
} | } | ||
addOnloadHook(AIV); | |||
/* </nowiki></pre> */ | /* </nowiki></pre> */ | ||
Revision as of 20:31, 18 July 2006
/* {{shortcut|BW:AVI}} <pre><nowiki> */
var pageName;
var AIVpageName = 'Battlestar_Wiki:Administrators%27_noticeboard';
var section = '4';
var vandal;
var reason;
addOnloadHook(AIV);
function AIV(){
if (document.title.indexOf("User talk:") != -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];
}
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];
}
}
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
var l = addlilink(tabs, "javascript:AIVandal("' + username + '")", 'report user', '');
l.lastChild.title = "Report this user to BW:AN";
}
}
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 += '<br />Grabbing page...';
gml_xmlhttp.open('GET', 'http://www.battlestarwiki.org/en/index.php?title=' + AIVpageName + '&action=edit' + '§ion=' + section + '', true);
gml_xmlhttp.onreadystatechange = AIVMore;
gml_xmlhttp.send(null);
}
function AIVMore() {
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 />Searching for exsisting report...';
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(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;
}
form.wpTextbox1.value += '*{{vandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
form.wpSummary.value = 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[BW:AVI]].';
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 [[BW:AVI]].';
} 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();
}
addOnloadHook(AIV);
/* </nowiki></pre> */