We do our best to give you all information you need. Use the Search menu to search for the page you are looking for. The most used pages are on the side menu or in the Popular Pages page.

Do you miss important stuff or do you have suggestions? Let us know via Discord or in-game. Thank you for using our Wiki!

MediaWiki:Common.js

From GrinderScape Wiki
Revision as of 17:59, 24 April 2016 by Jplayer (Talk | contribs)

Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences
// ***************************** Structure *****************************

// Remove unnecessary elements

$( "div#p-tb" ).remove();

// Wrap the content

$( "div#content, div#mw-navigation" ).wrapAll( "<div id='wrap'></div>" );

// Insert the header

$( "<header><div id='logo'><a href='https://www.grinderscape.org/'><img src='https://www.grinderscape.org/assets/images/logo.png' draggable='false'></a></div><nav><ul><li id='n-Home'><a href='https://www.grinderscape.org/'>Home</a></li><li id='n-Forums'><a href='http://forum.grinderscape.org/'>Forums</a></li><li id='n-Wiki'><a href='https://newwiki.grinderscape.org/Main_Page'>Wiki</a></li><li id='n-Vote'><a href='https://www.grinderscape.org/vote/status'>Vote</a></li><li id='n-Donate'><a href='https://www.grinderscape.org/donate'>Donate</a></li><li id='n-Marketplace'><a href='https://www.grinderscape.org/marketplace/all'>Marketplace</a></li><li id='n-Highscores'><a href='https://www.grinderscape.org/highscores/mode/regular'>Highscores</a></li><li id='n-Webclient'><a href='http://www.grinderscape.org/play'>Webclient</a></li><li id='n-Download'><a href='https://www.grinderscape.org/play/download'>Download</a></li></ul></nav></header>" ).insertBefore( "div#wrap" );

// Insert the footer

$( "<div id='customFooter'><div style='margin-bottom: 30px; line-height: 0;'><a href='https://www.facebook.com/Grinderscape.org' style='background: url(https://i.imgur.com/DeOQfOs.png) no-repeat center, linear-gradient( transparent,rgba(0, 0, 0, 0.15)), #3a589e; border: 1px solid #17274D;'></a><a href='https://twitter.com/grinderscape' style='background: url(https://i.imgur.com/GZzo3yV.png) no-repeat center, linear-gradient( transparent,rgba(0, 0, 0, 0.15)), #3A89C4; border: 1px solid #0E3959;'></a><a href='https://www.youtube.com/channel/UCVGi_iQHwRSGY36ff40SkYA' style='background: url(https://i.imgur.com/wF3Xf61.png) no-repeat center, linear-gradient( transparent,rgba(0, 0, 0, 0.15)), #C8312B; border: 1px solid #78130F;'></a></div><p style='margin-bottom: 0;'>Theme developed by <a href='https://forum.grinderscape.org/members/56905'>Jplayer</a>.<br>GrinderScape is not affiliated with Jagex or RuneScape in any way.</p></div>" ).insertBefore( "ul#footer-places" );

// Organize the elements

$( "div#mw-navigation" ).insertBefore( "div#content" );
$( "div#content" ).wrap( "<div id='content-sidebar-wrap'></div>" );
$( "div#mw-panel" ).insertAfter( "div#content" );
$( "div#content" ).wrap( "<div id='content-wrap'></div>" );

$( "<div id='navigation'></div>" ).prependTo( "div#content" );
$( "div#left-navigation" ).appendTo( "div#navigation" );
$( "div#right-navigation" ).appendTo( "div#navigation" );

$( "<div id='pageInfo'></div>" ).insertBefore( "div#content" );

$( "div#content" ).wrap( "<div id='content-navigation-wrap'></div>" );
$( "div#siteNotice" ).insertAfter( "div#mw-navigation" );
$( "ul#footer-info" ).insertAfter( "div#content" );

// Set up the page footer info

if ( $( "li#footer-info-credits" ).length > 0 ) {
	$( "li#footer-info-credits" ).html( $( "li#footer-info-credits" ).html().replace( /\[/g, "<span style='position: absolute; right: 0;'>" ).replace( /\]/g, "</span>" ).replace( /\{/g, "<p id='contentFooter' style='position: relative;'>" ).replace( /\}/g, "</p>" ) );
	$( "p#contentFooter" ).insertBefore( "li#footer-info-credits" );
	$( "li#footer-info-credits" ).remove();
}

// Set up the page title and breadcrumb

var title = $( "h1#firstHeading" ).html().split('/');
$( "h1#firstHeading" ).html( title[ title.length - 1 ] );
$( "h1#firstHeading" ).appendTo( "div#pageInfo" );

