Jump to content

User:Thetrick/tfd helper/votenom.js

From Wikipedia, the free encyclopedia
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.
//<pre><nowiki>
 
/*********** TfD Helper - basic **********/
/* see [[User:Thetrick/tfd_helper]]      */
/* based on [[User:Jnothman/afd_helper]] */

importScript("User:Thetrick/tfd_helper/automodtfdh.js");
 
var tfdh_signature;
var tfdh_advanced;
var tfdh_multi;

/* this function runs at load */
function tfd_helper() {
    /* call auto mod first, exit if it did processing */
    if (auto_mod_tfdh())
       return;
    if (tfdh_advanced == null)
        tfdh_advanced = false;
    if (tfdh_multi == null)
        tfdh_multi = false;
    if (tfdh_signature == null)
        tfdh_signature = '~~'+'~'
    /* add these to the sidebar all the time */
    amtfdh_add_li('tb', 'http://wiki.riteme.site/wiki/Wikipedia:Templates_for_deletion', 'TfDh: discussion', 'tfdl1', 'View Templates for Deletion discussions');
    /* add these to the sidebar if a template */
    if (wgCanonicalNamespace == 'Template' && wgIsArticle == true) {
        amtfdh_add_li('tb', 'javascript:tfd_nominate("normal")', 'TfDh: nominate TfD', 'tfdh1', 'Nominate this template for deletion (navboxes, infoboxes, messageboxes, etc.)');
        amtfdh_add_li('tb', 'javascript:tfd_notify()', 'TfDh: Notify user', 'tfdh12', 'Notify a user that this template has been nominated for deletion');
    }
    /* start wholescale copy to votenom.js here */
    /* add vote links */
    if (wgCanonicalNamespace == 'Project') {
        var title = wgTitle;
        if (title.match(new RegExp('eletion'))) {
            var anchors = document.getElementById('bodyContent').getElementsByTagName('a');
            var url_re = new RegExp("title=Wikipedia:Templates_for_deletion\/Log\/([^&]+)\&action=edit\&section=");
            for (var i=0; i < anchors.length; i++) {
                /* this match is touchy because main page and individual logs display differently */
                if ( !(anchors[i].href.match(url_re)) || (anchors[i].href.match(/section=1$/)) || (anchors[i].href.match(/section=T-1$/)) )
                    continue;
                var na = document.createElement('a');
                na.href = "javascript:tfd_vote('" + escape(anchors[i].href) + "')";
                na.title = "Vote on this nomination";
                na.innerHTML = "&nbsp;&bull;&nbsp;vote";
                anchors[i].parentNode.insertBefore(na, anchors[i].nextSibling);
            }
        }
    }
}
 
/* voting function - vote on a TfD nomination */
function tfd_vote(edit_link) {
    var choice = window.prompt("Enter your vote (Keep, Delete, Neutral, Comment, Merge, Redirect, Speedy keep, Speedy delete):", "");
    if (!choice)
        return;
    var reason = window.prompt("Provide an explanation for your vote:", "");
    if (!reason)
        return;
    var edit_sum = window.prompt("Provide an edit summary for your vote:", choice);
    if (!edit_sum)
        return;
    window.open(edit_link + '&tfdaddafter=' + escape("\n*'''" + choice + "''' " + reason + " " + tfdh_signature + " ~~" + "~~" + "~") + '&tfdsummary=' + escape(edit_sum), 'tfdv1');
}

/* tfdh1, tfdh9, tfdh10 - nominate this template for deletion - opens a new window */
function tfd_nominate(type) {
    var subst_str = '{{subst:PAGENAME}}';
    var log_date = window.prompt("This should be the date of the latest TfD log. Change it if necessary.", amtfdh_guess_date());
    if (!log_date)
        return;
    var reason = window.prompt("Justify your TfD nomination of " + wgPageName + ":", "");
    if (!reason)
        return;
    if (tfdh_multi)
        var append_name = window.prompt("Enter exact name of the previous TfD you want to append " + wgTitle+ " to (do NOT include Template:)", "");
    if (tfdh_multi && append_name) {
        subst_str = '{{subst:PAGENAME}}|' + append_name;
        window.open(amtfdh_make_url('Wikipedia:Templates for deletion/Log/' + log_date, '', '\n:{{tfdlinks|' + wgTitle + '}}\n', 'Appending ' + wgPageName + ' for deletion') + "&tfdatstring={{tfdlinks|" + escape(append_name) + "}}", 'tfdh1w1');
    } else {
        window.open(amtfdh_make_url('Wikipedia:Templates for deletion/Log/' + log_date, '', '\n{{' + 'subst:tfd2|' + wgTitle + '|text=' + reason + ' ' + tfdh_signature + ' ~~' + '~~' + '~' + '}}\n', 'Nominated ' + wgPageName + ' for deletion') + "&tfdatstring=-->", 'tfdh1w1');
    }
    if (type == 'normal') {
    	window.location.href = amtfdh_make_url(wgPageName, '{{' + 'tfd|' + subst_str + '}}', '', 'Nominated ' + wgPageName + ' for [[WP:TfD|deletion]]');
    } else if (type == 'parsed') {
    	window.location.href = amtfdh_make_url(wgPageName, '<noinclude>{{' + 'tfd|' + subst_str + '}}</noinclude>', '', 'Nominated ' + wgPageName + ' for [[WP:TfD|deletion]]');
    } else if (type == 'inline') {
    	window.location.href = amtfdh_make_url(wgPageName, '{{' + 'tfd-inline|' + subst_str + '}}', '', 'Nominated ' + wgPageName + ' for [[WP:TfD|deletion]]');
    }
}

/* tfdh12 - notify a user about a TfD */
function tfd_notify() {
    var user_name = window.prompt("Enter the name of the user you want to notify (e.g. Bob, not User:Bob) (this should be the creator and/or primary contributor)", "");
    if (!user_name)
        return;
    window.location.href = amtfdh_make_url('User_talk:' + user_name, '', '\n{{subst:Tfdnotice|' + wgTitle + '}}' + tfdh_signature + ' ~~' + '~~' + '~' + '\n', 'Notification that ' + wgPageName + ' has been nominated for [[WP:TfD|deletion]]');
}
/* end wholescale copy to votenom.js here */

/* run a register function */
addOnloadHook(tfd_helper);
 
//bits of test code sit here
//    var yes_no = window.prompt('Here is the url', amtfdh_make_url(here, here, here, here));
//    return;
 
//</nowiki></pre>