User:BryghtShadow/wikia.js

function createCSS(items, size, url) { var _css = ""; _css+=".champion-list, .champion-list ol, .champion-list ul { list-style:none outside none; margin:0; }\n"; _css+=".champion-list li { display:inline-block; }\n"; _css+=".champion-list li > a {\n"; _css+=" display:inline-block;\n"; _css+=" background:url('" + url + "');\n"; _css+=" background-size:" + size*10 + "px;\n"; _css+=" height:" + size + "px;\n"; _css+=" width:" + size + "px;\n"; _css+="}\n"; _css+=".champion-list li > a > b { display:none; }\n"; $(items).each(function(index,value) {   _css+=".champion-list li > a[title=\"" + this + "\"] {";    _css+=" background-position: " + -size*(index%10) + "px " + -size*Math.floor(index/10) + "px; }\n";  }); return _css; }

function createHTML(items, size) { var _html=" &lt;div class=\"champion-list\"&gt;\n"; $(items).each(function(index,value) {   _html+="*" + this + "\n";  }); _html+="&lt;/div&gt; "; return _html; }

function createSpriteCSSHTML(items, size, url) { var _css = " "; _css+=createCSS(items, size, url); _css+=" \n";

var _html=createHTML(items, size); return _css + _html; }

$(document).ready(function { if ($(".page-User_BryghtShadow").length > 0){  $.get("http://leagueoflegends.wikia.com/wiki/Template:Champion_variable?action=raw", function(text) { var size = 48; var url = "http://images.wikia.com/leagueoflegends/images/2/2c/ChampionSquareSpritesheet.png";

var items = []; var write = false; var lines = text.split("\n"); $(lines).each(function(index,value) {     if (this.indexOf("") > -1) { write = true; }      if (this.indexOf("disp_name") > -1 && write && this.indexOf("Cougar") == -1) {        items.push($.trim(this.replace("disp_name", "").replace("|", "").replace("=", "")));      }    }); if (items.length > 0) { items.sort; if ( $("#champion-list").length > 0) { $("#champion-list").html(createSpriteCSSHTML(items, size, url)); console.log("Champions list complete"); }   } else { console.log("No items were found."); } });  }

if ($(".page-User_BryghtShadow_sandbox_champion-list").length > 0) { $.get("http://leagueoflegends.wikia.com/wiki/Template:Champion_variable?action=raw", function(text) {   var url = "http://images.wikia.com/leagueoflegends/images/2/2c/ChampionSquareSpritesheet.png";

var items = []; var write = false; var lines = text.split("\n"); $(lines).each(function(index,value) {     if (this.indexOf("") > -1) { write = true; }      if (this.indexOf("disp_name") > -1 && write && this.indexOf("Cougar") == -1) {        items.push($.trim(this.replace("disp_name", "").replace("|", "").replace("=", "")));      }    }); if (items.length > 0) { items.sort; if ($(".page-User_BryghtShadow_sandbox_champion-list").length > 0) { $("pre").each(function(index,value) {         var id = $(this).attr("id").match(/^champion-list(\d+)/)[1];          console.log(id);          $(this).html(createCSS(items, id, url));        }); console.log("Success"); }

} else { console.log("No items were found."); } });  } });