User:Wayward/monobook.js

From Wikipedia, the free encyclopedia

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.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
/* <pre><nowiki> */
 
/**
 * [[User:Wayward]]'s monobook.js, based on [[User:Alphax/monobook.js]]
 * Must use [[User:Wayward/monobook.css]] for full tab functionality
 * Only tested with Firefox and admin rights
 * Looks like hell on IE with the current .css and may not be fully functional
 * A version of this script with more AfD helps can be found at [[User:Wayward/monobook.full]]
 * Forked from [[User:ABCD/monobook.js]] around April 2005
 * Dual licensed under the GFDL and GPL
 * See also: [[User:JesseW/monobook.js]]
 * And best of all: [[WP:US]]
 */
 
/**** Begin ****/
 
// [[User:Lupin/popups.js]] - please include this line 
document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
simplePopups=true;
popupAdminLinks=true;
popupStructure='menus';
 
/**** afd helper ****/
 
// From [[User:Jnothman/afd_helper/script.js]]
 
document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Jnothman/afd_helper/script.js&action=raw&ctype=text/javascript&dontcountme=s"><\/script>');
 
 
/**** Load custom functions ****/
 
addOnloadHook( myLoadFuncs );
 
function myLoadFuncs()
{
    // &action=purge
    addPurge();
 
    // &section=0
    addEditSection0();
 
    // cause the personal menu looks bad
    changeLinks();
 
    // load tabs
    add_tabs();
 
    // add toolbox links
    addToolBoxLinks();
 
    // add navigation bar links
    addNavBarLinks();
 
    // make red talk page links start new sections
    talkpageplus();
 
    // change the title of the edit link
    //ta['ca-edit'] = ['e', 'Edit page'];
 
    // remove the logout access key
    //ta['pt-logout'] = new Array(null, null);
 
    // re-render the title and accesskeys for stuff
    akeytt();
 
    // add history link to new messages box
    newmessagehistory();
 
    // add block and block IP tabs
    blockip();
 
}
 
/**** Edit section 0 ****/
 
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').getElementsByTagName("ul")[0].insertBefore(y,x.nextSibling);
    }
}
 
/**** Make the top links look better ****/
 
function changeLinks()
{
    if(!document.getElementById) return;
    // remove the "my" bits
    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';
    // Get the top toolbar
    var toplinks = document.getElementById('p-personal').getElementsByTagName('ul')[0];
    // remove the logout button entirely
    toplinks.removeChild(document.getElementById('pt-logout'));
    // add a clock
    addlilink(toplinks, '#', '', 'utcdate');
    showtime();
}
 
/**** Add generic tab ****/
 
function addlilink(tabs, url, name, id)
{
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    //return li;
}
 
/**** Add tab as menu ****/
 
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;
}
 
/**** Add purge tab ****/
 
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];
 
    var pf = document.createElement('form');
    pf.action = '?action=purge';
    pf.method = 'POST';
    pf.id = 'pf';
    x.appendChild(pf);
 
    addlilink(tabs, 'javascript:document.getElementById("pf").submit();', 'purge', 'ca-purge');
}
 
/**** Add block and blocklog tabs ****/
 
function addTab(url, name, id, title, key){ 
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    addlilink(tabs, url, name, id, title, key);
}
 
// Adds a "blocklog" tab and fills in the username field on Special:Blockip, if a "&ip=username" is present.
function do_blockip_stuff()
{
    var form = document.getElementById('blockip');
    // focus on Reason field
    form.wpBlockReason.focus();
    var target = getParam('ip');
    if(target == '') return;
 
    // add "blocklog" tab
    addTab('/wiki/Special:Log/block?page=User:' + target, 'blocklog', 'ca-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
    addTab('/wiki/Special:Blockip/' + editlk, 'block', 'ca-block');
 
    // add "blocklog" tab
    addTab('/wiki/Special:Log/block?page=User:' + editlk, 'blocklog', 'ca-blocklog');
 
    // add "edit count" tab
    //addTab('http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwiki_p&user=' + editlk, 'ecount', 'ca-ecount');  
}
 
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 '';
}
 