$( "span.subpages" ).appendTo( "div#pageInfo" );
$( "span.subpages" ).html( $( "span.subpages" ).children() );
$( "<span>" + title[ title.length - 1 ] + "</span>" ).appendTo( "span.subpages" );
$( "<span>&nbsp;&nbsp;/&nbsp;&nbsp;</span>" ).insertAfter( "span.subpages > a" );

// Set up the page title

document.title = title[ title.length - 1 ] + " - GrinderScape Wiki";

// Set up the announcement

$( "<div id='noticeTitle'>Notice</div>" ).prependTo( "div#siteNotice" );

// Remove href from selected tabs

$.each( $( "div.vectorTabs li.selected" ), function() {
	$( this ).find( "a" ).removeAttr( "href" );
});

// Remove title from links

$( "a" ).removeAttr( "title" );

// Set up the search box

$( "div#p-search" ).prependTo( "div#mw-panel" );
$( "<div id='searchTitle'>Search</div>" ).insertBefore( "form#searchform" );
$( "input#searchInput" ).val( "Search..." ).removeAttr( "placeholder" ).attr( "onfocus", "if (this.value == 'Search...') {this.value = '';}" ).attr( "onblur", "if (this.value == '') {this.value = 'Search...';}" );

// Set up the edit box

function wrapText( elementID, openTag, closeTag ) {
	var textArea = $( "#" + elementID );
	var len = textArea.val().length;
	var start = textArea[0].selectionStart;
	var end = textArea[0].selectionEnd;
	var selectedText = textArea.val().substring( start, end );
	var replacement = openTag + selectedText + closeTag;
	textArea.val( textArea.val().substring( 0, start ) + replacement + textArea.val().substring( end, len ) );
}

$( "input#wpWatchthis" ).prop( "checked", false );

$( "<div class='customButton' id='CB-Nowiki' style='background: url(https://i.imgur.com/Fx2AsCt.png);' title='Ignore wiki formatting'></div>" ).appendTo( "div#toolbar" );
$( "#CB-Nowiki" ).click( function() {
	wrapText( "wpTextbox1", "<nowiki>", "</nowiki>" );
});

$( "<div class='customButton' id='CB-Heading2' style='background: url(https://i.imgur.com/8uajyYO.png);' title='Level 2 heading'></div>" ).prependTo( "div#toolbar" );
$( "#CB-Heading2" ).click( function() {
	wrapText( "wpTextbox1", "<h2>", "</h2>" );
});

$( "<div class='customButton' id='CB-Heading1' style='background: url(https://i.imgur.com/jKOOZnF.png);' title='Level 1 heading'></div>" ).prependTo( "div#toolbar" );
$( "#CB-Heading1" ).click( function() {
	wrapText( "wpTextbox1", "<h1>", "</h1>" );
});

$( "<div class='customButton' id='CB-Italic' style='background: url(https://i.imgur.com/zdPfv0X.png);' title='Italic text'></div>" ).prependTo( "div#toolbar" );
$( "#CB-Italic" ).click( function() {
	wrapText( "wpTextbox1", "<i>", "</i>" );
});

$( "<div class='customButton' id='CB-Bold' style='background: url(https://i.imgur.com/lyqhAM9.png);' title='Bold text'></div>" ).prependTo( "div#toolbar" );
$( "#CB-Bold" ).click( function() {
	wrapText( "wpTextbox1", "<b>", "</b>" );
});

// Remove auto correct from text boxes

$( "textarea#wpTextbox1, input#searchInput, input#database_input" ).attr( "spellcheck", "false" );










// ***************************** Indices *****************************

$.each( $( "div.timestamp" ), function() {
	var str = $( this ).html();
	var year = str.substr( 0, 4 );
	var month = str.substr( 4, 2 );
		if ( month == 01 ) { month = " January " }
		else if ( month == 02 ) { month = " February " }
		else if ( month == 03 ) { month = " March " }
		else if ( month == 04 ) { month = " April " }
		else if ( month == 05 ) { month = " May " }
		else if ( month == 06 ) { month = " June " }
		else if ( month == 07 ) { month = " July " }
		else if ( month == 08 ) { month = " August " }
		else if ( month == 09 ) { month = " September " }
		else if ( month == 10 ) { month = " October " }
		else if ( month == 11 ) { month = " November " }
		else if ( month == 12 ) { month = " December " }
	var day = str.substr( 6, 2 );
	$( this ).html( "Last modified on " + day + month + year + "." );
});
$.each( $( "div.link > a" ), function() {
	var link = $( this ).html().split( "/" );
	$( this ).html( link[ link.length - 1 ].replace( /\_/g, " " ) );
});









