User:Func/wpfunc/bratsche.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.
/* <nowiki> */

/**
 * Extra tabs for monobook skin
 * Forked from [[User:ABCD/monobook.js]] around April 2005
 * Dual licensed under the GFDL and GPL
 * See also: [[User:JesseW/monobook.js]]
 */

/**** Initialise on window load ****/

if (window.addEventListener) window.addEventListener("load",myLoadFuncs,false);
else if (window.attachEvent) window.attachEvent("onload",myLoadFuncs);
else
{
    window.previousLoadFunction = window.onload;
    window.onload = function()
    {
        window.previousLoadFunction();
        myLoadFuncs();
    }
}

/**** Load custom functions ****/

function myLoadFuncs()
{
    // &action=purge
    addPurge();
    // &section=0
    addEditSection0();
    // cause the personal menu looks bad
    changeLinks();
    // because edit summaries are good
    addForceSummary();
    // if this is VFD, add the show/hide thingies
    if(document.title.indexOf("Wikipedia:Votes for deletion") != -1 && document.title.indexOf("Editing ") != 0) vfdlinks();
    // now add a million extra tabs
    morelinks();
    // and some stuff for the sidebar
    addToolBoxLinks();
    // for admins only...
    // if(document.title.indexOf("Confirm delete - Delete") == 0) addVfdLink();
    // change the title of the edit link
    ta['ca-edit'] = ['e', 'Edit page'];
    // re-render the title and accesskeys for stuff
    akeytt();
}

/**** Extra tab adding ****/

function addEditSection0()
{
    ta['ca-edit-0'] = ['', 'Edit the zeroth section of this page'];
    if(!document.getElementById) return;
    var x = document.getElementById('ca-edit');
    if(!x) return;
    var y = document.createElement('LI');
    y.id = 'ca-edit-0';
    if(x.className == 'selected'){
      if(/&action=edit&section=0$/.test(window.location.href)){
        x.className = 'istalk';
        y.className = 'selected';
      } else {
        x.className = 'selected istalk';
      }
    } else if(x.className == 'selected istalk'){
      if(/&action=edit&section=0$/.test(window.location.href)){
        x.className = 'istalk';
        y.className = 'selected istalk';
      } else {
        y.className = 'istalk';
      }
    } else {
      y.className = x.className;
      x.className = 'istalk';
    }
    var z = document.createElement('A');
    if(x.children){
        z.href = x.children[0].href + '&section=0';
        z.appendChild(document.createTextNode('0'));
        y.appendChild(z);
        document.getElementById('p-cactions').children[1].insertBefore(y,x.nextSibling);
    }else{
        z.href = x.childNodes[0].href + '&section=0';
        z.appendChild(document.createTextNode('0'));
        y.appendChild(z);
        document.getElementById('p-cactions').childNodes[3].insertBefore(y,x.nextSibling);
    }
}

function addlilink(tabs, url, name, id){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}

function addlimenu(tabs, name, id)
{
    var na = document.createElement('a');
    na.href = '';
    var mn = document.createElement('ul');
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.className = 'tabmenu';
    li.appendChild(na);
    li.appendChild(mn);
    tabs.appendChild(li);
    return li;
}

function addPurge()
{
    ta['ca-purge'] = ['g', 'Purge the internal cache for this page'];
    if(!document.getElementById) return;
    var x = document.getElementById('ca-history');
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if(!x) return;
    if(x.children) x = x.children[0];
    else x = x.childNodes[0];
    addlilink(tabs, x.href.replace(/=history/, "=purge"), 'purge', 'ca-purge');
}

function closevfd(bold, notbold)
{
  var txt = document.editform.wpTextbox1;
  txt.value = "{{subst:vt}} '''" + bold + "'''" + notbold + ". &ndash; ~~~~\n" + txt.value + "\n{{subst:vb}}\n";
  txt = document.editform.wpSummary;
  txt.value = "close discussion: " + bold + notbold;
  document.editform.wpWatchthis.checked = false;
}

function editSummary()
{
    var txt = document.editform.wpTextbox1;
    document.editform.wpSummary.value = 'Edit summary';
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '{{subst:edit summary}} ~~~~';
    txt.focus();
}

function startThread()
{
    var txt = document.editform.wpTextbox1;
    var which = prompt("Thread number?");
    var now = new Date();
    if(which < 10) which = '0' + which;
    var timestamp = now.getUTCFullYear() + '';
    now.getUTCMonth() < 9 ? timestamp += '0' + (now.getUTCMonth() + 1) : timestamp += (now.getUTCMonth() + 1);
    now.getUTCDate() < 10 ? timestamp += '0' + now.getUTCDate() : timestamp += now.getUTCDate();
    txt.value += '\n{{User talk:Alphax/' + timestamp + '-' + which + '}}';
    document.editform.wpSummary.value = 'new thread';
}

function welcomeMessage()
{
    document.editform.wpSummary.value = 'Welcome to Wikipedia!';
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '{{subst:User:Alphax/Welcome}} ~~~~';
    txt.focus();
}