/**** Talk message functions ****/
 
// Add date to talk page
function add_date(date)
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += date;
}
 
 
// Add test-n templates to user talk pages
function testn(number)
{
  var page = prompt("Vandalism to which article?")
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += "{{subst:uw-vandalism" + number + "|" + page + "|subst=subst:}} ~~~~";
  f.wpSummary.value = "Your edits to [[" + page + "]]"
  document.editform.wpWatchthis.checked = false; 
  document.editform.wpMinoredit.checked = false;
}
 
// Add duration for s/block                                
function duration(number)                                             
{                                                                    
  var duration = prompt("Block duration")                            
  var f = document.editform, t = f.wpTextbox1;                        
  if (t.value.length > 0)                                             
    t.value += '\n';                                                   
  t.value += "{{subst:uw-block2|time=" + duration + "|reason=[[Wikipedia:Vandalism|repeated abuse of editing privileges]]|subst=subst:}}";     
  f.wpSummary.value = "You have been blocked for " + duration + ""    
  document.editform.wpWatchthis.checked = false;  
  document.editform.wpMinoredit.checked = false;                                                       
}
 
// Add page for rvfd                                                
function rvfd(number)                                                
{                                                                    
  var page = prompt("Vandalism to which AfD candidate?")             
  var f = document.editform, t = f.wpTextbox1;                            
  if (t.value.length > 0)                                            
    t.value += '\n';                                                
  t.value += "{{subst:rvfd|" + page + "}} ~~~~";                       
  f.wpSummary.value = "Your edits to [[" + page + "]]"                
  document.editform.wpWatchthis.checked = false;  
  document.editform.wpMinoredit.checked = false;                                                         
}
 
// Add vanity article
function vanity(number)
{
  var page = prompt("Article")             
  var f = document.editform, t = f.wpTextbox1;                            
  if (t.value.length > 0)                                            
    t.value += '\n';                                                
  t.value += "{{subst:vanity|" + page + "}} ~~~~";                       
  f.wpSummary.value = "[[" + page + "]]"                
  document.editform.wpWatchthis.checked = false; 
  document.editform.wpMinoredit.checked = false; 
}
 
// Appends msg to the currently editted page, sets the summary to summ,
// marks or unmarks the "Watch this page" checkbox according to watch,
// and marks or unmarks the "Minor edit" checkbox
function edit_summary_watch(msg, summ, watch, minor)
{
  var f = document.editform, t = f.wpTextbox1;
  if (t.value.length > 0)
    t.value += '\n';
  t.value += msg;
  f.wpSummary.value = summ;
  f.wpWatchthis.checked = watch;
  f.wpMinoredit.checked = minor;
}
 
// Places perm block and name block tags at top of edit section,         
// marks or unmarks the "Watch this page" checkbox according to watch,
// and marks or unmarks the "Minor edit" checkbox 
function perm_name_block(msg, summ, watch, minor)                                
{                                                                          
  var f = document.editform, t = f.wpTextbox1;                            
  if (t.value.length > 0)                                                
      t.value += '\n';                                                  
  var temp = t.value;                                                    
  t.value = msg + '\n\n' + temp;                                                                                                            
  f.wpSummary.value = summ;                                                
  f.wpWatchthis.checked = watch; 
  f.wpMinoredit.checked = minor;
}
 
/**** Integrate tabs and talk message functions ****/
 
