MediaWiki:Common.js: Difference between revisions

From Celeste Wiki
Jump to navigation Jump to search
Content added Content deleted
(Added a variety of schenanigans)
 
(swapped => with function(id))
(23 intermediate revisions by 2 users not shown)
Line 6: Line 6:
* By [[User:Sikon|Sikon]], updated by [[User:Bizzeebeever]]
* By [[User:Sikon|Sikon]], updated by [[User:Bizzeebeever]]
*/
*/
/*
$j( function() {
$j( function() {
var $title = $j( '#title-meta' ),
var $title = $j( '#title-meta0' ),
text = $title.text().toLowerCase(),
text = $title.text().toLowerCase(),
name = mw.config.get( 'wgPageName' ).replace( /_/g, '' ).toLowerCase();
name = mw.config.get( 'wgPageName' ).replace( /_/g, '' ).toLowerCase();
Line 17: Line 18:
}
}
} );
} );
*/



/** Logo remover *********************************************************
/** Logo remover *********************************************************
* Used by [[Template:Nologo]]
* Used by [[Template:Nologo]]
* By some idiot, updated by [[User:Bizzeebeever]]
* Updated by [[User:Bizzeebeever]]
*/
*//*
$j( function() {
$j( function() {
if ( $j( '#nologo' ).length ) {
if ( $j( '#nologo' ).length ) {
Line 27: Line 30:
}
}
} );
} );
*/


/** Title remover ********************************************************
/** Title remover ********************************************************
* Used by [[Template:Notitle]]
* Used by [[Template:Notitle]]
* By some idiot, updated by [[User:Bizzeebeever]]
* Updated by [[User:Bizzeebeever]]
*/
*//*
$j( function () {
$j( function () {
if ( $j( '#notitle' ).length ) {
if ( $j( '#notitle' ).length ) {
Line 37: Line 41:
}
}
} );
} );
*/

/** Categories remover ***************************************************
/** Categories remover ***************************************************
* Used by [[Template:Nocategories]]
* Used by [[Template:Nocategories]]
* By some idiot, updated by [[User:Bizzeebeever]]
* Updated by [[User:Bizzeebeever]]
*/
*//*
$j( function() {
$j( function() {
if ( $j( '#nocategories' ).length ) {
if ( $j( '#nocategories' ).length ) {
Line 47: Line 51:
}
}
} );
} );
*/

/** Show username ********************************************************
/** Show username ********************************************************
* The annoying hack used by [[Template:USERNAME]]!
* The annoying hack used by [[Template:USERNAME]]!
Line 53: Line 57:
* Originally by [[wikia:User:Splarka|Splarka]], [[User:Spang]]
* Originally by [[wikia:User:Splarka|Splarka]], [[User:Spang]]
* New version by [[User:Bizzeebeever]]
* New version by [[User:Bizzeebeever]]
*/
*//*
$j( function() {
$j( function() {
var name = mw.config.get( 'wgUserName' );
var name = mw.config.get( 'wgUserName' );
Line 59: Line 63:
$j( 'span.insertusername' ).text( name );
$j( 'span.insertusername' ).text( name );
}
}
} );
} );*/


/** Archive edit tab disabling *******************************************
/** Archive edit tab disabling *******************************************
Line 66: Line 70:
* or by typing the edit address manually.
* or by typing the edit address manually.
* By [[User:Spang|Spang]], rewritten by [[User:Bizzeebeever]]
* By [[User:Spang|Spang]], rewritten by [[User:Bizzeebeever]]
*/
*//*
$j( function() {
$j( function() {
if ( $j( '#old-forum-warning' ).length && !window.enableOldForumEdit ) {
if ( $j( '#old-forum-warning' ).length && !window.enableOldForumEdit ) {
Line 73: Line 77:
.text( 'No editing' );
.text( 'No editing' );
}
}
} );
} );*/


/** Add-section tab disabling ********************************************
/** Add-section tab disabling ********************************************
Line 81: Line 85:
* example: <div id="disableAddSection"></div>
* example: <div id="disableAddSection"></div>
* By [[User:Olipro|Olipro]], updated by [[User:Bizzeebeever]]
* By [[User:Olipro|Olipro]], updated by [[User:Bizzeebeever]]
*/
*//*
$j( function() {
$j( function() {
if ( $j( '#disableAddSection' ).length ) {
if ( $j( '#disableAddSection' ).length ) {
$j( '#ca-addsection' ).remove();
$j( '#ca-addsection' ).remove();
}
}
} );
} );*/

// Replaces image

if (document.getElementById('replaceImageButton')) {
document.getElementById('replaceImageButton').addEventListener('click', function() {
// Get a reference to the container element by its ID
var container = document.getElementById('containerID');
// Find the image element within the container
var imageElement = container.querySelector('img');
// Replace the image source with a new one
imageElement.src = document.getElementById('newImageURL').innerText;
});
}

