User:Lightdarkness/warn.js

//This page is just testing, going to try to automate the adding of warning messages. var globalwarn; var pageName; myArray = document.title.split(/ - /); var page = myArray[0]; myregexp = new RegExp(" "); pageName = page.replace(myregexp, "_"); function WarnUser(warntemplate){ if (document.title.indexOf("User talk:") != -1) {   if (document.title.indexOf("Editing User talk:") == -1) {     globalwarn = warntemplate; document.getElementById('bodyContent').innerHTML = 'Please wait, warning user with ' + warntemplate + '...'; gml_xmlhttp = HTTPClient; if (!gml_xmlhttp) return; document.getElementById('bodyContent').innerHTML += ' Trying to get old contents...'; gml_xmlhttp.open('GET', 'http://en.wikipedia.org/w/index.php?title=' + pageName + '&action=edit', true); gml_xmlhttp.onreadystatechange = WarnMore; gml_xmlhttp.send(null); } } }

function WarnMore { if (gml_xmlhttp.readyState != 4) 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 prefix = ""; if(globalwarn == "test5"){ prefix = ""; } form.wpTextbox1.value = form.wpTextbox1.value + "" + prefix + "{" + "{" + "subst:" + globalwarn + "}" + "}" + " --~" + "~" + "~" + "~"; 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 = 'Warning user: ' + globalwarn +'' } 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 += ' Submitting form...'; document.getElementById('bodyContent').appendChild(newform); // Submit the form newform.submit; /* if (gml_xmlhttp.readyState != 4) return document.getElementById('bodyContent').innerHTML += ' Appending warning to talk page...'; 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'); text = form.wpTextbox1.value; text += "#{" + "{" + "subst:" + globalwarn + "}" + "}" + " --~" + "~" + "~" + "~"; topaz.statuschanger = new Object; topaz.wputil.setpagecontent(     pageName,      text,      'Warning user: ' + globalwarn +''); document.getElementById('bodyContent').innerHTML += ' Reloading talk page...'; window.location.reload; }