MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */

var pagename = mw.config.get("wgPageName") // Calculators $(function { var x // Hyperbolic // Stun Grenade, Tougher Times, Old Guillotine, Sentient Meat Hook  if ((pagename == "Stun_Grenade") || (pagename == "Tougher_Times") || (pagename == "Old_Guillotine") || (pagename == "Sentient_Meat_Hook")) {    $("#calc-table tr:last").after("       ")    if (pagename == "Stun_Grenade") {      x = 0.05    }    else if (pagename == "Tougher_Times") {      x = 0.15    }    else if (pagename == "Old_Guillotine") {      x = 0.13    }    else if (pagename == "Sentient_Meat_Hook") {      x = 0.2    }    $("#mx-calc").on("input", function { var y = Math.min(((1 - 1 / (1 + x * Number($("#mx-calc").val))) * 100).toFixed(1), 99.9) $("#mx-out").text(y + "%") }) } // Exponential // Genesis Loop  else if (pagename == "Genesis_Loop") {    $("#calc-table tr:last").after("       ")    $("#mx-calc").on("input", function { var y = Math.max((30 / (Number($("#mx-calc").val) + 1)).toFixed(2), 0.01) $("#mx-out").text(y + "s") }) } // Exponential (Equipment) // Fuel Cell, Gesture of the Drowned  else if ((pagename == "Fuel_Cell") || (pagename == "Gesture_of_the_Drowned")) {    $("#calc-table tr:last").after("                            ")    $("#mx-calc").on("input", function { x = Number($("#mx-calc").val) if (pagename == "Fuel_Cell") { x = Math.pow(0.85, x)     } else { x = 0.5 * Math.pow(0.85, x - 1) }     $("#mx-out1").text(parseFloat((15 * x).toFixed(1))) $("#mx-out2").text(parseFloat((20 * x).toFixed(1))) $("#mx-out3").text(parseFloat((30 * x).toFixed(1))) $("#mx-out4").text(parseFloat((45 * x).toFixed(1))) $("#mx-out5").text(parseFloat((60 * x).toFixed(1))) $("#mx-out6").text(parseFloat((100 * x).toFixed(1))) $("#mx-out7").text(parseFloat((140 * x).toFixed(1))) $("#mx-out8").text(parseFloat(((1 - x) * 100).toFixed(1)) + "%") }) } // Special // Bandolier  else if (pagename == "Bandolier") {    $("#calc-table tr:last").after("       ")    $("#mx-calc").on("input", function { var y = Math.min(((1 - 1 / Math.pow(1 + Number($("#mx-calc").val), 0.33)) * 100).toFixed(1), 99.9) $("#mx-out").text(y + "%") }) } // Special // Rusted Key  else if (pagename == "Rusted_Key") {    $("#calc-table tr:last").after("    <span id=\"mx-out1\">   <span id=\"mx-out2\">   <span id=\"mx-out3\">   ")    $("#mx-calc").on("input", function { x = Number($("#mx-calc").val) var y = 80 + 20*x + Math.pow(x, 2) $("#mx-out1").text((80 / y * 100).toFixed(2) + "%") $("#mx-out2").text((20*x / y * 100).toFixed(2) + "%") $("#mx-out3").text((Math.pow(x, 2) / y * 100).toFixed(2) + "%") }) } // Armor  else if (pagename == "Armor") {    $("#calc-table tr:last").after("  <input id=\"mx-calc\" type=\"number\" style=\"width:54px\">  <span id=\"mx-out\">   ")    $("#mx-calc").on("input", function { x = Number($("#mx-calc").val) if (x >= 0) { x = x / (100 + x)     } else { x = 100 / (100 - x) - 1 }     var y = Math.min(Math.max((x * 100).toFixed(2), -99.9), 99.9) $("#mx-out").text(y + "%") }) } })

// Item tooltips $(function { // Update tooltip position  $(".tooltip").mousemove(function { var x = Math.min(event.clientX, windowWidthMax) $(".tooltip-block", this).css({     "left": x + 10 + "px",      "top": event.clientY + 20 + "px"    }) }) windowWidthMax = $(window).width - 555  // Links' titles  $(".notitle, .tooltip").find("a").attr("title", "") })

