MediaWiki:Common.js

// /* --- Any JavaScript here will be loaded for all users on every page load. --- */ /*                                                                                                     */ //**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**// /* IMPORT SECTION *//* // mw.loader.load( '/index.php?title=MediaWiki:Gadget-Edittools.js&action=raw&ctype=text/javascript' );// Test

//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**// /* Make T:Button actually clickable! *//*
 * BY: U:Technical 13
 * 28 February 2017

if ( $( 'span.fakeButton' ) !== undefined ) { $( 'span.fakeButton' ).each( function {   var realButton = '';console.log('replacing id: %s with: %s', buttonID, realButton);    $( 'span#' + buttonID ).replaceWith( realButton );  } ); }

//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**// /* Home page "What's new" section sizer works with Common.css to achieve desired result *//*
 * BY: User:Technical 13
 * 29 July 2015
 * Modified: 30 July 2015

if (   mw.config.get( 'wgPageName' ) === 'Home' ||// Home itself    mw.config.get( 'wgPageName' ) === "Home/What's_new" ||// Home/What's_new    mw.config.get( 'wgPageName' ) === 'Talk:Home/ShoeMaker'//TESTCASES PAGE -- Talk:Home/ShoeMaker  ) { $( 'div#whatsNew, div.whatsNew' ).attr(   'style',    'width: ' + ( $( '#mw-content-text' ).width - 14 ) + 'px !important;'  ); $( '.whatsNewSection' ).attr(   'style',    'width: ' + Math.floor( ( $( '#mw-content-text' ).width - 73 ) / 3 ) + 'px !important;'  ); }

//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**// /* Namespace Stripping & Fixes *//*
 * Written 2012-04-20 by User:Ague
 * Modified 2016-08-15 by User:Technical 13
 * Modified 2021-09-03 by User:Technical_13

$( 'a[href^="/page/Item:"]' ).each( function { $( this ).addClass( 'item' );  $( this ).html( $( this ).html.replace( 'Item:', '' ) ); } ); $( '#firstHeading' ).each( function { $( this ).html( $( this ).html.replace( 'Item:', '' ) ); } ); $( 'title' ).each( function { $( this ).html( $( this ).html.replace( 'Item:', 'I:' ) ); } );

/*if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Editcount' ) { $( 'td' ).filter( ( x, cell ) => { return $( cell ).text === 'NS #274'; } ).text( 'Widget' ); $( 'td' ).filter( ( x, cell ) => { return $( cell ).text === 'NS #275'; } ).text( 'Widget talk' ); }//*/

//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**// /* Collapsible tables *//* * Description: Allows tables to be collapsed, showing only the header. See en:Wikipedia:NavFrame * Maintainers: en:User:R. Koot */ var autoCollapse = 2; var collapseCaption = 'hide'; var expandCaption = 'show'; window.collapseTable = function ( tableIndex ) { var Button = document.getElementById( 'collapseButton' + tableIndex ); var Table = document.getElementById( 'collapsibleTable' + tableIndex ); if ( !Table || !Button ) { return false; }   var Rows = Table.rows; var i;   if ( Button.firstChild.data === collapseCaption ) { for ( i = 1; i < Rows.length; i++ ) { Rows[i].style.display = 'none'; }       Button.firstChild.data = expandCaption; } else { for ( i = 1; i < Rows.length; i++ ) { Rows[i].style.display = Rows[0].style.display; }       Button.firstChild.data = collapseCaption; } }; function createCollapseButtons { var tableIndex = 0; var NavigationBoxes = {}; var Tables = document.getElementsByTagName( 'table' ); var i;   function handleButtonLink( index, e ) { window.collapseTable( index ); e.preventDefault; }   for ( i = 0; i < Tables.length; i++ ) { if ( $( Tables[i] ).hasClass( 'collapsible' ) ) { /* only add button and increment count if there is a header row to work with */ var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0]; if ( !HeaderRow ) continue; var Header = HeaderRow.getElementsByTagName( 'th' )[0]; if ( !Header ) continue; NavigationBoxes[ tableIndex ] = Tables[i]; Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex ); var Button    = document.createElement( 'span' ); var ButtonLink = document.createElement( 'a' ); var ButtonText = document.createTextNode( collapseCaption ); Button.className = 'collapseButton'; /* Styles are declared in Common.css */ ButtonLink.style.color = Header.style.color; ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex ); ButtonLink.setAttribute( 'href', '#' ); $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) ); ButtonLink.appendChild( ButtonText ); Button.appendChild( document.createTextNode( '[' ) ); Button.appendChild( ButtonLink ); Button.appendChild( document.createTextNode( ']' ) ); Header.insertBefore( Button, Header.firstChild ); tableIndex++; }   }    for ( i = 0;  i < tableIndex; i++ ) { if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) { window.collapseTable( i ); }        else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) { var element = NavigationBoxes[i]; while ((element = element.parentNode)) { if ( $( element ).hasClass( 'outercollapse' ) ) { window.collapseTable ( i ); break; }           }        }    } } $( createCollapseButtons ); //**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**// /* Dynamic Navigation Bars (experimental) *//* * Description: See enWikipedia:NavFrame. * Maintainers: UNMAINTAINED */ // set up the words in your language var NavigationBarHide = '[' + collapseCaption + ']'; var NavigationBarShow = '[' + expandCaption + ']';

/** * Shows and hides content and picture (if available) of navigation bars * Parameters: *    indexNavigationBar: the index of navigation bar to be toggled **/

window.toggleNavigationBar = function ( indexNavigationBar, event ) { var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar ); var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar ); var NavChild; if ( !NavFrame || !NavToggle ) { return false; }   // if shown now if ( NavToggle.firstChild.data === NavigationBarHide ) { for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { NavChild.style.display = 'none'; }       }    NavToggle.firstChild.data = NavigationBarShow; // if hidden now } else if ( NavToggle.firstChild.data === NavigationBarShow ) { for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { NavChild.style.display = 'block'; }       }        NavToggle.firstChild.data = NavigationBarHide; }   event.preventDefault; }; // adds show/hide-button to navigation bars function createNavigationBarToggleButton { var indexNavigationBar = 0; var NavFrame; var NavChild; /* iterate over all -elements */ var divs = document.getElementsByTagName( 'div' ); for ( var i = 0; (NavFrame = divs[i]); i++ ) { /* if found a navigation bar */ if ( $( NavFrame ).hasClass( 'NavFrame' ) ) { indexNavigationBar++; var NavToggle = document.createElement( 'a' ); NavToggle.className = 'NavToggle'; NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar ); NavToggle.setAttribute( 'href', '#' ); $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) ); var isCollapsed = $( NavFrame ).hasClass( 'collapsed' ); /**            * Check if any children are already hidden. This loop is here for backwards compatibility: * the old way of making NavFrames start out collapsed was to manually add style="display:none" * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make            * the content visible without JavaScript support), the new recommended way is to add the class * "collapsed" to the NavFrame itself, just like with collapsible tables. */           for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) { if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { if ( NavChild.style.display === 'none' ) { isCollapsed = true; }               }            }            if ( isCollapsed ) { for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { NavChild.style.display = 'none'; }               }            }            var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide ); NavToggle.appendChild( NavToggleText ); // Find the NavHead and + the 1/0 link (Must be this complicated because Moz's 1stChild handling is borked) for( var j = 0; j < NavFrame.childNodes.length; j++ ) { if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) { NavToggle.style.color = NavFrame.childNodes[j].style.color; NavFrame.childNodes[j].appendChild( NavToggle ); }           }            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar ); }   } } $( createNavigationBarToggleButton );