// Default scroll position for maps
window.addEventListener("load", function() {
console.log("started execution");
const bottom = ["scroll0", "scroll1", "scroll2", "scroll4", "scroll7", "scroll8"]; // ids of maps where we need to push the scrollbar to bottom
bottom.forEach(function(id){
console.log("trying to change scroll position of " + id);
if (document.getElementById(id)) {
// document.getElementById(id).scrollTop = document.getElementById(id).scrollHeight;
document.getElementById(id).scrollTop = 999999;
}
});
});

Revision as of 19:14, 23 April 2024

/* Any JavaScript here will be loaded for all users on every page load. */

/** Title replacement ****************************************************
 * Rewrites the page's title, used by [[Template:Title]]
 * Should use {{DISPLAYTITLE}}, unless you want to use an image
 * By [[User:Sikon|Sikon]], updated by [[User:Bizzeebeever]]
 */
/* 
$j( function() {
	var $title = $j( '#title-meta0' ),
		text = $title.text().toLowerCase(),
		name = mw.config.get( 'wgPageName' ).replace( /_/g, '' ).toLowerCase();
	if ( $title.length && !window.SKIP_TITLE_REWRITE ) {
		$title.appendTo( $j( '#firstHeading' ).empty() ).show();
		if ( text == name ) {
			document.title = text;
		}
	}
} );
*/


/** Logo remover *********************************************************
 * Used by [[Template:Nologo]]
 * Updated by [[User:Bizzeebeever]]
 *//*
$j( function() {
	if ( $j( '#nologo' ).length ) {
		$j( '#p-logo' ).hide();
	}
} );
*/

/** Title remover ********************************************************
 * Used by [[Template:Notitle]]
 * Updated by [[User:Bizzeebeever]]
 *//*
$j( function () {
	if ( $j( '#notitle' ).length ) {
		$j( '#firstHeading' ).hide();
	}
} );
*/
/** Categories remover ***************************************************
 * Used by [[Template:Nocategories]]
 * Updated by [[User:Bizzeebeever]]
 *//*
$j( function() {
	if ( $j( '#nocategories' ).length ) {
		$j( '#catlinks' ).hide();
	}
} );
*/
/** Show username ********************************************************
 * The annoying hack used by [[Template:USERNAME]]!
 * Inserts user name into <span class='insertusername'></span>
 * Originally by [[wikia:User:Splarka|Splarka]], [[User:Spang]]
 * New version by [[User:Bizzeebeever]]
 *//*
$j( function() {
	var name = mw.config.get( 'wgUserName' );
	if ( !window.disableUsernameReplace && name ) {
		$j( 'span.insertusername' ).text( name );
	}
} );*/

/** Archive edit tab disabling *******************************************
 * Disables the edit tab on old forums to stop noobs from bumping them.
 * Page can still be edited by going via the edit tab on the history etc,
 * or by typing the edit address manually.
 * By [[User:Spang|Spang]], rewritten by [[User:Bizzeebeever]]
 *//*
$j( function() {
	if ( $j( '#old-forum-warning' ).length && !window.enableOldForumEdit ) {
		$j( '#ca-edit a' ).removeAttr( 'href' )
			.css( 'color', 'gray' )
			.text( 'No editing' );
	}
} );*/

/** Add-section tab disabling ********************************************
 * Disables the add section tab on any page you like, mainly useful for
 * your user page (depending on how you have your user page set up)
 * To use it: include any HTML element with an ID of disableAddSection
 * example: <div id="disableAddSection"></div>
 * By [[User:Olipro|Olipro]], updated by [[User:Bizzeebeever]]
 *//*
$j( function() {
	if ( $j( '#disableAddSection' ).length ) {
		$j( '#ca-addsection' ).remove();
	}
} );*/

// Replaces image

if (document.getElementById('replaceImageButton')) {
	document.getElementById('replaceImageButton').addEventListener('click', function() {
		    // Get a reference to the container element by its ID
		    var container = document.getElementById('containerID');
		    
		    // Find the image element within the container
		    var imageElement = container.querySelector('img');
		    
		    // Replace the image source with a new one
		    imageElement.src = document.getElementById('newImageURL').innerText;
	});
}

// Default scroll position for maps
window.addEventListener("load", function() {
	console.log("started execution");
	const bottom = ["scroll0", "scroll1", "scroll2", "scroll4", "scroll7", "scroll8"]; // ids of maps where we need to push the scrollbar to bottom
	bottom.forEach(function(id){
		console.log("trying to change scroll position of " + id);
		if (document.getElementById(id)) {
			// document.getElementById(id).scrollTop = document.getElementById(id).scrollHeight;
			document.getElementById(id).scrollTop = 999999;
		}
	});
});