function anonWelcome()
{
    document.editform.wpSummary.value = 'Create an account!';
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '{{subst:anon}} Thanks, ~~~~';
    txt.focus();
}

function replace()
{
    var s = prompt("Search regexp?");
    if(s){
        var r = prompt("Replace regexp?");
        var txt = document.editform.wpTextbox1;
        txt.value = txt.value.replace(new RegExp(s, "g"), r);
    }
}

function vfdresult()
{
    var res = prompt("Result?");
    var vfddate = prompt("Nomination date?");
    if(!res) return;
    document.editform.wpSummary.value = 'VFD result - ' + res.replace(/'/g, '');
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '==VFD==\nOn [[' + vfddate + ']] [[{{subst:CURRENTYEAR}}]], this article was nominated for deletion. The result was ' + res + '. See [[Wikipedia:Votes for deletion/{{subst:PAGENAME}}]] for a record of the discussion. &ndash; ~~~~';
    txt.focus();
}

function hidevfd()
{
    var divs = document.getElementsByTagName("div");
    for(var x = 0; x < divs.length; ++x)
        if(divs[x].className.indexOf("vfd") != -1)
            divs[x].style.display = "none";
    document.getElementById('footer').style.display = 'none';
}

function showvfd()
{
    var divs = document.getElementsByTagName("div");
    for(var x = 0; x < divs.length; ++x)
        if(divs[x].className.indexOf("vfd") != -1)
            divs[x].style.display = "";
    document.getElementById('footer').style.display = '';
}

function vfdlinks()
{
    if(!document.getElementById) return;
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    addlilink(tabs, 'javascript:hidevfd()', 'hide closed', 'ca-hide');
    ta['ca-hide'] = ['', 'Hide closed VFDs'];
    addlilink(tabs, 'javascript:showvfd()', 'show closed', 'ca-show');
    ta['ca-show'] = ['', 'Show closed VFDs'];
}

function changeLinks()
{
    if(!document.getElementById) return;
    // remove the "my" bits
    document.getElementById('pt-mytalk').firstChild.innerHTML = 'talk';
    document.getElementById('pt-watchlist').firstChild.innerHTML = 'watchlist';
    document.getElementById('pt-mycontris').firstChild.innerHTML = 'contributions';
    if(document.getElementById('ca-edit'))
    document.getElementById('ca-edit').firstChild.innerHTML = 'Edit';
    // add a clock
    var toplinks = document.getElementById('p-personal').getElementsByTagName('ul')[0];
    addlilink(toplinks, '', '', 'utcdate');
    showtime();
}

function addForceSummary(){
    if(!/&action=edit/.test(window.location.href)) return;
    if(/&section=new/.test(window.location.href)) return;
    if(!document.forms.editform) return;
    document.forms.editform.wpSave.onclick = forceSummary;
}

function forceSummary(){
    if(!document.forms.editform.wpSummary.value.replace(/^(?:\/\\*.*\\*\/)? *(.*) *$/,'$1')){
      var r = prompt('Are you sure you want to submit without adding a summary?\nTo add a summary, type it in the box below:',document.forms.editform.wpSummary.value);
      if(r == null) return false;
      document.forms.editform.wpSummary.value = r;
    }
    return true;
}

function vfddelete(){
    var form = document.forms.deleteconfirm;
    form.wpReason.value = '[[Wikipedia:Votes for deletion/' + unescape(window.location.href.replace(/^.*\?title=([^&]+)&action=delete.*$/, '$1').replace(/_/g, ' ')) + ']]';
    form.wpConfirm.checked = true;
}

function morelinks(){
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if(document.title.indexOf("Editing Wikipedia:Votes for deletion") == 0)
    {
        addlimenu(tabs, 'vfd actions', 'vfda');
        var vfda = document.getElementById('vfda').getElementsByTagName('ul')[0];
        addlilink(vfda, 'javascript:closevfd("keep", "")', 'keep', '');
        addlilink(vfda, 'javascript:closevfd("merge and redirect", " to [[" + prompt("Merge and redirect to?") + "]]")', 'merge', '');
        addlilink(vfda, 'javascript:closevfd("redirect", " to [[" + prompt("Redirect to?") + "]]")', 'redir', '');
        addlilink(vfda, 'javascript:closevfd("transwiki", " to " + prompt("Transwiki to?"))', 'trans', '');
        addlilink(vfda, 'javascript:closevfd("transwiki", " to Wiktionary")', 'wikt', '');
        addlilink(vfda, 'javascript:closevfd("speedy delete", "")', 'speedy', '');
        addlilink(vfda, 'javascript:closevfd("delete", "")', 'del', '');
        addlilink(vfda, 'javascript:closevfd(prompt("Result?"), "")', 'other', '');
        addlilink(tabs, 'javascript:replace()', 'replace', '');
    }
    else if(document.title.indexOf("Confirm delete - Delete") == 0)
    {
        addlilink(tabs, 'javascript:vfddelete()', 'vfd', '');
    }
    else if(document.title.indexOf("Editing User talk:") == 0)
    {
        addlilink(tabs, 'javascript:replace()', 'replace', '');
        addlimenu(tabs, 'talk messages', 'talkm');
        var talkm = document.getElementById('talkm').getElementsByTagName('ul')[0];
        addlilink(talkm, 'javascript:welcomeMessage()', 'welcome', '');
        addlilink(talkm, 'javascript:anonWelcome()', 'anon', '');
        addlilink(talkm, 'javascript:startThread()', 'thread', '');
        addlilink(talkm, 'javascript:editSummary()', 'summary', '');
    }
    else if(document.title.indexOf("Editing ") == 0)
    {
        addlilink(tabs, 'javascript:replace()', 'replace', '');
        addlilink(tabs, 'javascript:vfdresult()', 'vfd result', '');
    }


}

function addToolBoxLinks()
{
    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
    addlilink(tb, '/wiki/Special:Newpages', 'New pages', '');
    addlilink(tb, '/wiki/Special:Shortpages', 'Short pages', '');
    addlilink(tb, '/wiki/Special:Log', 'Logs', '');
    addlilink(tb, '/wiki/Template:Deletiontools', 'Deletion tools', '');
    addlilink(tb, '/wiki/Wikipedia:Disambiguation_pages_with_links', 'Dab list', '');
    addlilink(tb, '/wiki/Wikipedia:Template_messages/User_talk_namespace', 'Talk messages', '');
    addlilink(tb, '/wiki/User_talk:Alphax/special', 'Special characters', '');
    addlilink(tb, '/wiki/WP:ICT', 'Image Copyright tags', '');
}

function showtime()
{
    var timerID;
    var now = new Date();
    var timeValue = now.toUTCString().replace(/GMT/, "UTC");
    document.getElementById('utcdate').firstChild.innerHTML = timeValue;
    timerID = setTimeout('showtime()', 100);
}


// Returns <li><a href="url">name</a></li>
function addlilink_BOTTOM(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);

  var txt = document.createTextNode(name);
  na.appendChild(txt);

  var li = document.createElement('li');
  li.appendChild(na);
  return li;
}

