Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
(some odd attempt) |
m |
||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
− | $(' | + | $('.itemicon').on('error', function() { |
// Check if the image is already the default image to avoid infinite loop | // Check if the image is already the default image to avoid infinite loop | ||
− | if ($(this).attr('src') !== 'https://pokegenrpg.com/images/items/shining_chest.png') { // | + | if ($(this).attr('src') !== 'https://pokegenrpg.com/images/items/shining_chest.png') { // check wether default icon is used to prevent loops |
− | $(this).attr('src', 'https://pokegenrpg.com/images/items/shining_chest.png'); // | + | $(this).attr('src', 'https://pokegenrpg.com/images/items/shining_chest.png'); // item icon default set |
} | } | ||
}); | }); | ||
+ | function filterByType() { | ||
+ | var selectedType = document.getElementById("typeFilter").value; | ||
+ | var rows = document.querySelectorAll(".pokemonList tr"); | ||
− | // | + | rows.forEach(function(row, index) { |
+ | var typeCell = row.cells[2]; | ||
+ | if (index === 0) { | ||
+ | row.style.display = ""; | ||
+ | } else if (selectedType === "All" || typeCell.innerText.includes(selectedType)) { | ||
+ | row.style.display = ""; | ||
+ | } else { | ||
+ | row.style.display = "none"; | ||
+ | } | ||
+ | }); | ||
+ | } | ||
+ | // current month number, 0=jan | ||
var today = new Date().getMonth(); | var today = new Date().getMonth(); | ||
var logoUrl = ''; | var logoUrl = ''; | ||
Line 23: | Line 37: | ||
break; | break; | ||
} | } | ||
− | // Apply the selected logo to the .mw-wiki-logo element | + | // Apply the selected logo to the .mw-wiki-logo element, copy pasted |
$('.mw-wiki-logo').css({ | $('.mw-wiki-logo').css({ | ||
'background-image': 'url("' + logoUrl + '")', | 'background-image': 'url("' + logoUrl + '")', | ||
− | 'background-size': 'contain', | + | 'background-size': 'contain', |
− | 'width': '160px', | + | 'width': '160px', |
− | 'height': '160px' / | + | 'height': '160px' |
+ | }); | ||
+ | /* | ||
+ | * dynamically updates Pokémon stats based on variant and gender. | ||
+ | */ | ||
+ | function updateStats() { | ||
+ | var formType = document.getElementById("formType").value; // Get the selected form (Normal or Shiny) | ||
+ | var rows = document.querySelectorAll(".pokemonList tr"); // Get all rows of the stat table | ||
+ | var purifiedType = document.getElementById("genderselector").value; // Get the selected purified state (Normal or Purified) | ||
+ | |||
+ | rows.forEach(function(row, index) { | ||
+ | if (index !== 0) { // Skip the header row | ||
+ | var hpCell = row.querySelector(".basestathp"); | ||
+ | var atkCell = row.querySelector(".basestatatk"); | ||
+ | var defCell = row.querySelector(".basestatdef"); | ||
+ | var spaCell = row.querySelector(".basestatspa"); | ||
+ | var spdCell = row.querySelector(".basestatspd"); | ||
+ | var speCell = row.querySelector(".basestatspe"); | ||
+ | var totalCell= row.querySelector(".basestattotal"); | ||
+ | |||
+ | var purifiedMultiplier = (purifiedType === "Purified") ? 1.15 : 1; // 15% increase for Purified form (except HP) | ||
+ | // Get original stat values from data attributes | ||
+ | var originalHP = parseFloat(hpCell.getAttribute("data-original")); | ||
+ | var originalAtk = parseFloat(atkCell.getAttribute("data-original")); | ||
+ | var originalDef = parseFloat(defCell.getAttribute("data-original")); | ||
+ | var originalSpa = parseFloat(spaCell.getAttribute("data-original")); | ||
+ | var originalSpd = parseFloat(spdCell.getAttribute("data-original")); | ||
+ | var originalSpe = parseFloat(speCell.getAttribute("data-original")); | ||
+ | |||
+ | if (formType === "Shiny") { | ||
+ | // Apply the stat increase for Shiny | ||
+ | hpCell.innerText = Math.round(originalHP * 1.08); | ||
+ | atkCell.innerText = Math.round(originalAtk * purifiedMultiplier * 1.08); | ||
+ | defCell.innerText = Math.round(originalDef * purifiedMultiplier * 1.08); | ||
+ | spaCell.innerText = Math.round(originalSpa * purifiedMultiplier * 1.08); | ||
+ | spdCell.innerText = Math.round(originalSpd * purifiedMultiplier * 1.08); | ||
+ | speCell.innerText = Math.round(originalSpe * purifiedMultiplier * 1.04); | ||
+ | var total = | ||
+ | parseInt(hpCell.innerText) + | ||
+ | parseInt(atkCell.innerText) + | ||
+ | parseInt(defCell.innerText) + | ||
+ | parseInt(spaCell.innerText) + | ||
+ | parseInt(spdCell.innerText) + | ||
+ | parseInt(speCell.innerText); | ||
+ | totalCell.innerText = total; | ||
+ | } else if (formType === "Golden") { | ||
+ | hpCell.innerText = Math.round(originalHP * 1.16); | ||
+ | atkCell.innerText = Math.round(originalAtk * purifiedMultiplier * 1.16); | ||
+ | defCell.innerText = Math.round(originalDef * purifiedMultiplier * 1.16); | ||
+ | spaCell.innerText = Math.round(originalSpa * purifiedMultiplier * 1.16); | ||
+ | spdCell.innerText = Math.round(originalSpd * purifiedMultiplier * 1.16); | ||
+ | speCell.innerText = Math.round(originalSpe * purifiedMultiplier * 1.08); | ||
+ | var total = | ||
+ | parseInt(hpCell.innerText) + | ||
+ | parseInt(atkCell.innerText) + | ||
+ | parseInt(defCell.innerText) + | ||
+ | parseInt(spaCell.innerText) + | ||
+ | parseInt(spdCell.innerText) + | ||
+ | parseInt(speCell.innerText); | ||
+ | totalCell.innerText = total; | ||
+ | } else if (formType === "Midnight") { | ||
+ | // Apply the stat increase for Shiny | ||
+ | hpCell.innerText = Math.round(originalHP); | ||
+ | atkCell.innerText = Math.round(originalAtk * purifiedMultiplier * 1.2); | ||
+ | defCell.innerText = Math.round(originalDef * purifiedMultiplier * 0.85); | ||
+ | spaCell.innerText = Math.round(originalSpa * purifiedMultiplier * 1.2); | ||
+ | spdCell.innerText = Math.round(originalSpd * purifiedMultiplier * 0.85); | ||
+ | speCell.innerText = Math.round(originalSpe * purifiedMultiplier * 1.1); | ||
+ | var total = | ||
+ | parseInt(hpCell.innerText) + | ||
+ | parseInt(atkCell.innerText) + | ||
+ | parseInt(defCell.innerText) + | ||
+ | parseInt(spaCell.innerText) + | ||
+ | parseInt(spdCell.innerText) + | ||
+ | parseInt(speCell.innerText); | ||
+ | totalCell.innerText = total; | ||
+ | } else if (formType === "Snow") { | ||
+ | hpCell.innerText = Math.round(originalHP*1.17); | ||
+ | atkCell.innerText = Math.round(originalAtk * purifiedMultiplier); | ||
+ | defCell.innerText = Math.round(originalDef * purifiedMultiplier * 1.15); | ||
+ | spaCell.innerText = Math.round(originalSpa * purifiedMultiplier); | ||
+ | spdCell.innerText = Math.round(originalSpd * purifiedMultiplier * 1.15); | ||
+ | speCell.innerText = Math.round(originalSpe * purifiedMultiplier * 0.94); | ||
+ | var total = | ||
+ | parseInt(hpCell.innerText) + | ||
+ | parseInt(atkCell.innerText) + | ||
+ | parseInt(defCell.innerText) + | ||
+ | parseInt(spaCell.innerText) + | ||
+ | parseInt(spdCell.innerText) + | ||
+ | parseInt(speCell.innerText); | ||
+ | totalCell.innerText = total; | ||
+ | } else { | ||
+ | // Set stats back to Normal | ||
+ | hpCell.innerText = Math.round(originalHP); | ||
+ | atkCell.innerText = Math.round(originalAtk * purifiedMultiplier); | ||
+ | defCell.innerText = Math.round(originalDef * purifiedMultiplier); | ||
+ | spaCell.innerText = Math.round(originalSpa * purifiedMultiplier); | ||
+ | spdCell.innerText = Math.round(originalSpd * purifiedMultiplier); | ||
+ | speCell.innerText = Math.round(originalSpe * purifiedMultiplier); | ||
+ | var total = | ||
+ | parseInt(hpCell.innerText) + | ||
+ | parseInt(atkCell.innerText) + | ||
+ | parseInt(defCell.innerText) + | ||
+ | parseInt(spaCell.innerText) + | ||
+ | parseInt(spdCell.innerText) + | ||
+ | parseInt(speCell.innerText); | ||
+ | totalCell.innerText = total; | ||
+ | } | ||
+ | } | ||
}); | }); | ||
+ | } |
Latest revision as of 14:29, 18 October 2024
/* Any JavaScript here will be loaded for all users on every page load. */ $('.itemicon').on('error', function() { // Check if the image is already the default image to avoid infinite loop if ($(this).attr('src') !== 'https://pokegenrpg.com/images/items/shining_chest.png') { // check wether default icon is used to prevent loops $(this).attr('src', 'https://pokegenrpg.com/images/items/shining_chest.png'); // item icon default set } }); function filterByType() { var selectedType = document.getElementById("typeFilter").value; var rows = document.querySelectorAll(".pokemonList tr"); rows.forEach(function(row, index) { var typeCell = row.cells[2]; if (index === 0) { row.style.display = ""; } else if (selectedType === "All" || typeCell.innerText.includes(selectedType)) { row.style.display = ""; } else { row.style.display = "none"; } }); } // current month number, 0=jan var today = new Date().getMonth(); var logoUrl = ''; // Set the logo based on the month switch (today) { case 9: // October logoUrl = 'https://pokegenrpg.com/images/pokemon/Normal/249xd.png'; break; case 11: logoUrl = 'https://pokegenrpg.com/images/pokemon/Golden/947_1.png'; break; default: logoUrl = './logo.png'; break; } // Apply the selected logo to the .mw-wiki-logo element, copy pasted $('.mw-wiki-logo').css({ 'background-image': 'url("' + logoUrl + '")', 'background-size': 'contain', 'width': '160px', 'height': '160px' }); /* * dynamically updates Pokémon stats based on variant and gender. */ function updateStats() { var formType = document.getElementById("formType").value; // Get the selected form (Normal or Shiny) var rows = document.querySelectorAll(".pokemonList tr"); // Get all rows of the stat table var purifiedType = document.getElementById("genderselector").value; // Get the selected purified state (Normal or Purified) rows.forEach(function(row, index) { if (index !== 0) { // Skip the header row var hpCell = row.querySelector(".basestathp"); var atkCell = row.querySelector(".basestatatk"); var defCell = row.querySelector(".basestatdef"); var spaCell = row.querySelector(".basestatspa"); var spdCell = row.querySelector(".basestatspd"); var speCell = row.querySelector(".basestatspe"); var totalCell= row.querySelector(".basestattotal"); var purifiedMultiplier = (purifiedType === "Purified") ? 1.15 : 1; // 15% increase for Purified form (except HP) // Get original stat values from data attributes var originalHP = parseFloat(hpCell.getAttribute("data-original")); var originalAtk = parseFloat(atkCell.getAttribute("data-original")); var originalDef = parseFloat(defCell.getAttribute("data-original")); var originalSpa = parseFloat(spaCell.getAttribute("data-original")); var originalSpd = parseFloat(spdCell.getAttribute("data-original")); var originalSpe = parseFloat(speCell.getAttribute("data-original")); if (formType === "Shiny") { // Apply the stat increase for Shiny hpCell.innerText = Math.round(originalHP * 1.08); atkCell.innerText = Math.round(originalAtk * purifiedMultiplier * 1.08); defCell.innerText = Math.round(originalDef * purifiedMultiplier * 1.08); spaCell.innerText = Math.round(originalSpa * purifiedMultiplier * 1.08); spdCell.innerText = Math.round(originalSpd * purifiedMultiplier * 1.08); speCell.innerText = Math.round(originalSpe * purifiedMultiplier * 1.04); var total = parseInt(hpCell.innerText) + parseInt(atkCell.innerText) + parseInt(defCell.innerText) + parseInt(spaCell.innerText) + parseInt(spdCell.innerText) + parseInt(speCell.innerText); totalCell.innerText = total; } else if (formType === "Golden") { hpCell.innerText = Math.round(originalHP * 1.16); atkCell.innerText = Math.round(originalAtk * purifiedMultiplier * 1.16); defCell.innerText = Math.round(originalDef * purifiedMultiplier * 1.16); spaCell.innerText = Math.round(originalSpa * purifiedMultiplier * 1.16); spdCell.innerText = Math.round(originalSpd * purifiedMultiplier * 1.16); speCell.innerText = Math.round(originalSpe * purifiedMultiplier * 1.08); var total = parseInt(hpCell.innerText) + parseInt(atkCell.innerText) + parseInt(defCell.innerText) + parseInt(spaCell.innerText) + parseInt(spdCell.innerText) + parseInt(speCell.innerText); totalCell.innerText = total; } else if (formType === "Midnight") { // Apply the stat increase for Shiny hpCell.innerText = Math.round(originalHP); atkCell.innerText = Math.round(originalAtk * purifiedMultiplier * 1.2); defCell.innerText = Math.round(originalDef * purifiedMultiplier * 0.85); spaCell.innerText = Math.round(originalSpa * purifiedMultiplier * 1.2); spdCell.innerText = Math.round(originalSpd * purifiedMultiplier * 0.85); speCell.innerText = Math.round(originalSpe * purifiedMultiplier * 1.1); var total = parseInt(hpCell.innerText) + parseInt(atkCell.innerText) + parseInt(defCell.innerText) + parseInt(spaCell.innerText) + parseInt(spdCell.innerText) + parseInt(speCell.innerText); totalCell.innerText = total; } else if (formType === "Snow") { hpCell.innerText = Math.round(originalHP*1.17); atkCell.innerText = Math.round(originalAtk * purifiedMultiplier); defCell.innerText = Math.round(originalDef * purifiedMultiplier * 1.15); spaCell.innerText = Math.round(originalSpa * purifiedMultiplier); spdCell.innerText = Math.round(originalSpd * purifiedMultiplier * 1.15); speCell.innerText = Math.round(originalSpe * purifiedMultiplier * 0.94); var total = parseInt(hpCell.innerText) + parseInt(atkCell.innerText) + parseInt(defCell.innerText) + parseInt(spaCell.innerText) + parseInt(spdCell.innerText) + parseInt(speCell.innerText); totalCell.innerText = total; } else { // Set stats back to Normal hpCell.innerText = Math.round(originalHP); atkCell.innerText = Math.round(originalAtk * purifiedMultiplier); defCell.innerText = Math.round(originalDef * purifiedMultiplier); spaCell.innerText = Math.round(originalSpa * purifiedMultiplier); spdCell.innerText = Math.round(originalSpd * purifiedMultiplier); speCell.innerText = Math.round(originalSpe * purifiedMultiplier); var total = parseInt(hpCell.innerText) + parseInt(atkCell.innerText) + parseInt(defCell.innerText) + parseInt(spaCell.innerText) + parseInt(spdCell.innerText) + parseInt(speCell.innerText); totalCell.innerText = total; } } }); }