Jump to content

User:Jnothman/afd helper/script.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jnothman (talk | contribs) at 06:10, 3 November 2005 (only check appropriate anchors: may speed up script for some). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/************* 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");
}