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 = 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 { var 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 { var 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) + "%") }) } })

// 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"    }) }) // Set window width once, when mouse enters a tooltip  $(".tooltip").mouseenter(function { windowWidthMax = $(window).width - 555 }) 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(window.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        window.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        window.history.replaceState(null, "", "Lore")        $(".lore").parent.show        $("#count").text("")      }    }  } })

// 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")      }    }) } }