// adds various tabs and menu tabs
function add_tabs()
{
  var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    // Only add for pages with "Editing User talk:" somewhere in the title
  if (document.title.indexOf("Editing User talk:") != -1)
     {
      addlimenu(tabs, 'Talk messages', 'talkm');
      var talkm = document.getElementById('talkm').getElementsByTagName('ul')[0];
      addlilink(talkm,'javascript:add_date("==" + "{{subst:CURRENTMONTHNAME}} {{subst:CURRENTDAY}}\, {{subst:CURRENTYEAR}}" + "==", 1)','Add Date', '');
      addlilink(talkm,'javascript:testn(1)', 'Test1', '');
      addlilink(talkm,'javascript:testn(2)','Test2', '');
      addlilink(talkm,'javascript:testn(3)','Test3', '');
      addlilink(talkm,'javascript:testn(4)','Test4', '');
      addlilink(talkm,'javascript:duration(1)', 'Temp Block', ''); 
      addlilink(talkm,'javascript:perm_name_block("{{subst:uw-block3|time=duration|reason=repeated [[Wikipedia:Vandalism|abuse of editing privileges]]|subst=subst:}}", "You have been indefinitely blocked", true, false, 1)','Perm Block', ''); 
      addlilink(talkm,'javascript:perm_name_block("{{subst:usernameblock}} ~~~~", "{{usernameblock}}", true, false, 1)','Name Block', ''); 
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:uw-bv|subst=subst:}} ~~~~", "Vandalism", false, false, 1)','BV', '');
      addlilink(talkm,'javascript:vanity(1)', 'Vanity', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam1}} ~~~~", "Adding links to Wikipedia", false, false, 1)','Spam1', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam2}} ~~~~", "Spamming", false, false, 1)','Spam2', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam3}} ~~~~", "Last warning for spamming", false, false, 1)','Spam3', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam4}} ~~~~", "You have been blocked for spamming", false, false, 1)','Spam4', '');
      addlilink(talkm,'javascript:rvfd(1)', 'rvfd', ''); 
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:blanking}} ~~~~", "Blanking pages", false, false, 1)','blanking', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:nothanks|}} ~~~~", "About your edits", false, false, 1)','nothanks', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:nothanks-sd|pg=page name|url=url of source}} ~~~~", "{{nothanks-sd}}", false, false, 1)','nothanks-sd', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:Welcome}} ~~~~", "Welcome to Wikipedia!", true, false, 1)','Welcome', '');
      addlilink(talkm,'javascript:edit_summary_watch("{{subst:Anon}}  ~~~~", "Welcome to Wikipedia!", true, false, 1)','Anon', '');
    }
}
 
/**** Add links to the toolbox ****/
 
function addToolBoxLinks()
{
    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
    addlilink(tb, '/wiki/Special:Ipblocklist', 'IPBlocklist', ''); 
    addlilink(tb, '/w/index.php?title=Special:Ipblocklist&action=unblock&ip=', 'Unblock page', '');            
    addlilink(tb, '/wiki/Wikipedia:Template messages/User_talk_namespace', 'Talk templates', '');
    addlilink(tb, '/wiki/Wikipedia:Template_messages', 'Templates', '');
    addlilink(tb, '/wiki/WP:CSD', 'SD criteria', '');
    addlilink(tb, 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwiki_p&user=Wayward', 'My edit count', '');
    //addlilink(tb, '/wiki/Special:Log/delete', 'Delete log', '');
    //addlilink(tb, '/wiki/Category:Wikipedia spam cleanup', 'Spam cleanup', '');
    username_a = document.URL.match(/:.*:(.*)/);
    username=username_a[1];
    addlilink(tb, 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwiki_p&user=' + username, 'User\'s edit count', '');
    addlilink(tb, '/wiki/Special:Log', 'Log', '');
    addlilink(tb, '/wiki/Category:Requests for unblock', 'Unblock requests', ''); 
}
 
/**** Add links to the navigation bar  ****/
 
function addNavBarLinks()
{   
    var navbar = document.getElementById('p-navigation').getElementsByTagName('ul')[0];
    var afdtime = new Date();
    var months = ['January', 'February', 'March', 'April', 'May', 'June',
        'July', 'August', 'September', 'October', 'November', 'December'];
    addlilink(navbar, '/wiki/Wikipedia:Articles_for_deletion/Log/' + afdtime.getUTCFullYear()
        + '_' + months[afdtime.getUTCMonth()] + '_' + afdtime.getUTCDate(), 'Todays AfD', '');
    afdtime.setUTCDate(afdtime.getUTCDate() - 5);
    addlilink(navbar, '/wiki/Wikipedia:Articles_for_deletion/Log/' + afdtime.getUTCFullYear()
        + '_' + months[afdtime.getUTCMonth()] + '_' + afdtime.getUTCDate(), '5-day-old AfD', '');
    var username=document.getElementById("pt-userpage").textContent;
  //addlilink(navbar, '/w/index.php?title=User:' + username + '/Status&action=edit', 'Edit my status', '');
    addlilink(navbar, '/w/index.php?title=User:' + username + '/monobook.js&action=edit', 'monobook.js', '');   
    addlilink(navbar, '/w/index.php?title=User:' + username + '/monobook.css&action=edit', 'monobook.css', ''); 
    addlilink(navbar, '/wiki/User:Wayward/Sandbox', 'My sandbox', ''); 
}
 
/**** Get a clock that autoupdates! ****/
 
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);
}
 