// Lore page filter $(function { if (pagename == "Lore") {    //--- Create input & button    $("#toc").after(" <input id=\"search\" style=\"width:15em\"> <button id=\"filter\" style=\"width:4em\">Filter <span id=\"count\" style=\"color:#808080\"> ")    var total = $(".lore").length    //--- Get URL "?s=" param & filter it    var s = new URLSearchParams(location.search).get("s")    if (s) {      $("#search").val(decodeURI(s))      filter    }    //--- Bind events    $("#filter").click(filter)    $("#search").keyup(function(e) { if (e.keyCode == 13) { filter }   })    //--- filter    function filter {      var search = $("#search").val.toLowerCase      //--- Remove previous highlights      $(".lore-highlight").contents.unwrap      if (search) {        //--- Set URL "?s=" param to search value        history.replaceState(null, "", "Lore?s=" + encodeURI(search))        //--- Show matching entries & hide non-matching        var c = 0        $(".lore").each(function { if ($(this).text.toLowerCase.includes(search)) { //--- Highlight matching text $(this).html($(this).html.replace(/ /g, String.fromCharCode(1)).replace(/<\/span>/g, String.fromCharCode(2)).replace(new RegExp("(" + search.replace(/[-[\]{}*+?.\\^$|]/g, "\\$&") + ")", "gi"), "<span class=\"lore-highlight\" style=\"background:#187D20\">$1 ").replace(new RegExp(String.fromCharCode(1), "g"), "<span class=\"mono\">").replace(new RegExp(String.fromCharCode(2), "g"), " ")) $(this).parent.show c++ }         else { $(this).parent.hide }       })        //--- Display results count        $("#count").text("(" + c + " results)")      }      else {        //--- Set everything back to default        history.replaceState(null, "", "Lore")        $(".lore").parent.show        $("#count").text("")      }    }  } })

// Ace Editor $(function { if ((mw.config.get("wgAction") == "edit") && ((mw.config.get("wgNamespaceNumber") == 8) || (mw.config.get("wgNamespaceNumber") == 828))) {    var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) {       var newNodes = mutation.addedNodes        if (newNodes !== null) {          $(newNodes).each(function { if ($(this).hasClass("ace_content")) { observer.disconnect $(".ui-resizable").height(660) var editor = ace.edit(document.getElementsByClassName("ace_editor")[0]) editor.setOptions({               theme: "ace/theme/solarized_dark",                useSoftTabs: true,                printMargin: false,                wrap: true,                scrollPastEnd: 0.05              }) if (editor.session.$modeId != "ace/mode/css") { editor.setOptions({                 tabSize: 2                }) }           }          })        }      })    })    observer.observe(document.getElementsByClassName("mw-body")[0], { childList: true, subtree: true })  } })

// Floating table header $(function { if ($("table.floatheader").length) {    setTimeout(waitForTablesorter, 200)  }  function waitForTablesorter {    if ($("table.sortable").length == $("table.sortable.jquery-tablesorter").length) {      floatheader    }    else {      setTimeout(waitForTablesorter, 200)    }  } })

function floatheader { $("table.floatheader").each(function {   $(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"> ")

//--- If there is no thead, put all header rows into a thead if (!$("thead", this).length) { var thead = $(" ") $("> tbody > tr", this).each(function {       if ($("> td", this).length) {          return false        }        thead.append(this)      }) thead.insertBefore($("> tbody", this)) }

var originalHeader = $("thead", this) var clonedHeader = originalHeader.clone.hide clonedHeader.insertAfter(originalHeader)

originalHeader.addClass("tableFloatingHeaderOriginal") clonedHeader.addClass("tableFloatingHeader") clonedHeader.css("position", "absolute") clonedHeader.css("top", "0") clonedHeader.css("left", $(this).css("margin-left"))

//--- Floating Header $("th", clonedHeader).each(function {     //--- Remove Sort Buttons      if ($(this).hasClass("headerSort")) {        $(this).removeClass("headerSort").removeAttr("tabindex").removeAttr("title")      }

//--- Remove Collapsible Toggle Button $(".mw-collapsible-toggle", this).remove

//--- Remove Transparency var bgcolors = $(this).css("background-color") if (bgcolors.charAt(3) == "a" && bgcolors != "rgba(0, 0, 0, 0)") { $(this).css("background-color", "rgb(" + bgcolors.match(/\d+/g).slice(0, 3).join(", ") + ")") }

//--- Handle collapsible columns if ($(this).hasClass("mw-made-collapsible")) { $(this).removeClass("mw-made-collapsible").makeCollapsible }   })  })

UpdateTableHeaders $(window).scroll(UpdateTableHeaders).resize(UpdateTableHeaders)

function UpdateTableHeaders { $("div.divTableWithFloatingHeader").each(function {     var offset = $(this).offset      var scrollTop = $(window).scrollTop      var floatingHeader = $(".tableFloatingHeader", this)      if (scrollTop > offset.top && scrollTop < offset.top + $(this).height) {        var originalHeader = $(".tableFloatingHeaderOriginal", this)

floatingHeader.css("top", Math.min(scrollTop - offset.top, $(this).height - floatingHeader.height - $("tr:last", this).height) + "px").show

//--- Copy cell widths & horizontal padding from original header $("th", floatingHeader).each(function(i) {         var oh = $("th", originalHeader).eq(i)          $(this).css("width", oh.css("width"))          $(this).css("padding-left", oh.css("padding-left"))          $(this).css("padding-right", oh.css("padding-right"))        })

//--- Copy width from original thead -- Add 1px to wikitables floatingHeader.css("width", originalHeader.width + +$("> table", this).hasClass("wikitable") + "px") }     else { floatingHeader.hide }   })  } }