MediaWiki:Wikia.js/themeChanger.js

// ==UserScript== // @name          Wikia Theme Changer // @namespace     http://community.wikia.com/wiki/User:T3CHNOCIDE // @author        T3CHNOCIDE // @description   Allows registered users to set their theme to selection of pre-set themes. // @include       http://*.wikia.com/* // ==/UserScript==

/*COOKIE AND LOAD FUNCTIONS*/

//Sets function to create cookie function createCookie(name,value,days) { if (days) { var date = new Date; date.setTime(date.getTime+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString; }	else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; }

//Sets function to read cookie function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); }	return null; }

//Sets functions to erase cookies function eraseCookie(name) { createCookie(name,"",-1); }

//Checks theme choice and sets selected theme var theme_choice = readCookie('ThemeDesign');

function checkTheme { if (theme_choice == "Titan") {	$('link[href="http://t3chbox.wikia.com/__load/-/cb%3D62259%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26skin%3Doasis/site"]').remove; $('head').append($(' ').attr({'rel': 'stylesheet', 'href': 'http://t3chbox.wikia.com/wiki/MediaWiki:TitanTheme.css?action=raw&ctype=text/css'})); }	else if (theme_choice == "Warlock") {	$('link[href="http://t3chbox.wikia.com/__load/-/cb%3D62259%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26skin%3Doasis/site"]').remove; $('head').append($(' ').attr({'rel': 'stylesheet', 'href': 'http://t3chbox.wikia.com/wiki/MediaWiki:WarlockTheme.css?action=raw&ctype=text/css'})); }	else if (theme_choice == "Hunter") {	$('link[href="http://t3chbox.wikia.com/__load/-/cb%3D62259%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26skin%3Doasis/site"]').remove; $('head').append($(' ').attr({'rel': 'stylesheet', 'href': 'http://t3chbox.wikia.com/wiki/MediaWiki:HunterTheme.css?action=raw&ctype=text/css'})); }	else {	$('head').append($(' ').attr({'rel': 'stylesheet', 'href': 'http://t3chbox.wikia.com/__load/-/cb%3D62259%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26skin%3Doasis/site'})); createCookie('ThemeDesign','default',365) } }

//Adds My Themes option to account navigation if (wgUserName != null) { $('.AccountNavigation .subnav>li:first-child').remove; $('.AccountNavigation .subnav>li').remove; $('.AccountNavigation .subnav').prepend('Message WallMy preferencesMy ThemesHelp<a data-id="logout" href="/wiki/Special:UserLogout?returnto=User%3AT3CHNOCIDE%2FSandbox">Log out</a></li>'); } else {	$('.GlobalNavigation').append('<a id="OpenMyThemes" style="cursor:pointer;">My Themes</a></li>'); }

/*MENU FUNCTIONS*/

//Opens My Theme menu on selection $('#OpenMyThemes').click(function {	window.location.href = wgServer + "/index.php?title=Special:BlankPage&blankspecial=mythemes"; });

//Creates function to make My Themes menu function createMyThemesMenu { $('.AdminDashboardHeader h1').html('My Themes'); $('.AdminDashboardGeneralHeader h1').html( 'Change your Wikia theme!' ); $('#mw-content-text').html('                         '); }

//Creates My Themes menu on page load if( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Blankpage' && $.getUrlVar( 'blankspecial' ) === 'mythemes' ) { document.title = 'My Themes'; createMyThemesMenu; }

/*TRY FUNCTIONS*/

//Temporarily sets Titan theme on click $('#TitanThemeTry').click(function {	$('link[href="http://t3chbox.wikia.com/__load/-/cb%3D62259%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26skin%3Doasis/site"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:WarlockTheme.css?action=raw&ctype=text/css"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:HunterTheme.css?action=raw&ctype=text/css"]').remove;	$('head').append($(' ').attr({'rel': 'stylesheet', 'href': 'http://t3chbox.wikia.com/wiki/MediaWiki:TitanTheme.css?action=raw&ctype=text/css'})); });

//Temporarily sets Warlock theme on click $('#WarlockThemeTry').click(function {	$('link[href="http://t3chbox.wikia.com/__load/-/cb%3D62259%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26skin%3Doasis/site"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:TitanTheme.css?action=raw&ctype=text/css"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:HunterTheme.css?action=raw&ctype=text/css"]').remove;	$('head').append($(' ').attr({'rel': 'stylesheet', 'href': 'http://t3chbox.wikia.com/wiki/MediaWiki:WarlockTheme.css?action=raw&ctype=text/css'})); });

//Temporarily sets Hunter theme on click $('#HunterThemeTry').click(function {	$('link[href="http://t3chbox.wikia.com/__load/-/cb%3D62259%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26skin%3Doasis/site"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:TitanTheme.css?action=raw&ctype=text/css"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:WarlockTheme.css?action=raw&ctype=text/css"]').remove;	$('head').append($(' ').attr({'rel': 'stylesheet', 'href': 'http://t3chbox.wikia.com/wiki/MediaWiki:HunterTheme.css?action=raw&ctype=text/css'})); });

/*INSTALL FUNCTIONS*/ //Installs Titan theme on click $('#TitanThemeInstall').click(function {	createCookie('ThemeDesign','Titan',365)	$('link[href="http://t3chbox.wikia.com/__load/-/cb%3D62259%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26skin%3Doasis/site"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:WarlockTheme.css?action=raw&ctype=text/css"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:HunterTheme.css?action=raw&ctype=text/css"]').remove;	$('head').append($(' ').attr({'rel': 'stylesheet', 'href': 'http://t3chbox.wikia.com/wiki/MediaWiki:TitanTheme.css?action=raw&ctype=text/css'}));	location.reload });

//Installs Warlock theme on click $('#WarlockThemeInstall').click(function {	createCookie('ThemeDesign','Warlock',365)	$('link[href="http://t3chbox.wikia.com/__load/-/cb%3D62259%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26skin%3Doasis/site"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:TitanTheme.css?action=raw&ctype=text/css"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:HunterTheme.css?action=raw&ctype=text/css"]').remove;	$('head').append($(' ').attr({'rel': 'stylesheet', 'href': 'http://t3chbox.wikia.com/wiki/MediaWiki:WarlockTheme.css?action=raw&ctype=text/css'}));	location.reload });

//Installs Hunter theme on click $('#HunterThemeInstall').click(function {	createCookie('ThemeDesign','Hunter',365)	$('link[href="http://t3chbox.wikia.com/__load/-/cb%3D62259%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26skin%3Doasis/site"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:TitanTheme.css?action=raw&ctype=text/css"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:WarlockTheme.css?action=raw&ctype=text/css"]').remove;	$('head').append($(' ').attr({'rel': 'stylesheet', 'href': 'http://t3chbox.wikia.com/wiki/MediaWiki:HunterTheme.css?action=raw&ctype=text/css'}));	location.reload });

//Clears themes and refreshes page. $('#ResetTheme').click(function {	eraseCookie('ThemeDesign')	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:TitanTheme.css?action=raw&ctype=text/css"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:WarlockTheme.css?action=raw&ctype=text/css"]').remove;	$('link[href="http://t3chbox.wikia.com/wiki/MediaWiki:HunterTheme.css?action=raw&ctype=text/css"]').remove;	$('link[href="http://t3chbox.wikia.com/__load/-/cb%3D62259%26debug%3Dfalse%26lang%3Den%26only%3Dstyles%26skin%3Doasis/site"]').remove;	location.reload });

//Cancels changes and returns to set theme $('#CancelTheme').click(function {	checkTheme });

//Initialises theme on page load addOnloadHook(checkTheme);