// Adds a "blocklog" tab and fills in the username field on Special:Blockip, if a "&faketarget=username" is present.
function do_blockip_stuff()
{
  // focus on Reason field
  document.getElementsByName('wpBlockReason')[0].focus();

  // Look for a &faketarget= for the username/ip
  var l = location.search.substring(1).split('&');
  var target = '';
  for (var i = 0; i < l.length; ++i)
    {
      var n = l[i].indexOf('=');
      if (l[i].substring(0, n) == 'faketarget')
	{
	  target = l[i].substring(n + 1);
	  break;
	}
    }

  if (target == '')
    return;

  // put account name in "IP Address/username" field
  var addr = document.getElementsByName('wpBlockAddress')[0];
  addr.value = unescape(target);

  // add "blocklog" tab
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
  tabs.appendChild(addlilink_BOTTOM('/w/index.php?title=Special%3ALog&type=block&user=&page=User%3A' + target, 'blocklog'));
}

// Opens the block log in the current window, and Special:Blockip in a popup.
// Width, height, top, and left are chosen for a 1600x1200 display.
//function blockpage_and_log(target)
//{
//  window.open('Special_Blockip.html?foo=blarg&faketarget=' + target, 'Block', 'width=1600,height=600,top=600,left=0');
//  document.location.href = 'http://en.wikipedia.org/w/index.php?title=Special%3ALog&type=block&user=&page=User%3A' + target;
//}

// Adds "block" and "blocklog" tabs to User: and User talk: pages.
function add_block_tab()
{
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];

  // use the "edit this page" tab to get already-tidied url
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  // cut everything up to "title=" from the start and everything past "&action=edit" from the end
  editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.lastIndexOf('&action=edit'));
  editlk = editlk.substring(editlk.indexOf(':') + 1);
  var slloc = editlk.indexOf('/');
  if (slloc > 0)
    editlk = editlk.substring(0, slloc);

  // add "block" tab
  tabs.appendChild(addlilink_BOTTOM('/w/index.php?title=Special%3ABlockip&faketarget=' + editlk, 'block'));

  // To open the block page and block log simultaneously, replace the above line with:
  // tabs.appendChild(addlilink_BOTTOM('javascript:blockpage_and_log("' + editlk + '")', 'Block'));
  // and uncomment the blockpage_and_log() function above.

  // add "blocklog" tab
  tabs.appendChild(addlilink_BOTTOM('/w/index.php?title=Special%3ALog&type=block&user=&page=User%3A' + editlk, 'blocklog'));

  //add "contributions" tab
  tabs.appendChild(addlilink_BOTTOM('/w/wiki.phtml?title=Special:Contributions&target=User%3A' + editlk, 'contributions'));

}

function do_onload()
{
  if (document.title.indexOf('User:') == 0
      || document.title.indexOf('User talk:') == 0)
    add_block_tab();
  else if (document.title.indexOf('Block user') == 0) // could stand to be more robust
    do_blockip_stuff();
}

if (window.addEventListener) 
  window.addEventListener("load", do_onload, false);
else if (window.attachEvent) 
  window.attachEvent("onload", do_onload);

/* </nowiki> */