User:Starfleet Academy/global.js

//IMPORTS //Importing 'Wikimarks' gadget by Pecoes importScriptPage('Client.js', 'wikimarks'); //END importing gadget //END Imports

//(window.mw = window.mw || {}).config = window.mw.config || { get: function(p) { return window[p]; } };

//This class makes a URL friendly version of passed wgVariables -- by Starfleet Academy function FixWgVariable(wgVariable) { this.variable = wgVariable; this.encodeURL = function { var variable = this.variable; var findDQuotes = new RegExp('"');   var findAmps = new RegExp('&');        if (findDQuotes.test(variable) === true && findAmps.test(variable) === true) {            variable = variable.replace(/"/g, '%22'); variable = variable.replace(/&/g, '%26'); }       return variable; }; }

var getPageName = mw.config.get("wgPageName"); var fixPageName = new FixWgVariable(getPageName);

//Adds recent changes button to Main header -- by Starfleet Academy $(function navRC { var blankimgurl=mw.config.get('wgBlankImgUrl'); if (mw.config.get('wgAction') == "edit" || mw.config.get('wgPageName') == "User:Starfleet_Academy/Wikimarks") { $('.WikiaHeader .GlobalNavigation').append('RC  ');} else {  $('.WikiaHeader .GlobalNavigation').append('RC  ');} }); //END adding recent changes button

//Adds links to my blog, contribs & watchlist //under talkpage link in account nav (drop-down) -- by Starfleet Academy $(function accnavLinks { var server = mw.config.get('wgServer'),    pagename = mw.config.get('wgPageName'),     DBname = mw.config.get('wgDBname'),     CCwiki = "http://community.wikia.com";  if ( DBname != "admintools" ) {    if ( pagename == "Wikia" ) {      $('.WikiaHeader .AccountNavigation .subnav > li:first-child').after('My blog<a data-id="mycontribs" href="' + CCwiki + '/wiki/Special:Contributions/Starfleet_Academy">Contributions</a></li><a data-id="mywatchlist" href="' + CCwiki + '/wiki/Special:Following">Followed pages</a></li>');    }    else {      $('.WikiaHeader .AccountNavigation .subnav > li:first-child').after('<a data-id="myblog" href="/wiki/User_blog:Starfleet_Academy">My blog</a></li><a data-id="mycontribs" href="/wiki/Special:Contributions/Starfleet_Academy">Contributions</a></li><a data-id="mywatchlist" href="/wiki/Special:Following">Followed pages</a></li>'); } } }); //END adding links to Account nav

//Adds purge link to edit menu -- by Starfleet Academy $(function purgeLink { var pageName = fixPageName.encodeURL; if (mw.config.get('wgPageName') != "User:Starfleet_Academy/Wikimarks") { $('.WikiaPageHeader .wikia-menu-button .WikiaMenuElement > li:first-child').before('<a href="/index.php?title='+ pageName +'&action=purge" data-id="purge">Purge</a></li>'); }; if (mw.config.get('wgCanonicalNamespace') == "User", "User_talk") { $('.UserProfileActionButton .wikia-menu-button .WikiaMenuElement > li:first-child').before('<a href="/index.php?title='+ pageName +'&action=purge" data-id="purge">Purge</a></li>');} }); //END adding purge button

//Adds a "return to page top" link on the toolbar -- by Starfleet Academy $(function beamMeUp { var server=mw.config.get('wgServer'),   pagename=mw.config.get('wgPageName'); if (mw.config.get('wgAction') == "view" || mw.config.get('wgCanonicalNamespace') == "Message_Wall" || mw.config.get('wgCanonicalNamespace') == "Thread") {  $('.skin-oasis .WikiaBarWrapper .toolbar .tools').append('<a href="'+ server +'/wiki/'+ pagename +'#" class="to-top-link" title="Return to page home">Top</a></li>');} }); //END top-returning link

//Adds a tabindex of 2 to the link at the top of the editor $(function {   $('#EditPageHeader h1 > a').attr('tabindex', '2'); }); //END adding tabindex

//Changes the contribute button to a random page button //And adds a random in cat button on category pages -- by Starfleet Academy $(function { var server=mw.config.get('wgServer'),   title=mw.config.get('wgTitle'); $('.WikiHeaderRestyle .buttons .contribute').replaceWith('<a href="'+ server +'/wiki/Special:Random" title="Random Page" class="wikia-button secondary" data-id="randompage"><img src="data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D" height="0" width="0" class="sprite random" /> Random Page</a>');  if (mw.config.get('wgCanonicalNamespace') == "Category") { $('.WikiHeaderRestyle .buttons').append('<a href="'+ server +'/wiki/Special:RandomInCategory/'+ title +'" target="_blank" title="Random Page" class="wikia-button secondary" data-id="randompage"><img src="data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D" height="0" width="0" class="sprite random" /> RIC</a>');} }); //END random page button.

//Edit button customz if ( mwCustomEditButtons ) { mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images3.wikia.nocookie.net/central/images/1/11/Button_category.png", "speedTip": "Category", "tagOpen": "[[Category:",		"sampleText": "Insert cat"       }; }; //END edit button customz