User:Spidern/monobook.js

Source: 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.
// Twinkle and config
importScript('User:AzaToth/twinkle.js'); // This script causes problems with sortable tables
if( typeof( TwinkleConfig ) == 'undefined' ) TwinkleConfig = {};
TwinkleConfig.watchRevertedPages = [];

// Essentials
importScript('User:Lupin/popups.js');
importScript('User:Pyrospirit/metadata.js'); //[[User:Pyrospirit/metadata.js]]
importScript('User:Animum/count.js');
importScript('User:JeremyMcCracken/contribstab.js');

// History combing
importScript('User:Alex Smotrov/histcomb.js');
histCombLeaveComment = true //if true, keep summary on the last folded edit
histCombNoCollapse = false //if true, do not collapse edits on load
histCombMyBg = '#F0FFF0' //background on your edits (light green)
histCombTalk = 'talk' //string to replace 'Talk'
histCombContrib = 'contribs' //string to replace 'contribs'

//friendly in the article namespace
importScript('User:AzaToth/morebits.js');
importScript('User:Ioeth/friendlytag.js');

//--------------------------------------------------------------------------------------------------------
//importScript('User:Cacycle/wikEdDiff.js);
//--------------------------------------------------------------------------------------------------------
// install [[User:Cacycle/wikEdDiff]] enhanced diff view using ajax
//document.write('<script type="text/javascript" src="'
//+ 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEdDiff.js'
//+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');


//--------------------------------------------------------------------------------------------------------
//importScript(Menustuff);
//--------------------------------------------------------------------------------------------------------
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);
 
if ( document.createElement && window.addEventListener )
{
 function SoFixItInit() // pre-load, (don't want to slow down loading of article's content, though)
 {
 
 }
 
 function SoFixItLoad() // post-load
 {
 UserMenu = new PortletMenu( 'p-personal'   );
 PageMenu = new PortletMenu( 'p-cactions'   );
  NavMenu = new PortletMenu( 'p-navigation' );
 //ToolMenu = new PortletMenu( 'p-tb'         );
 
 // This is inefficient and not particularly robust.
 // This comes first, I want this link to come up as
 // fast as possible.
 //
 function GetByClass( sElem, sClass )
 { var i, a2 = [], a = document.getElementsByTagName( sElem );
 for ( i = 0; i < a.length; i++ )
 if ( a[ i ].className == sClass )
 a2.push( a[ i ] );
 return a2;
 }
 var a, td = GetByClass( 'td', 'diff-otitle' );
 if ( ( td = td[ 0 ] ) && ( a = td.getElementsByTagName( 'a' )[ 0 ] ) )
 a.href = a.href + '&action=edit'; // need to change text, later
 
 var userName = UserMenu.getText( 'pt-userpage' );
 
 // personal (top-most) menu
 //
 // Splash  Talk  Prefs  Watch  List  Contribs Logout
 //
 UserMenu.setText( 'pt-watchlist'  , 'watch' );
 UserMenu.setText( 'pt-mytalk'     , 'talk'  );
 UserMenu.setText( 'pt-preferences', 'prefs' );
 UserMenu.setText( 'pt-mycontris'  , 'contribs' );
 UserMenu.setText( 'pt-logout'     , 'logout'   );
 //
 UserMenu.setHref( 'pt-mycontris',
 'http://en.wikipedia.org/wiki/Special:Contributions/' +
 userName );
 //
 //
 // it seems there is a stylesheet that makes them lowercase
 //
 // ok, the lowercased menu items are starting to really bug me:
 //
 document.getElementById( 'p-personal' ).getElementsByTagName( 'ul' )[0].style.textTransform = 'none';
 //
 UserMenu.insertBefore( 'pt-mycontris', 'pt-list', 'editlist', '/wiki/Special:Watchlist/edit' );

 // article-actions menu, (the "tabs")
 //
 if ( PageMenu[ 'ca-history' ] ) // theory: if it has a history tab, then it's purgable
 {
 PageMenu.insertBefore( 'ca-history', 'ca-lastdiff', 'Last Diff',
 PageMenu.getHref( 'ca-history' ).replace( /action=history/, 'diff=0' ) );
 
 PageMenu.append( 'ca-purge', 'Purge',
 PageMenu.getHref( 'ca-history' ).replace( /action=history/, 'action=purge' ) );
 }
 
 var x = 1;
 NavMenu.append( 'n-' + x++, 'monobook.js', '/wiki/User:' + userName + '/monobook.js' );
 NavMenu.append( 'n-' + x++, 'Templates', '/wiki/Wikipedia:Template' );
 NavMenu.append( 'n-' + x++, 'Cleanup tags', '/wiki/Wikipedia:Template_messages/Cleanup' );
                NavMenu.append( 'n-' + x++, 'Stub sorts', '/wiki/Stub_types' );
 
 
 }
 
 function PortletMenu( id ) // constructor
 {
 this.menu = document.getElementById( id );
 this.list = this.menu.getElementsByTagName( 'ul' )[ 0 ]; // bypass "<h5>Views</h5>", etc.
 
 // sigh...as far as I can figure, there is empty whitespace being treated
 // as TextNodes....
 //
 var LIs = this.list.getElementsByTagName( 'li' );
 
 for ( var i = 0; i < LIs.length; i++ )
 {
 this[ LIs[ i ].id ] = LIs[ i ];
 }
 
 this.newItem = function( id, txt, url )
 { var li = document.createElement( 'li' ); li.id   = id;
 var  a = document.createElement( 'a'  );  a.href = url;
 
  a.appendChild( document.createTextNode( txt ) );
 li.appendChild( a );
 
 this[ id ] = li; // watch this!!!
 
 return li;
 }
 
 this.append = function( id, txt, url )
 { this.list.appendChild( this.newItem( id, txt, url ) );
 }
 
 this.insertBefore = function( old, id, txt, url )
 { this.list.insertBefore( this.newItem( id, txt, url ), this[ old ] );
 }
 
 // the ByTagName here is a bit annoying, but in Safari, I was picking
 // up TextNodes by using this[ id ].firstChild.firstChild
 //
 this.getText = function( id      ) { return this[ id ].getElementsByTagName( 'a' )[ 0 ].firstChild.data }
 this.setText = function( id, txt ) {        this[ id ].getElementsByTagName( 'a' )[ 0 ].firstChild.data = txt }
 
 this.getHref = function( id      ) { return this[ id ].getElementsByTagName( 'a' )[ 0 ].href       }
 this.setHref = function( id, url ) {        this[ id ].getElementsByTagName( 'a' )[ 0 ].href = url }

 }
 
 function RemoveNode( id )
 { var node = document.getElementById( id )
 node.parentNode.removeChild( node );
 }
 
 SoFixItInit();
 window.addEventListener( 'load', SoFixItLoad, false );
}

