User:NSR/monobook.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

If a message on your talk page led you here, please be wary of who left it. The code below could contain malicious content capable of compromising your account; if your account appears to be compromised, it will be blocked. If you are unsure whether the code is safe, you can ask at the appropriate village pump.
/* <nowiki> */


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

function fixformat(){
    var form = document.editform;
    var txt = form.wpTextbox1;
    txt.value = txt.value
        .replace(/<\/?(b|strong)>/gi, "'''")
        .replace(/<\/?(i|em|var)>/gi, "''")
        .replace(/\{\{([Ss]u[bp])\|([^}]+)\}\}/g, "{{subst:$1|$2}}")
        .replace(/<\/div +>/gi, "</div>");
    form.wpSummary.value += "formatting";
    form.wpMinoredit.checked = true;
}

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

function moveprotect(){
  document.getElementById('wpReasonProtect').value = "Protect from moves only";
  document.getElementById('wpMoveOnly').checked = true;
}

function vfdresult(){
    var res = prompt("Result?");
    if(!res) return;
    var form = document.editform;
    form.wpSummary.value = 'VFD result';
    var txt = form.wpTextbox1;
    txt.value += '{{oldvfdfull|date=[[DAY MONTH]] [[2005]]|result=' + res + '|votepage={{subst:PAGENAME}}}}';
    txt.focus();
}

