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 **************/
/* 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 tabs at the top */
    if (tfdh_advanced && mw.config.get('wgCanonicalNamespace') == 'Template' && mw.config.get('wgIsArticle') == true) {
        amtfdh_add_li('cactions', 'javascript:add_one_category()', 'add 1 cat.', 'tfdh14', 'Add just one category to this template');
    }
    /* add these to the sidebar all the time */
    amtfdh_add_li('tb', 'http://en.wikipedia.org/wiki/Wikipedia:Templates_for_deletion', 'TfDh: discussions', 'tfdl1', 'View Templates for Deletion discussions');
    amtfdh_add_li('tb', 'http://en.wikipedia.org/wiki/Category:Wikipedia_uncategorized_templates', 'TfDh: uncat. cat.', 'tfdl2', 'View Category:Wikipedia uncategorized templates');
    amtfdh_add_li('tb', 'http://en.wikipedia.org/wiki/Special:UncategorizedTemplates', 'TfDh: uncat. list', 'tfdl3', 'View Special:UncategorizedTemplates list');
    amtfdh_add_li('tb', 'javascript:search_namespace("14")', 'TfDh: find category', 'tfdh5', 'Search the category namespace');
    amtfdh_add_li('tb', 'javascript:search_namespace("10")', 'TfDh: find template', 'tfdh6', 'Search the template namespace');
    amtfdh_add_li('tb', 'javascript:view_prefix("10")', 'TfDh: view prefix', 'tfdh16', 'View the template namespace starting at a specified string');
    /* add these to the sidebar if a template */
    if (mw.config.get('wgCanonicalNamespace') == 'Template' && mw.config.get('wgIsArticle') == true) {
        amtfdh_add_li('tb', 'javascript:add_template_category()', 'TfDh: add category', 'tfdh2', 'Add categories to this template');
        amtfdh_add_li('tb', 'javascript:flag_uncat_template()', 'TfDh: flag as uncat.', 'tfdh3', 'Flag this template as uncategorized');
        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_nominate("parsed")', 'TfDh: n. TfD (parsed)', 'tfdh9', 'Nominate this template for deletion (parsed templates)');
        amtfdh_add_li('tb', 'javascript:tfd_nominate("inline")', 'TfDh: n. TfD (inline)', 'tfdh10', 'Nominate this template for deletion (inline templates)');
        amtfdh_add_li('tb', 'javascript:tfd_notify()', 'TfDh: Notify user', 'tfdh12', 'Notify a user that this template has been nominated for deletion');
        /* add these to the sidebar if the user is advanced */
        if (tfdh_advanced) {
            amtfdh_add_li('tb', 'javascript:flag_template_csd("t1")', 'TfDh: req. CSD#T1', 'tfdh18', 'Request speedy deletion because this template is divisive or inflamatory');
            amtfdh_add_li('tb', 'javascript:flag_template_csd("t2")', 'TfDh: req. CSD#T2', 'tfdh19', 'Request speedy deletion because this template blatently misrepresents policy');
            amtfdh_add_li('tb', 'javascript:flag_template_csd("t3")', 'TfDh: req. CSD#T3', 'tfdh20', 'Request speedy deletion because this template is unused AND duplicates or hardcodes another template');
            amtfdh_add_li('tb', 'javascript:flag_template_csd("g1")', 'TfDh: req. CSD#G1', 'tfdh15', 'Request speedy deletion because this template is patently nonsensical');
            amtfdh_add_li('tb', 'javascript:flag_template_csd("g2")', 'TfDh: req. CSD#G2', 'tfdh4', 'Request speedy deletion because this template is a test template');
            amtfdh_add_li('tb', 'javascript:flag_template_csd("g6")', 'TfDh: req. CSD#G6', 'tfdh8', 'Request speedy deletion of this template for housekeeping reasons');
            amtfdh_add_li('tb', 'javascript:flag_template_csd("g7")', 'TfDh: req. CSD#G7', 'tfdh7', 'Request speedy deletion of this template because the author requested it');
        }
    }
    /* start wholescale copy to votenom.js here */
    /* add vote links */
    if (mw.config.get('wgCanonicalNamespace') == 'Project') {
        var title = mw.config.get('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 " + mw.config.get('wgPageName') + ":", "");
    if (!reason)
        return;
    if (tfdh_multi)
        var append_name = window.prompt("Enter exact name of the previous TfD you want to append " + mw.config.get('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|' + mw.config.get('wgTitle') + '}}\n', 'Appending ' + mw.config.get('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|' + mw.config.get('wgTitle') + '|text=' + reason + ' ' + tfdh_signature + ' ~~' + '~~' + '~' + '}}\n', 'Nominated ' + mw.config.get('wgPageName') + ' for deletion') + "&tfdatstring=-->", 'tfdh1w1');
    }
    if (type == 'normal') {
    	window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '{{' + 'tfd|' + subst_str + '}}', '', 'Nominated ' + mw.config.get('wgPageName') + ' for [[WP:TfD|deletion]]');
    } else if (type == 'parsed') {
    	window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '<noinclude>{{' + 'tfd|' + subst_str + '}}</noinclude>', '', 'Nominated ' + mw.config.get('wgPageName') + ' for [[WP:TfD|deletion]]');
    } else if (type == 'inline') {
    	window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '{{' + 'tfd-inline|' + subst_str + '}}', '', 'Nominated ' + mw.config.get('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|' + mw.config.get('wgTitle') + '}}' + tfdh_signature + ' ~~' + '~~' + '~' + '\n', 'Notification that ' + mw.config.get('wgPageName') + ' has been nominated for [[WP:TfD|deletion]]');
}
/* end wholescale copy to votenom.js here */

