Jump to content

User:J. Ash Bowie/monobook.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.
// ====================================
// Twinkle anti-vandalism
// Wikipedia:WikiProject User scripts/Scripts/Twinkle
// ====================================

importScript('User:AzaToth/twinkle.js');

// ====================================
// Adds a drop-down menu to the search box to choose the namespace to search in.
// Wikipedia:WikiProject User scripts/Scripts/Multi-NS search
// ====================================

addOnloadHook(function () {
    var searchGoButton = document.getElementById('searchGoButton');
    if (!searchGoButton) return;

    var searchNsHidden = document.createElement('input');
    searchNsHidden.id = 'searchNsHidden';
    searchNsHidden.type = 'hidden';
    searchNsHidden.name = 'ns0';
    searchNsHidden.value = '1';

    var searchNsMenu = document.createElement('select');
    searchNsMenu.id = 'searchNsMenu';
    searchNsMenu.name = 'ns';
    searchNsMenu.options[searchNsMenu.options.length] = new Option('(Main)', 0);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Talk', 1);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('User', 2);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('User talk', 3);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Wikipedia', 4);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Wikipedia talk', 5);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Image', 6);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Image talk', 7);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('MediaWiki', 8);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('MediaWiki talk', 9);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Template', 10);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Template talk', 11);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Help', 12);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Help talk', 13);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Category', 14);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Category talk', 15);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Portal', 100);
    searchNsMenu.options[searchNsMenu.options.length] = new Option('Portal talk', 101);
    searchNsMenu.onchange = function () {
        searchNsHidden.name = 'ns' + (this.selectedIndex < 0 ? '0' : 
this.options[this.selectedIndex].value);
    };
    // From /skins-1.5/monobook/main.css?5:
    searchNsMenu.style.width = '10.9em';
    searchNsMenu.style.margin = '0';
    searchNsMenu.style.fontSize = '95%';
    searchGoButton.parentNode.insertBefore(searchNsHidden, searchGoButton);
    searchGoButton.parentNode.insertBefore(searchNsMenu, searchGoButton);
});

// ====================================
// Duplicates tabs at bottom
// Wikipedia:WikiProject User scripts/Scripts/Duplicate tabs at bottom
// ====================================

addOnloadHook(function () {
    var tabs = document.getElementById('p-cactions').cloneNode(true);
    tabs.id = 'mytabs';
    var listitems = tabs.getElementsByTagName('LI');
    for (i=0;i<listitems.length;i++) {
        if(listitems[i].id) listitems[i].id = 'mytabs-' + listitems[i].id;
    }

    content = document.getElementById("content");    // Find the content div
    content.parentNode.insertBefore(tabs, content.nextSibling);    // Place tab list right after content div
});


// ====================================
// Unwatch button on watchlist
// http://en.wikipedia.org/wiki/User_talk:Alex_Smotrov/wlunwatch.js
// ====================================

importScript('User:Alex Smotrov/wlunwatch.js');

// ====================================
// Shows version differences in body text form
// User:Cacycle/wikEdDiff
// ====================================

// 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>');

// ====================================
// Edit top section
// User:Ais523/editsection0tab.js
// ====================================

// Simplified edit section 0 ([[User:ais523/editsection0tab.js]])
// <source lang="javascript">
addOnloadHook(function()
{
  var x=document.getElementById('ca-history');
  if(x!=null)
    mw.util.addPortletLink('p-cactions', mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+
                                 "&action=edit&section=0", '0', 'ca-edit-0',
                                 'Edit the lead section of this page', '0', x);
});
// </source>
// [[Category:Wikipedia scripts]]

// ====================================
// History script
// http://en.wikipedia.org/wiki/User_talk:Alex_Smotrov/histcomb.js
// ====================================

importScript('User:Alex Smotrov/histcomb.js')

addOnloadHook ( extendededitlinks ) ;
 
function extendededitlinks_get_event_target ( e ) {
  var targ ;
  if (!e) var e = window.event;
  if (e.target) targ = e.target;
  else if (e.srcElement) targ = e.srcElement;
  if (targ.nodeType == 3) targ = targ.parentNode; // defeat Safari bug
  while ( targ.nodeType != 1 || targ.className != "editsection" ) targ = targ.parentNode ;
  return targ ;
}
 
function extendededitlinks_is_relevant_heading ( current , compare ) {
  if ( current.nodeType != 1 ) return false ;
  if ( current.tagName.length != 2 ) return false ;
  if ( current.tagName.substr ( 0 , 1 ) != "H" ) return false ;
  if ( current.tagName> compare.tagName) return false ;
  return true ;
}
 
function extendededitlinks_onmouseover ( e ) {
  var target = extendededitlinks_get_event_target ( e ) ;
 
  var h2 = target ;
  while ( h2.nodeType != 1 || h2.tagName.substr(0,1) != "H" ) h2 = h2.parentNode;
 
  var newdiv = document.createElement ( "div" ) ;
  newdiv.style.backgroundColor = "#DDDDDD" ;
//  newdiv.style.border = "1px solid black" ;
//  newdiv.style.padding = "2px" ;
 
  h2.parentNode.insertBefore ( newdiv , h2 ) ;
  newdiv = h2.previousSibling ; // Unneccessary?
 
  var x = h2 ;
  do {
    var y = x ;
    x = x.nextSibling ;
    newdiv.appendChild ( y ) ;
  } while ( x && !extendededitlinks_is_relevant_heading ( x , h2 ) ) ;
 
}
 
function extendededitlinks_onmouseout ( e ) {
  var target = extendededitlinks_get_event_target ( e ) ;
 
  var h2 = target ;
  while ( h2.nodeType != 1 || h2.tagName.substr(0,1) != "H" ) h2 = h2.parentNode;
 
  var newdiv = h2 ;
  while ( newdiv.nodeType != 1 || newdiv.tagName != "DIV" ) newdiv = newdiv.parentNode;
 
  for ( var y = newdiv.firstChild ; y ; y = z ) {
    z = y.nextSibling ;
    newdiv.parentNode.insertBefore ( y , newdiv ) ;
  }
  newdiv.parentNode.removeChild ( newdiv ) ;
}
 
function extendededitlinks () {
  var spans = document.getElementsByTagName( "span" );
  for ( var i = 0 ; i < spans.length ; i++ ) {
    if ( spans[i].className != "editsection" ) continue ;
    var a = spans[i].getElementsByTagName("a")[0] ;
    a.onmouseover = extendededitlinks_onmouseover ;
    a.onmouseout = extendededitlinks_onmouseout ;
  }
}