function test(x){
    var form = document.editform;
    var txt = form.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '{{subst:test' + (x == 1 ? '' : x) + '}} &ndash; ~~~~';
    var s = '';
    switch(x){
        case 1: s = 'Thanks for your test'; break;
        case 2:
        case 3:
            s = 'Please stop';
            break;
        case 4: s = 'Last warning'; break;
        case 5: s = 'You have been blocked'; break;
    }
    form.wpSummary.value = s;
}

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 edlix(){
  var l;
  l = document.getElementById('bodyContent').getElementsByTagName('td');
  for (i = 0; i < l.length; i++) {
    if (l[i].className == 'diff-otitle') {
     l[i].getElementsByTagName('a')[0].href += "&action=edit&revertme=true"; 
     l[i].getElementsByTagName('a')[0].innerHTML += "<br>(revert vandalism)";
}
}
}


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 addlilink(tabs, url, name, id){
    var na = document.createElement('a');
    na.href = url;
    na.id = id;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.appendChild(na);
    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 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 changeLinks(){
    if(!document.getElementById) return;
    document.getElementById('pt-mytalk').firstChild.innerHTML = 'Talk';
    document.getElementById('pt-preferences').firstChild.innerHTML = 'Preferences';
    document.getElementById('pt-watchlist').firstChild.innerHTML = 'Watchlist';
    document.getElementById('pt-mycontris').firstChild.innerHTML = 'Contributions';
    document.getElementById('pt-logout').firstChild.innerHTML = 'Log out';
    document.getElementById('pt-userpage').innerHTML = makelist(usernames);
    document.getElementById('t-specialpages').innerHTML = makelist(pages);
    if(document.getElementById('ca-talk'))
        document.getElementById('ca-talk').firstChild.innerHTML = 'Talk';
    if(document.getElementById('ca-nstab-wp'))
        document.getElementById('ca-nstab-wp').firstChild.innerHTML = 'About';
    
}
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(){
    var form = document.forms.editform;
    if(!form.wpSummary.value.replace(/^(\/\*.*\*\/)? *(.*) *$/,'$2')){
      var r = prompt('Are you sure you want to submit without adding a summary?\nTo add a summary, type it in the box below:',form.wpSummary.value);
      if(r == null) return false;
      form.wpSummary.value = r;
    }
    return true;
}

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

function morelinks(){
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
      
addlilink(tabs, 'javascript:zaplink()', 'Speedy', '');     

    if(document.title.indexOf("Editing Wikipedia:Votes for deletion") == 0){
        addlilink(tabs, 'javascript:closevfd("keep", "")', 'K', '');
        addlilink(tabs, 'javascript:closevfd("merge and redirect", " to [[" + prompt("Merge and redirect to?") + "]]")', 'M&R', '');
        addlilink(tabs, 'javascript:closevfd("redirect", " to [[" + prompt("Redirect to?") + "]]")', 'R', '');
        addlilink(tabs, 'javascript:closevfd("transwiki", " to " + prompt("Transwiki to?"))', 'T', '');
        addlilink(tabs, 'javascript:closevfd("transwiki", " to Wiktionary")', 'WIKT', '');
        addlilink(tabs, 'javascript:closevfd("speedy delete", "")', 'SD', '');
        addlilink(tabs, 'javascript:closevfd("delete", "")', 'D', '');
        addlilink(tabs, 'javascript:closevfd(prompt("Result?"), "")', 'Oth', '');
    }else if(document.title.indexOf("Editing User talk:") == 0){
        addlilink(tabs, 'javascript:replace()', 'Replace', '');
        addlilink(tabs, 'javascript:fixformat()', 'Format', '');
        addlilink(tabs, 'javascript:test(1)', 'Test', '');
        addlilink(tabs, 'javascript:test(2)', '2', '');
        addlilink(tabs, 'javascript:test(3)', '3', '');
        addlilink(tabs, 'javascript:test(4)', '4', '');
        addlilink(tabs, 'javascript:test(5)', '5', '');
    }else if(document.title.indexOf("Editing ") == 0){
        addlilink(tabs, 'javascript:replace()', 'Replace', '');
        addlilink(tabs, 'javascript:fixformat()', 'Format', '');
        addlilink(tabs, 'javascript:vfdresult()', 'VFD', '');
    }else if(document.title.indexOf("Confirm delete - Delete") == 0){
        addlilink(tabs, 'javascript:vfddelete()', 'VFD', '');
    }else if(document.title.indexOf("Confirm protection - Protect") == 0){
        addlilink(tabs, 'javascript:moveprotect()', 'MV', '');
    }else if(document.title.indexOf("Wikipedia:Votes for deletion") == 0){
        addlilink(tabs, 'javascript:hidevfd()', 'Hide', 'ca-hide');
        addlilink(tabs, 'javascript:showvfd()', 'Show', 'ca-show');
    }


}

function zaplink () {
var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
location.href = editlk + '&zapme=yes';
}

function speedy() {
if (location.href.indexOf("zapme=yes") != -1) {
  document.editform.wpTextbox1.value = '{{' + 'delete}}\n' + document.editform.wpTextbox1.value;
    document.editform.wpSummary.value = 'Speedy delete';
    document.editform.submit();
}
}

function rvandal() {
if (location.href.indexOf("revertme=true") != -1) {
    document.editform.wpSummary.value = 'reverting vandalism';
    document.editform.submit();
}
}


function strip_namespace(target){
    var colon = target.indexOf(':');
    if(colon != -1){
        var spaces = ['User', 'Wikipedia', 'Image', 'MediaWiki', 'Template', 'Help', 'Category'];
        var ns = target.substring(0, colon);
        if(ns == '' || ns == 'Talk') return target.substring(colon + 1);
        else
            for(var i = 0; i < spaces.length; ++i)
                if(ns == spaces[i] || ns == spaces[i] + '_talk') return target.substring(colon + 1);
    }
    return target;
}

function vfd(){
    document.editform.wpTextbox1.value = '{{' + 'subst:vfd}}\n' + document.editform.wpTextbox1.value;
    document.editform.wpSummary.value = 'vfd';

    var target = document.editform.action;
    target = target.substring(target.indexOf('title=') + 6, target.lastIndexOf('&action=submit'));

    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    var date = new Date();
    date = date.getUTCFullYear() + '_' + months[date.getUTCMonth()] + '_' + date.getUTCDate();

    var pagename = strip_namespace(target);

    window.open('/wiki/Wikipedia:Votes_for_deletion/' + pagename + '?action=edit&fakeaction=vfdsub&faketarget=' + target, 'Vfd ' + unescape(target), 'status,toolbar,location,menubar,directories,resizeable,scrollbars');
    window.open('/wiki/Wikipedia:Votes_for_deletion/Log/' + date + '?action=edit&fakeaction=vfdlist&faketarget=' + pagename, 'VfdLog ' + unescape(target), 'status,toolbar,location,menubar,directories,resizeable,scrollbars');
}

function autovfd(){
    if(document.title.indexOf('Editing ') == 0){
        var action = getParam('fakeaction');
        var target = getParam('faketarget');
        if(action == 'vfdlist'){
            document.editform.wpTextbox1.value += '{{Wikipedia:Votes for deletion/' + target + '}}\n';
            document.editform.wpSummary.value = '[[Wikipedia:Votes for deletion/' + target + ']]';
        }else if(action == 'vfdsub'){
            if(document.editform.wpTextbox1.value.length > 0){
                target = document.editform.action;
                target = unescape(target.substring(target.indexOf('title=') + 6, target.lastIndexOf('&action=submit'))).replace(/_/g, ' ');
                window.alert("There's an old vfd at the default location already.\n\nPlease either move it out of the way (and update existing links to it), or file the Vfd by hand in another location (such as [[" + target + " (2)]]).");
            }else document.editform.wpTextbox1.value += '===[[' + target + ']]===\nReason for nomination. ~~' + '~~\n*\n*\n*\n';
        }else addlilink(document.getElementById('p-cactions').getElementsByTagName('ul')[0], 'javascript:vfd()', 'autovfd', '');
    }
}

// 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();
    var target = getParam('faketarget');
    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];
    addlilink(document.getElementById('p-cactions').getElementsByTagName('ul')[0], '/wiki/Special:Log/block?page=User:' + target, 'blocklog', '');
}

