User:Jnothman/afd helper/script.js
Appearance
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. |
![]() | This user script seems to have a documentation page at User:Jnothman/afd helper/script. |
/************* afd Helper ************/
// see User:Jnothman/afd_helper
afdh_signature = '~~'+'~';
function afd_get_query_vars(){
var res = new Array();
var pairs = location.search.substring(1).split("&");
for(var i=0; i < pairs.length; i++){
var pair = pairs[i].split("=");
res[unescape(pair[0])] = unescape(pair[1]).replace(/\+/g, ' ');
}
return res;
}
function afd_helper() {
qvars = afd_get_query_vars();
var vote;
if (qvars['action']=='edit') {
if (vote = qvars['afdverdict']) {
var comment = qvars['afdcomment'] || '';
var text = document.getElementById('wpTextbox1');
if (text.value.charAt(text.value.length-1) != '\n')
text.value += '\n';
text.value += "* '''"+vote+"''' "+comment+" "+afdh_signature+" ~~"+"~~"+"~";
document.getElementById('wpSummary').value += ' ' + vote;
document.getElementById('editform').submit();
}
return;
}
var anchors = new Array();
{
var oldanchors = document.getElementById('bodyContent').getElementsByTagName('a');
for (var i=0; i < oldanchors.length; i++)
anchors[i] = oldanchors[i];
}
var url_re = /\?title=Wikipedia:Articles_for_deletion\/([^&]+)&action=edit&/;
var url, matches;
for (var i=0; i < anchors.length; i++) {
if (!(matches = anchors[i].href.match(url_re))
|| (matches[1].substr(0, 4) == 'Log/'))
continue;
var na = document.createElement('a');
na.href = "javascript:afd_vote('"+anchors[i].href.replace(/'/g, '\\\'')+"')";
na.title = "Make a vote on the proposed deletion of"+unescape(matches[1]);
var inlink = document.createElement('sup');
inlink.appendChild(document.createTextNode('vote'));
na.appendChild(inlink);
anchors[i].parentNode.insertBefore(na, anchors[i].nextSibling);
}
}
function afd_vote(edit_link) {
var vote = window.prompt("Enter your vote (eg delete, keep, merge):");
if (!vote) return;
var comment = window.prompt("Enter your comment:");
if (typeof comment != 'string') return;
var url = edit_link + '&afdverdict='+escape(vote)+'&afdcomment='+escape(comment);
window.open(url, "afd_helper_vote");
}