MediaWiki

Gadget-breadcrumbs.js

From Dogcraft Wiki

Revision as of 13:05, 11 September 2021 by Domino (talk | contribs)

Note: After publishing, 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 / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
$(document).ready(function() {
	
	function worldCat( pageCats ) {
		var world;
		for (var i = 0; i < pageCats.length; i++) {
			if ( pageCats[i].indexOf('Survival ') > -1) {
	    		world = pageCats[i] + '';
	        	return world;
			}
		}
		return "";
	}
	
	var config =  mw.config.get([
		"wgIsArticle",
		"wgNamespaceNumber",
		"wgCategories",
		"wgTitle"
		]);
	
	if ( config.wgIsArticle && ( config.wgNamespaceNumber == 0 && config.wgTitle !== "Main Page")) {
		//var namespace = mw.config.get('wgFormattedNamespaces')[mw.config.get('wgNamespaceNumber')];
		var serverInfo = "",
			siteContent = "",
			type = "",
			list = "",
			typeCategories = [
				"Events",
				"Settlements",
				"Groups",
				"Phenomenon",
				"Projects",
				"Worlds"
				],
			pageCategories = config.wgCategories,
			links = [],
			crumbs = "<a href='/wiki/Main_Page'><span>Main Page</span></a>";
		
		if (pageCategories.includes('Site Content')) {
			links.push( "Site Content" );
		}	
		
		if (pageCategories.includes('Server Information')) {
			links.push( "Server Information" );
		}
		
		var world = '';
		if ( worldCat( pageCategories ) !== "") {
			links.push( worldCat( pageCategories ) );
		}
		
		if (pageCategories.includes('Builds')) {
			links.push( "Builds" );
			for (var i = 0; i < pageCategories.length; i++) {
				switch (pageCategories[i]) {
					case 'Bases':
						links.push( "Bases" );
						break;
					case 'Stations':
						links.push( "Stations" );
						break;
					case 'Shelters':
						links.push( "Shelters" );
						break;
					default:
						break;
				}
			}
			
		}
		else
		{
			var typesOnPage = pageCategories.filter(function(x){ return typeCategories.includes(x) });
			if ( typesOnPage.length == 1) {
				links.push( typesOnPage[0] + "" );
			}
			else if (typesOnPage.length > 1) {
				console.log('Breadcrumbs: Page has more than one type category');
				links.push( typesOnPage[0] + "" );
			}
		}
		
		if (pageCategories.includes('Lists')) {
			links.push( "Lists" );
		}
		
		links.forEach( function( elem ) {
			crumbs += '<a href="/wiki/Category:' + elem + '">' + '<span>' + elem + '</span>' + '</a>';
		});
		
		if( links !== "undefined") {
		
			$('.top .indicators').prepend('<div id="breadcrumbs"></div>');
			$('#breadcrumbs').html('' + crumbs + '<span>' + config.wgTitle + '</span>' );
			
		}
		else { console.log(' Breadcrumbs: links is undefined '); }
	
	}
	
	if (mw.config.get('wgPageName') === "Rules")
	{
		$('#tagline').hide();
		$('#breadcrumbs > a').slice(1).hide();
		$('#breadcrumbs a:first-child').attr('href', '//dogcraft.net');
		$('#breadcrumbs a:first-child').text('Dogcraft.net');
	}

		
});
This page was last modified on 11 September 2021, at 13:05. (8 months ago)
Background Dragon Slayer - Retriever by Ironboundred