// Adds "block" and "blocklog" tabs to User: and User talk: pages.
function add_block_tab(){
    var c1 = document.getElementById('column-one');
    var tabs = document.getElementById('p-cactions').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
    addlilink(tabs, '/wiki/Special:Blockip?faketarget=' + editlk, 'block', '');
    // editcountitus on wheels!
    addlilink(tabs, 'http://tools.wikimedia.de/~kate/cgi-bin/count_edits?user=' + editlk + '&dbname=enwiki', 'Edit count', '');
    // add "blocklog" tab
    addlilink(tabs, '/wiki/Special:Log/block?page=User:' + editlk, 'blocklog', '');
}

function blockip()
{
  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();
}

function getParam(name){
    if(location.search){
        for(var x in location.search.substring(1).split('&')){
            var eq = x.indexOf('=');
            if(x.substring(0, eq) == name) return x.substring(eq + 1);
        }
    }
    return '';
}

function sandbox () {
/*
alert('Mia Hu');
alert(location.href.indexOf("zapme=yes"));
*/
}

function myLoadFuncs(){
    addPurge();
    addEditSection0();
 changeLinks();
    addForceSummary();
    edlix();
    morelinks();
    speedy();
    rvandal();
    addToolBoxLinks();
    autovfd();
    blockip();
    sandbox();
}
if (window.addEventListener) window.addEventListener("load",myLoadFuncs,false);
else if (window.attachEvent) window.attachEvent("onload",myLoadFuncs);
else{
    window._old_ABCD_onload = window.onload;
    window.onload = function(){
        window._old_ABCD_onload();
        myLoadFuncs();
    }
}

usernames = new Array( "NSR", "Phroziac", "RickK", "Linuxbeak", "Smoddy")	
pages = new Array("SIGN", "AN/I", "AN",  "AFD")

function makelist (array) {

code = "<select>"

for (i = 0; i < array.length; i++) {

code += "<option>"+array[i]+"</option>";

}

code += "</select>"

return code;

}	

/* </nowiki> */