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 = '~~'+'~';
afdh_summaryprompt = true;
afdh_shortcuts = Array();
afdh_shortcuts['d'] = 'Delete';
afdh_shortcuts['k'] = 'Keep';
afdh_shortcuts['m'] = 'Merge';
afdh_shortcuts['mv'] = 'Move';
afdh_shortcuts['rd'] = 'Redirect';
afdh_shortcuts['rw'] = 'Rewrite';
afdh_shortcuts['t'] = 'Transwiki';
afdh_shortcuts['wd'] = 'Weak delete';
afdh_shortcuts['sd'] = 'Strong delete';
afdh_shortcuts['sp'] = 'Speedy delete';
afdh_shortcuts['sk'] = 'Strong keep';
afdh_shortcuts['wk'] = 'Weak keep';
afdh_shortcuts['c'] = 'Comment';
afdh_commscs = Array();
afdh_commscs['pn'] = 'per nom.';
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 summ_el = document.getElementById('wpSummary');
if (summ_el.value != '' && summ_el.value.substr(summ_el.value.length - 3, 3) != '*/ ') {
// have already added summary
return;
}
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+" ~~"+"~~"+"~";
summ_el.value += ' ' + qvars['afdsumm'];
document.getElementById('editform').submit();
}
return;
}
var editlinks = new Array();
{
var anchors = document.getElementById('bodyContent').getElementsByTagName('a');
for (var i=0; i < anchors.length; i++)
if (anchors[i].className == 'editsection')
editlinks[i] = anchors[i];
var url_re = /\?title=Wikipedia:Articles_for_deletion\/([^&]+)&action=edit&/;
var url, matches;
for (var i=0; i < editlinks.length; i++) {
if (!(matches = editlinks[i].href.match(url_re))
|| (matches[1].substr(0, 4) == 'Log/'))
continue;
var na = document.createElement('a');
na.href = "javascript:afd_vote('"+editlinks[i].href.replace(/'/g, '\\\'')+"')";
na.title = "Vote on deletion of "+unescape(matches[1]);
var inlink = document.createElement('sup');
inlink.appendChild(document.createTextNode('vote'));
na.appendChild(inlink);
editlinks[i].parentNode.insertBefore(na, editlinks[i].nextSibling);
}
}
function afd_vote(edit_link) {
var shortcuts_list = '';
for (var key in afdh_shortcuts)
shortcuts_list += key + ': ' + afdh_shortcuts[key] + '; ';
var vote = window.prompt("Enter your vote. (Shortcuts available are: "+shortcuts_list+")");
if (!vote) return;
if (afdh_shortcuts[vote.toLowerCase()])
vote = afdh_shortcuts[vote.toLowerCase()];
shortcuts_list = '';
for (var key in afdh_commscs)
shortcuts_list += key + ': ' + afdh_commscs[key] + '; ';
var comment = window.prompt("Enter your comment. (Shortcuts available are: "+shortcuts_list+")");
if (typeof comment != 'string') return;
if (afdh_commscs[comment.toLowerCase()])
comment = afdh_commscs[comment.toLowerCase()];
var summary = vote;
if (afdh_summaryprompt)
if (!(summary = window.prompt("Enter the edit summary:", summary)))
summary = vote;
var url = edit_link + '&afdverdict='+escape(vote)+'&afdcomment='+escape(comment)+'&afdsumm='+escape(summary);
if (window.location.href.indexOf("/Log/") == -1)
window.location.href = url;
else
window.open(url, "afd_helper_vote");
}