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 02:03, 3 November 2005 (speedy delete shortcut). 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['wd'] = 'Weak delete';
afdh_shortcuts['sd'] = 'Strong delete';
afdh_shortcuts['k'] = 'Keep';
afdh_shortcuts['sk'] = 'Strong keep';
afdh_shortcuts['wk'] = 'Weak keep';
afdh_shortcuts['sp'] = 'Speedy delete';
afdh_shortcuts['rw'] = 'Rewrite';
afdh_shortcuts['rd'] = 'Redirect';
afdh_shortcuts['m'] = 'Merge';
afdh_shortcuts['mv'] = 'Move';
afdh_shortcuts['c'] = 'Comment';
afdh_shortcuts['t'] = 'Transwiki';

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 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;
    if (afdh_shortcuts[vote.toLowerCase()])
        vote = afdh_shortcuts[vote.toLowerCase()];
    var comment = window.prompt("Enter your comment:");
    if (typeof comment != 'string') return;
    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);
    window.open(url, "afd_helper_vote");
}