/**** Auto start new topics when hitting empty talk pages from the content page ****/
 
function talkpageplus()
{
    var talkpagelink = document.getElementById('ca-talk');
    if (talkpagelink.className == 'new')
    {
        talkpagelink.firstChild.href += '&section=new';
    }
}
 
/**** Add history link to the "You have new messages" box ****/
 
function newmessagehistory()
{
    var divs = document.getElementsByTagName('div');
    var talkmessagebox;
 
    for(var x = 0; x < divs.length; ++x)
    {
        if(divs[x].className.indexOf('usermessage') != -1)
        {
            talkmessagebox = divs[x];
            x = divs.length; // force break
        }
    }
 
    divs = ''; // release divs?
    if(!talkmessagebox) return false;
 
    var newmessagelink = talkmessagebox.getElementsByTagName('a')[0];
 
    var historylink = document.createElement('a');
    historylink.href = newmessagelink.href.replace(/\/wiki\//, '/w/index.php?title=') + '&action=history';
    historylink.className = 'extiw';
    historylink.appendChild(document.createTextNode('history'));
 
    // var talkmessagetext = 'You have ';
    // talkmessagebox.innerHTML = talkmessagetext;
    // talkmessagebox.appendChild(newmessagelink);
    talkmessagebox.appendChild(document.createTextNode(' ('));
    talkmessagebox.appendChild(historylink);
    talkmessagebox.appendChild(document.createTextNode(')'));
}
 
/**** Add "unwatch" link to watchlist ****/
 
*/
 
addOnloadHook(function () {
 
    // Check if we're on the watchlist
    if (!wgCanonicalSpecialPageName || wgCanonicalSpecialPageName != "Watchlist") return;
    if (!document.forms[0] || !document.forms[0].namespace) return;
 
    // Unwatch links go back to watchlist with "Removing requested items from watchlist..." message
    var query_prefix = "title="+encodeURIComponent(wgPageName)+"&action=submit&remove=1&id[]=";
 
    // ...or...
    // Unwatch links go to "Removed from watchlist" page
    //var query_prefix = "action=unwatch&title=";
 
    // get list of all links in content:
    var links = document.getElementById('content').getElementsByTagName('a');
 
    // make a static copy of the nodelist and lose the original for speed
    // while we're at it, prune the uninteresting links from the list
    var linksCopy = new Array ();
    for (var i = 0; i < links.length; i++) {
        if (/[?&]action=history([&#]|$)/.test(links[i].href)) linksCopy.push(links[i]);
    }
    links = linksCopy;
 
    for (var i = 0; i < links.length; i++) {
        // create unwatch link and append it after history link
        var unwatch = document.createElement('a');
        unwatch.href = wgServer + wgScriptPath + "/index.php?" + query_prefix + encodeURIComponent(links[i].title);
        unwatch.title = "Unwatch "+links[i].title;
        unwatch.appendChild(document.createTextNode("unwatch"));
        links[i].parentNode.insertBefore(unwatch, links[i].nextSibling);
 
        // insert a delimiter between the two links
        var delim = links[i].previousSibling;
        delimText = (delim.nodeType == 3 ? delim.nodeValue : ""); // kluge to handle case where "diff" is unlinked
        delim = document.createTextNode(delimText.replace(/^.*diff/, ""));
        links[i].parentNode.insertBefore(delim, unwatch);
    }
});
 
// 
 
/**** End ****/
 
/* </nowiki></pre> */