//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**// /* DDO Wiki UI Improvement - User Talk Archival Script - FINAL * BY: User:Ague * 31 January 2014 */

$( 'p' ).click( function {   var id = $( this ).attr( 'id' ) + '_div';    if ( $( '#' + id ).hasClass( 'show' ) ) {        $( '#' + id ).slideUp( 1000 ).removeClass( 'show' );               } else {        $( 'div.ArchiveContentBox > div' ).slideUp( 700 );        $( '#' + id ).slideDown( 1000 ).addClass( 'show' );    } } );

//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**// /** * Redirect User:Name/skin.js and skin.css to the current skin's pages * (unless the 'skin' page really exists). * * Dependencies: mediawiki.util * * @source https://www.mediawiki.org/wiki/Snippets/Redirect_skin.js * @revision 2016-04-13 */ if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) { mw.loader.using( 'mediawiki.util', function {		var titleParts = mw.config.get( 'wgPageName' ).split( '/' );		// Make sure there was a part before and after the slash		// And that the latter is 'skin.js' or 'skin.css'		if ( titleParts.length == 2 ) {			var userSkinPage = titleParts[0] + '/' + mw.config.get( 'skin' );			if ( titleParts[1] === 'skin.js' ) {				location.href = mw.util.getUrl( userSkinPage + '.js' );			} else if ( titleParts[1] === 'skin.css' ) {				location.href = mw.util.getUrl( userSkinPage + '.css' );			}		}	} ); }