//--------------------------------------------------------------------------------------------------------
//importScript('User:Js/ajaxPreview.js');
//--------------------------------------------------------------------------------------------------------
/*function ajaxPreviewInit(){
 if ((wgNamespaceNumber % 2 == 0) && /\.(js|css)$/.test(wgTitle)) return
 if (typeof ajaxPreviewKey != 'string') ajaxPreviewKey = 'p'
 if (typeof ajaxDiffKey != 'string') ajaxDiffKey  = 'v'
 ajaxPreviewPos = window.ajaxPreviewPos || 'right'
 if (ajaxPreviewPos != 'bottom'){
   var tOld = document.getElementById('toolbar') || document.getElementById('wpTextbox1')
   tOld.style.clear = 'none'
   var d = document.createElement('div'); d.style.cssText = 'width:100%; clear:both'
   tOld.parentNode.insertBefore(d, tOld)
   var tNew = document.createElement('div'); tNew.style.cssText = 'float:'+ ajaxPreviewPos
   tOld.parentNode.insertBefore(tNew, tOld)
 }
 addBtn(window.ajaxPreviewButton, 'wpPreview', ajaxPreviewKey)
 addBtn(window.ajaxDiffButton, 'wpDiff', ajaxDiffKey)
 function addBtn(name, id, akey){ 
  var btnOld = document.getElementById(id)
  if (!btnOld) return
  //var
  btn = document.createElement('input'); btn.type = 'button'
  btn.onclick = ajaxPreviewClick;  btn.id = id + 'Live'
  if (!name){ //extract last word from standard buttons
    name = btnOld.value.split(' '); name = name[name.length-1]
    name = name.substring(0,1).toUpperCase() + name.substring(1) 
  }
  btn.value = name;  btn.title = btnOld.value + ' (Ajax)'
  if (ajaxPreviewPos == 'bottom'){
    btnOld.parentNode.insertBefore(btn, btnOld)
    btn.value = btnOld.value
    btnOld.value = '>'
  }else{
    btn.style.cssText = 'height:22px; padding:0 1px'
    tNew.appendChild(btn)
  }
  if (akey){ //reassign acces key
    if (btnOld.accessKey == akey){ 
      btnOld.accessKey = ''
      //btnOld.setAttribute('accesskey', '')
      btnOld.title = btnOld.title.replace(tooltipAccessKeyRegexp, '')
    }
    //btn.setAttribute('accesskey', akey)
    btn.accessKey = akey
    btn.title += ' ['+tooltipAccessKeyPrefix+akey+']'
  }
  btn.value2 = btn.value
 }
}
 
function ajaxPreviewClick(){ajaxPreviewRun(this)}
 
function ajaxPreviewRun(btn){
 var wkPreview = document.getElementById('wikiPreview'), form = document.editform
 var aj = sajax_init_object()
 if (!wkPreview || !form || !aj) return
 var oldHeight = wkPreview.offsetHeight
 var el, htm, isDiff = (btn.id=='wpDiffLive')
 wkPreview.style.opacity = '0.3'; wkPreview.style.color = 'gray'; document.body.style.cursor = 'wait'
 if (el=document.getElementById('wikiDiff')) el.style.display = 'none'
 if (el=document.getElementById('newarticletext')) el.style.display = 'none'
 btn.style.width = Math.max(btn.scrollWidth, btn.offsetWidth) + 'px';  btn.value = '...'
 //prepare
 var txt = form.wpTextbox1.value, action = form.action
 var boundary = '--------123xyz', data = ''
 if (isDiff){
   addData('wpDiff', ''); addData('wpStarttime'); addData('wpEdittime')
   if (!window.ajaxPreview_CSS) ajaxPreview_CSS = importStylesheetURI('/skins-1.5/common/diff.css') 
 }else{
   action += '&live'
   if (form.wpSection && form.wpSection.value) txt += '\n<br /><references />'
 } 
 addData('wpTextbox1', txt); addData('wpSection'); addData('wpSummary')
 //send
 aj.open('POST', action, true)
 aj.setRequestHeader('Content-Type', 'multipart/form-data; boundary='+boundary)
 aj.send(data + '--' + boundary)
 aj.onreadystatechange = function(){
  if (aj.readyState != 4) return
  wkPreview.style.display = 'block'
  if (isDiff){
    var htm = aj.responseText
    var p1 = htm.indexOf("<table class='diff'>" )
    var p2 = htm.indexOf('</table>', p1)
    htm = (p1!=-1 && p2!=-1) ? htm.substring(p1, p2+8) : 'Error'
  }else{
    htm = aj.responseText.replace(/&gt;/g,'>').replace(/&lt;/g,'<').replace(/&quot;/g,'"').replace(/&amp;/g,'&').replace(/&apos;/g,"'")
  }
  wkPreview.innerHTML = htm
  btn.value = btn.value2
  btn.blur()
 
 
  if (el = wkPreview.getElementsByTagName('h2')[0]){
    if (el.style.textAlign != 'right') el.innerHML +=  ' (Ajax)'
    el.style.textAlign = 'right'
  }
 
  if (window.ajaxPreviewScrollTop && wkPreview.scrollIntoView) wkPreview.scrollIntoView()
  else document.documentElement.scrollTop +=  wkPreview.offsetHeight - oldHeight 
 
  wkPreview.style.opacity = ''; wkPreview.style.color = ''; document.body.style.cursor = ''
  if (!isDiff) ajaxPreviewFinish(wkPreview)
 }
 
 function addData(name, value){
   if (!value) value = form[name] ? form[name].value : ''
   data += '--' + boundary + '\nContent-Disposition: form-data; name="'+name+'"\n\n' + value + '\n'
 }
}
 
function ajaxPreviewFinish(el){
 sortables_init()
 if (window.createCollapseButtons){//en.wp
   createCollapseButtons()
   createNavigationBarToggleButton()
 } 
 if (window.ajaxPreviewExec) ajaxPreviewExec(el)
}

if (wgAction=='edit' || wgAction=='submit') addOnloadHook(ajaxPreviewInit)*/

// Misc
importScript('User:Dr_pda/prosesize.js');
//importScript('User:AndyZ/peerreviewer.js');
importScript('User:Shubinator/DYKcheck.js');
importScript('User:TheDJ/Gadget-HotCat.js');
importScript('User:Proteins/followrandomlinkonpage.js');
importScript('User:Anomie/getWatchlist.js');
importScript('user:js/watchlist.js') // watchlist enhancments
importScript('User:Lupin/recent2.js');

// Deletion sorting
importScript('User:Quarl/util.js');
importScript('User:Quarl/wikipage.js');
importScript('Wikipedia:WikiProject User scripts/Scripts/Add LI menu');
importStylesheet('Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css');;
importScript('Wikipedia:WikiProject Deletion sorting/delsort.js');