User:2D/afdvote.js
Appearance
< User:2D
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:2D/afdvote. |
<!--
function urlencode(plaintext) { //Unicode chars aren't encoded, which is what I want
var SAFECHARS = "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()";
var HEX = "0123456789ABCDEF";
var encoded = "";
for (var i = 0; i < plaintext.length; i++) {
var ch = plaintext.charAt(i);
if (ch == " ") {
encoded += "+";
}
else if (SAFECHARS.indexOf(ch) != - 1) {
encoded += ch;
}
else {
var charCode = ch.charCodeAt(0);
if (charCode > 255) {
encoded += ch;
}
else {
encoded += "%";
encoded += HEX.charAt((charCode >> 4) & 0xF);
encoded += HEX.charAt(charCode & 0xF);
}
}
}
return encoded;
}
function postr(url, vars,type)
{
var request = new XMLHttpRequest();
request.open("POST", url, true);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.onreadystatechange = function()
{
var done = 4, ok = 200;
if (request.readyState == done && request.status == ok)
{
if (request.responseText)
{
httpresponse(request.responseText,type);
}
}
};
request.send(vars);
}
function httpresponse(response,type)
{
if(type=="content")
{
parser = new DOMParser();
xmlDoc = parser.parseFromString(response,"text/xml");
content = xmlDoc.getElementsByTagName("rev")[0].childNodes[0].nodeValue;
if(content.indexOf("If you are seeing this page as a result of an attempt to re-nominate") != -1) // Has already been nominated
{
nomnum = prompt("This article has had more than one AfD. What is the one you want to vote on? Format: 2nd, 3rd, 4th, etc.","2nd");
nomstring = " (" + nomnum + " nomination)";
postr("http://en.wikipedia.org/w/api.php","format=xml&action=query&prop=revisions&titles=" + urlencode("Wikipedia:Articles for deletion/") + urlencode(pagename) + urlencode(nomstring) + "&rvprop=content","content");
return false;
}
postr("http://en.wikipedia.org/w/api.php","action=query&prop=info&intoken=edit&format=xml&titles=WP:AFD","token");
}
if(type=="token")
{
parser = new DOMParser();
xmlDoc = parser.parseFromString(response,"text/xml");
token = xmlDoc.getElementsByTagName("page")[0].attributes.getNamedItem("edittoken").childNodes[0].nodeValue;
postr("http://en.wikipedia.org/w/api.php","format=xml&action=edit&title=" + urlencode("Wikipedia:Articles for deletion/" + pagename + nomstring) + "&summary=Voting%20using%20AfDVote&text=" + urlencode(content) + urlencode("\r\n*'''" + vote + "''' - " + reason + " ~~~~") + "&token=" + urlencode(token),"edit");
}
if(type=="edit")
{
//document.write(response);
}
}
function vote(element)
{
var firstp = element.textContent.indexOf("(edit");
firstp--;
pagename = element.textContent.slice(0,firstp);
//pagename.replace(" ","_");
vote = prompt("What would you like to vote (eg. Delete)"); //Yes, it's ugly, but it works, and it doesn't make the script less effective
reason = prompt("What is your reason for voting " + vote + "?"); //See above
var tc = confirm("So, to confirm, you want to vote \"" + vote + "\" because \"" + reason + "\"?");
if(!tc) return false;
nomstring = "";
postr("http://en.wikipedia.org/w/api.php","format=xml&action=query&prop=revisions&titles=" + urlencode("Wikipedia:Articles for deletion/") + urlencode(pagename) + "&rvprop=content","content");
}
function addlinks()
{
var eles = document.getElementsByClassName("plainlinksneverexpand lx");
for(var i=0; i < eles.length; i++)
{
eles[i].innerHTML += " <tt>(</tt><input type='button' onclick='vote(this.parentNode)' value='vote on this AfD'><tt>)</tt>";
}
}
function start()
{
if(mw.config.get('wgPageName').indexOf("Wikipedia:Articles_for_deletion/Log/") != -1)
{
addlinks();
}
}
$(start);
-->