User:SubAqua/wikia.js

// http://www.netlobo.com/url_query_string_javascript.html function getParam(name) { name = name.replace(/[\[]/, '\\\[').replace(/[\]]/, '\\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(window.location.href); if (results == null) return ''; else return decodeURIComponent(results[1].replace(/\+/g, '%20')); } function setSkin(newskin) { document.cookie = "useSkin=" + newskin; location.href = getSkinHref(location.href, newskin); } function getSkinHref(href, newskin) {   var anchor = ""; if (href.indexOf("#") != -1) {     href = href.split("#"); anchor = "#" + href[1]; href = href[0]; }   href = href.replace(/useskin=[^&]*/gi, "").replace(/\&+/gi, "&").replace(/\?\&/gi, "?").replace(/[\&\?]$/, ""); if (href.indexOf("?") != -1) return href + "&useskin=" + newskin + anchor; else return href + "?useskin=" + newskin + anchor; } $(function{ /* Add switch buttons - modified from http://dev.wikia.com/index.php?title=SkinSwitchButton/beta.js */  switch (skin)  {    case 'answers': //pass to monaco    case 'awesome':    case 'monaco':      var li = $(" ");      var img = $(" ");      img.attr("src", "/skins/common/blank.gif").addClass("sprite search");      var a = $("");      a.attr("id", "ca-skins").attr("rel", "nofollow").attr("href", getSkinHref(document.location.href, "wikia")).text("Oasis");      li.append(img).append(a);      $("#page_controls").append(li);      break;    case 'uncyclopedia': //pass to monobook    case 'wikiaphone':    case 'monobook': //        $('Monaco Oasis').appendTo('#p-cactions > .pBody > ul'); //Too lazy to code in monobook so far break; case 'oasis': case 'wikia': var li = $(" "); li.attr("id", "ca-skins"); var a = $(""); a.attr("id", "ca-skins").attr("rel", "nofollow").attr("href", getSkinHref(document.location.href, "answers")).text("Monaco"); li.append(a); $("#WikiHeader>nav>ul").append(li); break; } /* Get current skin setting */ var curskin = getParam("useskin"); var cookie = document.cookie.match('(^|;) ?useSkin=([^;]*)(|$)'); var newskin = curskin? curskin : cookie? unescape(cookie[2]) : "monaconew"; /* Check location */ if(location.href.indexOf("useskin=" + newskin) == -1 && newskin != "wikia") setSkin(newskin); /* Alter all internal links to include useskin=newskin */ $("a[href^='/'],a[href*='.wikia.com/']").each(function{   if ($(this).attr("href").indexOf("useskin=") == -1)      $(this).attr("href", getSkinHref($(this).attr("href"), newskin));  }); });