Jump to content

User:Thetrick/tfd helper/userfy.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>
 
/**************** Userfy ****************/
/* userfication of templates - advanced */

importScript("User:Thetrick/tfd_helper/automodtfdh.js");

/* this function runs at load */
function userfy_helper() {
    /* call auto mod first, exit if it did processing */
    if (auto_mod_tfdh())
       return;
    if (wgCanonicalNamespace == 'Template' && wgIsArticle == true) {
        amtfdh_add_li('tb', 'javascript:userfy_template("req")', 'Userfy: request', 'usrf1', 'Request that a user move this template into their user pages');
        amtfdh_add_li('tb', 'javascript:userfy_template("not")', 'Userfy: notify', 'usrf2', 'Notify a user that this template has been userfied');
        //amtfdh_add_li('tb', 'javascript:userfy_template("do")', 'Userfy: perform', 'usrf3', 'Userfy this template and notify user');
     }
}

/* usrf1, usrf2, usrf3 - deal with userfication */
function userfy_template(userfy) {
    var userfy_name = window.prompt("Enter the name of the user (e.g. Fred or PunkerDude999)", "");
    if (!userfy_name)
        return;
    if (userfy == "req") {
        window.location.href = amtfdh_make_url('User_talk:' + userfy_name, '', '\n\n{{subst:User:Thetrick/Userfy-request|' + wgTitle + '|' + userfy_name + '}}', 'Request for template move');
    } else if (userfy == "not") {
        var userfy_page = window.prompt("Enter the name of the new page (e.g. Yourtemplate or Sandbox/Templatehere)");
        if (!userfy_page)
            return;
        window.location.href = amtfdh_make_url('User_talk:' + userfy_name, '', '\n\n{{subst:User:Thetrick/Userfied|' + wgTitle + '|' + userfy_name + '/' + userfy_page + '}}', 'Notification of template move');
    } else if (userfy == "do") {
        var userfy_page = window.prompt("Enter the name of the new page (e.g. Yourtemplate or Sandbox/Templatehere)");
        if (!userfy_page)
            return;
        var movewindow = window.open("http://en.wikipedia.org/wiki/Special:MovePage/" + wgPageName, "usrfy1");
        //movewindow.setfocus;
        movewindow.getElementById('wpNewTitle').value = 'User:/' + userfy_name + '/' + userfy_page;
        //window.location.href = amtfdh_make_url('User_talk:' + userfy_name, '', '\n\n{{subst:User:Thetrick/Userfied|' + wgTitle + '|' + userfy_name + '/' + userfy_page + '}}' + "&tfdpreview=true", 'Notification of template move');
    }
}

/* run a register function */
$(userfy_helper);

//bits of test code sit here
//    var yes_no = window.prompt('Here is the url', am_make_url(here, here, here, here));
//    return;
 
//</nowiki></pre>