/* tfdh2 - add some categories to the template */
function add_template_category() {
    var new_cat1 = window.prompt("Provide one (and only one) category to add to this template:", "");
    if (!new_cat1)
        return;
    var new_cat = '\n[[Category:' + new_cat1 + '|{{PAGENAME}}]]'
    var edit_sum = 'Added 1 new category';
    var new_cat2 = window.prompt("Optionally provide a second (but only one) category to add to this template:", "");
    if (new_cat2) {
        new_cat += '\n[[Category:' + new_cat2 + '|{{PAGENAME}}]]';
        edit_sum = 'Added 2 new categories';
        var new_cat3 = window.prompt("Optionally provide a third (but only one) category to add to this template:", "");
        if (new_cat3) {
           new_cat += '\n[[Category:' + new_cat3 + '|{{PAGENAME}}]]';
           edit_sum = 'Added 3 new categories';
       }
    }
    var edit_sum = window.prompt("Provide a summary for this change to " + mw.config.get('wgPageName') + ":", edit_sum);
    if (!edit_sum)
        return;
    window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '', '<noinclude>' + new_cat + '</noinclude>', edit_sum) + "&tfdfind={{uncat}}&tfdpreview=true";
}

/* tfdh3 - flag this template as uncategorized - puts a noinclude'd message at the bottom of template page */
function flag_uncat_template() {
    var flag_sum = window.prompt("Provide a summary for the tagging of " + mw.config.get('wgPageName') + ":", "Tagged " + mw.config.get('wgPageName') + " as uncategorized", "");
    if (!flag_sum)
        return;
    window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '', '<noinclude>\n{{subst:dated|Uncategorized template}}</noinclude>', flag_sum);
}

/* tfdh4, tfdh7, tfdh8, tfdh15, tfdh18, tfdh19, tfdh20 - nominate template for speedy deletion */
function flag_template_csd(crit) {
    /* four general reasons */
    if (crit == 'g1') {
        var yes_no = window.prompt("Are you sure " + mw.config.get('wgPageName') + " is elegible for CSD G1 because it is patently nonsensical? (Yes or yes)", "No");
        if (yes_no == 'yes' || yes_no == 'Yes') {
            window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '{{db-g1}}\n', '', 'Requested ' + mw.config.get('wgPageName') + ' be [[WP:CSD#G1|speedily deleted]]');
        }
    } else if (crit == 'g2') {
        var yes_no = window.prompt("Are you sure " + mw.config.get('wgPageName') + " is elegible for CSD G2 because it is a test? (Yes or yes)", "No");
        if (yes_no == 'yes' || yes_no == 'Yes') {
            window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '{{db-g2}}\n', '', 'Requested ' + mw.config.get('wgPageName') + ' be [[WP:CSD#G2|speedily deleted]]');
        }
    } else if (crit == 'g6') {
        var yes_no = window.prompt("Are you sure " + mw.config.get('wgPageName') + " is elegible for CSD G6 because of technical or housekeeping reasons? (Yes or yes)", "No");
        if (yes_no == 'yes' || yes_no == 'Yes') {
            var del_word = window.prompt("Explain the technical reason (was previously TfDed, text fragment, etc.)", "");
            if (!del_word)
                return;
            window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '{{db-g6|wording=' + del_word + '}}\n', '', 'Requested ' + mw.config.get('wgPageName') + ' be [[WP:CSD#G6|speedily deleted]]');
        }
    } else if (crit == 'g7') {
        var yes_no = window.prompt("Are you sure " + mw.config.get('wgPageName') + " is elegible for CSD G7 because the only substantial contributor wanted it? (Yes or yes)", "No");
        if (yes_no == 'yes' || yes_no == 'Yes') {
            var del_rat = window.prompt("Explain what the only substantial contributor did (blanked page, improper TfD, etc.)", "");
            if (!del_rat)
                return;
            window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '{{db-g7|rationale=' + del_rat + '}}\n', '', 'Requested ' + mw.config.get('wgPageName') + ' be [[WP:CSD#G7|speedily deleted]]');
        }
    /*  three template reasons */
    } else if (crit == 't1') {
        var yes_no = window.prompt("Are you sure " + mw.config.get('wgPageName') + " is elegible for CSD T1 because it is divisive and inflammatory? (Yes or yes)", "No");
        if (yes_no == 'yes' || yes_no == 'Yes') {
            window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '{{db-t1}}\n', '', 'Requested ' + mw.config.get('wgPageName') + ' be [[WP:CSD#T1|speedily deleted]]');
        }
    } else if (crit == 't2') {
        var yes_no = window.prompt("Are you sure " + mw.config.get('wgPageName') + "  is elegible for CSD T2 because blatantly misrepresents established policy? (Yes or yes)", "No");
        if (yes_no == 'yes' || yes_no == 'Yes') {
            window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '{{db-t2}}\n', '', 'Requested ' + mw.config.get('wgPageName') + ' be [[WP:CSD#T2|speedily deleted]]');
        }
    } else if (crit == 't3') {
        var yes_no = window.prompt("Are you sure " + mw.config.get('wgPageName') + " is elegible for CSD T3 because it is not employed in any useful fashion, and are either: substantial duplications of another template, or hardcoded instances? (Yes or yes)", "No");
        if (yes_no == 'yes' || yes_no == 'Yes') {
            var other_temp = window.prompt("Give the name of the template this template duplicates (do NOT include Template:):", "");
            if (!other_temp)
                return;
            window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '{{db-t3|~~~~~|' + other_temp + '}}\n', '', 'Requested ' + mw.config.get('wgPageName') + ' be [[WP:CSD#T3|speedily deleted]]');
        }
    }
}

