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") || (pagename == "Sentient_Meat_Hook")) {      x = 0.2    }    $("#mx-calc").on("input", function { var y = parseFloat(((1 - 1 / (1 + x * $("#mx-calc").val)) * 100).toFixed(1)) $("#mx-out").text(y + "%") }) } // Exponential // H3AD-5T v2, Genesis Loop  else if ((pagename == "H3AD-5T_v2") || (pagename == "Genesis_Loop")) {    $("#calc-table tr:last").after("       ")    if (pagename == "H3AD-5T_v2") {      x = 10    }    else if (pagename == "Genesis_Loop") {      x = 30    }    $("#mx-calc").on("input", function { var y = parseFloat((x * Math.pow(0.5, Number($("#mx-calc").val) - 1)).toFixed(2)) $("#mx-out").text(y + "s") }) } // Exponential // Corpsebloom  else if (pagename == "Corpsebloom") {    $("#calc-table tr:last").after("       ")    $("#mx-calc").on("input", function { var y = parseFloat(((0.1 * Math.pow(0.5, Number($("#mx-calc").val) - 1)) * 100).toFixed(2)) $("#mx-out").text(y + "%") }) } // 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 { var x = $("#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("    <span id=\"mx-out\">   ")    $("#mx-calc").on("input", function { var y = parseFloat(((1 - 1 / Math.pow(1 + Number($("#mx-calc").val), 0.33)) * 100).toFixed(1)) $("#mx-out").text(y + "%") }) } // Special // Rusted Key  else if (pagename == "Rusted_Key") {    $("#calc-table tr:last").after("  <input id=\"mx-calc\" type=\"number\" min=\"1\" style=\"width:54px\">  <span id=\"mx-out1\">   <span id=\"mx-out2\">   <span id=\"mx-out3\">   ")    $("#mx-calc").on("input", function { var x = $("#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) + "%") }) } })

// Item tooltips $(document).on("mousemove", function(event) { $(".tooltip:hover > .tooltip-block").css( { "left": event.clientX + 10 + "px", "top": event.clientY + 20 + "px" } ) }) // Links titles $(function { $(".notitle, .tooltip").find("a").attr("title", "") })

// Ace Editor 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 })           if (editor.session.$modeId != "ace/mode/css") {              editor.setOptions({ tabSize: 2, wrap: true })           }          }        })      }    })  })  observer.observe(document.getElementsByClassName("mw-body")[0], { childList: true, subtree: true }) }

// Floating table header // https://dev.fandom.com/wiki/FloatingTableHeader if ($("table.floatheader").length) { window.setTimeout(waitForTablesorter, 200) }

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

function floatheader { $("table.floatheader").each(function {   $(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"> ")    var originalHeaderRow = $("tr:first", this)    var clonedHeaderRow = originalHeaderRow.clone    clonedHeaderRow.insertAfter(originalHeaderRow)    clonedHeaderRow.addClass("tableFloatingHeader")    clonedHeaderRow.css("position", "absolute")    clonedHeaderRow.css("top", "0")    clonedHeaderRow.css("left", $(this).css("margin-left"))    clonedHeaderRow.css("visibility", "hidden")    originalHeaderRow.addClass("tableFloatingHeaderOriginal")    // Remove transparency & sort buttons from floating header    $("th", clonedHeaderRow).each(function { // Transparency var bgcolors = $(this).css("background-color") if (bgcolors != "rgba(0, 0, 0, 0)") { $(this).css("background-color", "rgb(" + bgcolors.match(/\d+/g).slice(0, 3).join(", ") + ")") }     // Sort buttons if ($(this).hasClass("headerSort")) { $(this).removeClass("headerSort").removeAttr("tabindex").removeAttr("title") }     // 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 originalHeaderRow = $(".tableFloatingHeaderOriginal", this)      var floatingHeaderRow = $(".tableFloatingHeader", this)      var offset = $(this).offset      var scrollTop = $(window).scrollTop      if ((scrollTop > offset.top) && (scrollTop < offset.top + $(this).height)) {        floatingHeaderRow.css("visibility", "visible")        floatingHeaderRow.css("top", Math.min(scrollTop - offset.top, $(this).height - floatingHeaderRow.height) + "px")        // Copy cell widths from original header        $("th", floatingHeaderRow).each(function(index) { var cellWidth = $("th", originalHeaderRow).eq(index).css("width") $(this).css("width", cellWidth) })       // Copy row width from whole table        floatingHeaderRow.css("width", $(this).css("width"))      }      else {        floatingHeaderRow.css("visibility", "hidden")        floatingHeaderRow.css("top", "0")      }    }) } }