User:Cumbrowski/monobook.js

/**** Initialise on window load and load custom functions ****/ function myLoadFuncs { // &section=0 //addEditSection0; // cause the personal menu looks bad changeLinks; // and some stuff for the sidebar addToolBoxLinks; // make red talk page links start new sections talkpageplus; // now add a million extra tabs Addmorelinks; // add history link to new messages box newmessagehistory; //add more links to nav bar morelinks; }

// Live Preview customization, // edit this to your own liking.

var wpLanguageCode = 'en'; var wpUserNamespace = 'User'; var wpImageNamespace = 'Image'; var wpCategoryNamespace = 'Category'; var wpUserName  = 'Cumbrowski';   // User name to display in signatures var wpShowImages = true;     // Enable downloading and displaying of images var wpImageBasePath = 'http://upload.wikimedia.org/wikipedia/'+wpLanguageCode+'/';

// Now set everything up //window.onload = Main;

function AddOnload(myfunc) { if(window.addEventListener) window.addEventListener('load', myfunc, false); else if(window.attachEvent) window.attachEvent('onload', myfunc); } AddOnload(Main);

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

//-- // Function Main. Add Other Extensions as Function(s) and Excecute from this Funtion //-- function Main { myLoadFuncs; }

//-- // External JS Scripts //--

/**** 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').childNodes[3].insertBefore(y,x.nextSibling); } }

/**** 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'); li.id = id; li.appendChild(na); tabs.appendChild(li); return li; }

function addlilinkbold(tabs2, url2, name2, id2){ var na2 = document.createElement('a'); na2.href = url2; na2.appendChild(document.createTextNode(name2)); na2.className = 'boldlnk'; var li2 = document.createElement('li'); li2.id = id2; li2.appendChild(na2); tabs2.appendChild(li2); return li2; }

/**** 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; }

/**** Generic custom talk message ****/

function autoMessage(msgtext, summary, saveopt) {   var txt = document.editform.wpTextbox1; document.editform.wpSummary.value = summary; if(txt.value.length > 0) txt.value += '\n'; txt.value += msgtext; if(saveopt == 'save') {       document.editform.submit; }   else if(saveopt == 'preview') {       document.editform.wpPreview.click; }   else if(saveopt == 'diff') {       document.editform.wpDiff.click; } }

/**** Get the pagename for a specified thread ****/

function startThread {   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; return ''; }

/**** Make the top links look better ****/

function changeLinks {   if (!document.getElementById('p-personal')) return; // remove the "my" bits //   document.getElementById('pt-mytalk').firstChild.innerHTML = 'talk 2 me'; document.getElementById('pt-preferences').firstChild.innerHTML = 'settings'; document.getElementById('pt-watchlist').firstChild.innerHTML = 'watch dog'; document.getElementById('pt-mycontris').firstChild.innerHTML = 'my mess'; //   document.getElementById('n-currentevents').firstChild.innerHTML = 'News'; //   document.getElementById('n-Portals').firstChild.innerHTML = 'Community Portal'; //   document.getElementById('n-mainpage').firstChild.innerHTML = 'W\! Home'; document.getElementById('n-sitesupport').style.display='none'; document.getElementById('n-randompage').style.display='none';

var toplinks = document.getElementById('p-personal').getElementsByTagName('ul')[0]; addlilink(toplinks, '/wiki/User:Cumbrowski/WikiResources', 'Wiki Res.', ''); addlilink(toplinks, '/wiki/Affiliate_marketing', 'Aff.Marketing', ''); addlilink(toplinks, '/wiki/Search_Engine_Optimization', 'SEO', ''); addlilink(toplinks, '/wiki/ASCII_art', 'ASCII art', ''); addlilink(toplinks, '/wiki/Superior_Art_Creations', 'SAC', ''); }

/**** Add links to the toolbox ****/

function addToolBoxLinks {   var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0]; addlilink(tb, '/w/index.php?title=Special:Newpages', 'New pages', ''); addlilink(tb, '/w/index.php?title=Special:Log', 'Logs', ''); addlilink(tb, '/w/index.php?title=User:Cumbrowski/monobook.js', 'Monobook.js', ''); addlilink(tb, '/w/index.php?title=User:Cumbrowski/monobook.css', 'Monobook.css', ''); addlilink(tb, '/w/index.php?title=User:Cumbrowski/Sandbox', 'My sandbox', ''); }

function Addmorelinks {  // var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; var tabs = document.getElementById('p-tb').getElementsByTagName('ul')[0];

if((document.title.indexOf("User:") == 0) || (document.title.indexOf("User talk:") == 0)) { //       addlimenu(tabs, 'User functions', 'userf'); //       var userf = document.getElementById('userf').getElementsByTagName('ul')[0]; //       var userf = document.getElementById('p-tb').getElementsByTagName('ul')[0];

var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; 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 "contributions" tab // addlilinkbold(tabs, '/index.php?title=Special:Contributions/' + editlk, 'contributions', ''); } }

/**** Copy More Links to the Bottom ****/

function morelinks {

var tabs = document.getElementById('p-cactions').cloneNode(true); // don't use the same ids twice- replace the p-cactions id and prepend 'mytabs-' to the li's tabs.id = 'mytabs'; // needs this to be set from js, it ignores the css width for some reason tabs.style.width = '100%'; var listitems = tabs.getElementsByTagName('LI'); for (i=0;i<listitems.length;i++) { if(listitems[i].id) listitems[i].id = 'mytabs-' + listitems[i].id; }    // drop them at the bottom of the content area document.getElementById('content').appendChild(tabs); }

/**** 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 {   if (document.getElementById('ca-talk')) {

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('changes')); // var talkmessagetext = 'You have '; // talkmessagebox.innerHTML = talkmessagetext; // talkmessagebox.appendChild(newmessagelink); talkmessagebox.appendChild(document.createTextNode(' ('));   talkmessagebox.appendChild(historylink);    talkmessagebox.appendChild(document.createTextNode(')')); }

/**** String replacement popup ****/

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); } }

/**** Get the pagename for a specified thread ****/

function startThread {   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; return ''; }