/* tfdh5, tfdh6 - search a specified namespace in advanced search - sometimes opens new window */
function search_namespace(ns) {
    if (ns == '14') {
         var find_term = window.prompt("Enter a category namespace search term (e.g. Austrialian navigational or rail templates):", "");
    } else if (ns == '10') {
         var find_term = window.prompt("Enter a template namespace search term (e.g. football roster or television series):", "");
    }
    if (!find_term)
        return;
    if (window.name == 'tfdh5w1') {
        window.location.href = 'http://en.wikipedia.org/w/index.php?title=Special%3ASearch&ns' + ns + '=1&search=' + escape(find_term) + '&fulltext=Advanced+search';
    } else {
        window.open('http://en.wikipedia.org/w/index.php?title=Special%3ASearch&ns' + ns + '=1&search=' + escape(find_term) + '&fulltext=Advanced+search', 'tfdh5w1');
    }
}

/* tfdh14 - add just one category to the template */
function add_one_category() {
    var new_cat = window.prompt("Provide one (and only one) category to add to this template:", "");
    if (!new_cat)
        return;
    var title = mw.config.get('wgTitle');
    if (title.match(new RegExp('^User '))) {
        title = title.replace(new RegExp('^User label ', 'i'), '');
        title = title.replace(new RegExp('^User WikiProject ', 'i'), '');
        title = title.replace(new RegExp('^User ', 'i'), '');
    } else {
        title = '{{PAGENAME}}';
    }
    window.location.href = amtfdh_make_url(mw.config.get('wgPageName'), '', '<noinclude>\n[[Category:' + new_cat + '|' + title + ']]</noinclude>', 'Added 1 new category') + "&tfdfind={{uncat}}";
}

/* tfdh16 - view the template namespace starting at a specified character string - sometimes opens new window */
function view_prefix(ns) {
    if (ns == '14') {
        var prfx_term = window.prompt("Enter a category namespace prefix (e.g. Cthulhu or Xylophone):", "");
    } else if (ns == '10') {
        var prfx_term = window.prompt("Enter a template namespace prefix (e.g. Cthulhu or Xylophone):", "");
    }
    if (!prfx_term)
        return;
    if (window.name == 'tfdh16w1') {
        window.location.href = 'http://en.wikipedia.org/w/index.php?title=Special%3APrefixIndex&from=' + escape(prfx_term) + '&namespace=' + ns;
    } else {
        window.open('http://en.wikipedia.org/w/index.php?title=Special%3APrefixIndex&from=' + escape(prfx_term) + '&namespace=' + ns, 'tfdh16w1');
    }
}

/* tfdh11, tfdh13, tfdh17, tfdh21 - removed */
/* tfdl1, tfdl2, tfdl3 - straight-up links */

/* 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;
// + "tfdpreview=true"

//</nowiki></pre>