// ***************************** Databases *****************************

function commaSeparateNumber( val ){
	while ( /(\d+)(\d{3})/.test( val.toString() ) ) {
		val = val.toString().replace( /(\d+)(\d{3})/, '$1' + '.' + '$2' );
	};
	return val;
};

$( "button#database_button" ).click( function() {
	search_term();
});

function search_term() {

	var input = $( "input#database_input" ).val().toLowerCase();

	if ( $( 'div#item_database > div[item="' + input + '"]' ).length > 0 ) {

		var data = $( "div#item_database > div[item='" + input + "']" ).html().split( ";" );

		// Item

		var item_name = data[0];
		var id = data[1];

		// Item statistics

		var min_price = data[2];
		var max_price = data[3];
		var donator = data[4];
		var tradeable = data[5];
		var noteable = data[6];
		var stackable = data[7];
		var equipable = data[8];

		// Combat statistics

		var ab_stab = data[9];
		var ab_slash = data[10];
		var ab_crush = data[11];
		var ab_magic = data[12];
		var ab_range = data[13];

		var db_stab = data[14];
		var db_slash = data[15];
		var db_crush = data[16];
		var db_magic = data[17];
		var db_range = data[18];

		var ob_strenght = data[19];
		var ob_prayer = data[20];

		var slot = data[21]
		var item_class = data[22]
		var degradable = data[23];

		var sr_defence = data[24];
		var sr_attack = data[25];
		var sr_strenght = data[26];
		var sr_ranged = data[27];
		var sr_magic = data[28];
		var sr_hitpoints = data[29];
		var sr_prayer = data[30];
		var sr_slayer = data[31];

		// Text

		var sources = data[32];
		var uses = data[33];
		var notes = data[34];

		// Update the text

		$( "h1#item_name" ).html( item_name );

		if ( sources == "" ) {
			$( "td#sources" ).html( "No data available." );
		} else {
			$( "td#sources" ).html( sources );
		};

		if ( uses == "" ) {
			$( "td#uses" ).html( "No data available." );
		} else {
			$( "td#uses" ).html( uses );
		};
		
		if ( notes == "" ) {
			$( "td#notes" ).html( "No data available." );
		} else {
			$( "td#notes" ).html( notes );
		};

		// Update the item stats table

		$( "td#picture" ).html( "<img src='https://www.grinderscape.org/assets/images/items/" + id + ".png'>" );
		$( "td#min_price" ).html( commaSeparateNumber( min_price ) );
		$( "td#max_price" ).html( commaSeparateNumber( max_price ) );
		$( "td#donator" ).html( donator );
		$( "td#tradeable" ).html( tradeable );
		$( "td#noteable" ).html( noteable );
		$( "td#stackable" ).html( stackable );
		$( "td#equipable" ).html( equipable );

		// Update combat stats table

		$( "td#ab_stab" ).html( ab_stab );
		$( "td#ab_slash" ).html( ab_slash );
		$( "td#ab_crush" ).html( ab_crush );
		$( "td#ab_magic" ).html( ab_magic );
		$( "td#ab_range" ).html( ab_range );

		$( "td#db_stab " ).html( db_stab );
		$( "td#db_slash" ).html( db_slash );
		$( "td#db_crush" ).html( db_crush );
		$( "td#db_magic" ).html( db_magic );
		$( "td#db_range" ).html( db_range );

		$( "td#ob_strenght" ).html( ob_strenght );
		$( "td#ob_prayer" ).html( ob_prayer );

		$( "td#sr_defence" ).html( sr_defence );
		$( "td#sr_attack" ).html( sr_attack );
		$( "td#sr_strenght" ).html( sr_strenght );
		$( "td#sr_ranged" ).html( sr_ranged );
		$( "td#sr_magic" ).html( sr_magic );
		$( "td#sr_hitpoints" ).html( sr_hitpoints );
		$( "td#sr_prayer" ).html( sr_prayer );
		$( "td#sr_slayer" ).html( sr_slayer );

		$( "td#slot" ).html( slot );
		$( "td#class" ).html( item_class );
		$( "td#degradable" ).html( degradable );

		// Show results

		$( "div#search_results" ).show();
		$( "div#no_results" ).hide();

	} else {

		$( "div#search_results" ).hide();
		$( "div#no_results" ).show();

	};

};








// ***************************** Close *****************************










// Remove the loader

setTimeout( function() {
	$( "div#mw-head-base" ).fadeOut( 500 );
	$( "div#mw-page-base" ).fadeOut( 500 );
}, 600 );