//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**// /** * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL * @revision 2020-04-01 * @author User:Technical_13 */

mw.loader.using( [ 'mediawiki.util', 'mediawiki.notify', 'mediawiki.api' ], function {  var userPageCSS, isMWCSS;  var extraCSS = mw.util.getParamValue( 'withCSS' );  if ( extraCSS ) {    userPageCSS = ( extraCSS.split( ':' )[ 0 ] === 'User' ? extraCSS.split( ':' )[ 1 ].split( '/' )[ 0 ] : null );   isMWCSS = ( extraCSS.split( ':' )[ 0 ] === 'MediaWiki' ? true : false );     }  var  userPageJS, isMWJS;  var extraJS = mw.util.getParamValue( 'withJS' );  if ( extraJS ) {    userPageJS = ( extraJS.split( ':' )[ 0 ] === 'User' ? extraJS.split( ':' )[ 1 ].split( '/' )[ 0 ] : null );   isMWJS = ( extraJS.split( ':' )[ 0 ] === 'MediaWiki' ? true : false ); }  var isUserSysop = ( mw.config.get( 'wgUserGroups' ).indexOf( 'sysop' ) !== -1 ? true : false ); var isOnSysopUser = false, doAnyway = false;  var strUsers = ( userPageCSS && userPageJS ? ( userPageCSS === userPageJS ? userPageCSS : userPageCSS + '|' + userPageJS ) : ( userPageCSS || userPageJS || mw.config.get( 'wgUserName' ) ) ); console.log( 'strUsers: %s', strUsers ); ( new mw.Api ).get( { action: 'query', list: 'users', usprop: 'rights', ususers: strUsers } ).done( function( userRights ) { userRights = userRights.query.users[ 0 ].rights; isOnSysopUser = ( userRights.indexOf( 'editinterface' ) !== -1 ? true : false ); if ( isUserSysop && ! isOnSysopUser && !isMWCSS && !isMWJS ) { doAnyway = confirm( 'This code is NOT in the MediaWiki: namespace OR in the User: space of an administrator.\n\t\t\tHit [OK] ONLY if you trust the source of this code!' ); }   if ( extraCSS ) { // WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks) if ( isMWCSS || ( isOnSysopUser && userPageCSS ) || doAnyway ) { mw.loader.load( '/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' ); } else { mw.notify( 'Only pages on an administrators User: space or from the MediaWiki: namespace are allowed.', { title: 'Invalid withCSS value' } ); }   }    if ( extraJS ) { // WARNING: DO NOT REMOVE THIS "IF" - REQUIRED FOR SECURITY (against XSS/CSRF attacks) if ( isMWJS || ( isOnSysopUser && userPageJS ) || doAnyway ) { mw.loader.load( '/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' ); } else { mw.notify( 'Only pages on an administrators User: space or from the MediaWiki: namespace are allowed.', { title: 'Invalid withJS value' } ); }   }  } ); } );

//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**// /** */
 * BY: User:Technical 13
 * 17 September 2021

if ( mw.config.get( 'wgPageName' ) === 'DDO wiki:Social media' ) { $( 'span#fbFeedDDOwiki' ).replaceWith( ' ' ); } //