User:LaluShi/common.js: Difference between revisions
From Growtopia Wiki
More actions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
document.addEventListener('DOMContentLoaded', function() { | |||
// Check if we are on the page where we want to insert the XP calculation box | // Check if we are on the page where we want to insert the XP calculation box | ||
if (mw.config.get('wgCanonicalNamespace') === 'User_blog' && mw.config.get('wgAction') === 'view') { | if (mw.config.get('wgCanonicalNamespace') === 'User_blog' && mw.config.get('wgAction') === 'view') { | ||
// Create | // Create the XP calculation box | ||
var xpCalculationBox = '<h2>XP Calculation</h2>' + | var xpCalculationBox = document.createElement('div'); | ||
xpCalculationBox.innerHTML = '<h2>XP Calculation</h2>' + | |||
'<div>' + | '<div>' + | ||
' <label for="rValue">Enter the rarity (R):</label>' + | ' <label for="rValue">Enter the rarity (R):</label>' + | ||
' <input type="number" id="rValue" min="0" step="1">' + | ' <input type="number" id="rValue" min="0" step="1">' + | ||
' <button | ' <button id="calculateBtn">Calculate XP</button>' + | ||
'</div>' + | '</div>' + | ||
'<div>' + | '<div>' + | ||
| Line 14: | Line 15: | ||
// Insert the XP calculation box into the page | // Insert the XP calculation box into the page | ||
document.querySelector('.mw-parser-output').prepend(xpCalculationBox); | |||
// Function to calculate XP when the button is clicked | // Function to calculate XP when the button is clicked | ||
document.getElementById('calculateBtn').addEventListener('click', function() { | |||
// Get the value of R from the input field | // Get the value of R from the input field | ||
var r = parseInt( | var r = parseInt(document.getElementById('rValue').value); | ||
// Calculate E using the formula E = 1 + floor(R / 5) | // Calculate E using the formula E = 1 + floor(R / 5) | ||
| Line 25: | Line 26: | ||
// Display the result | // Display the result | ||
document.getElementById('xpResult').textContent = "XP Earned: " + e; | |||
}; | }); | ||
} | } | ||
}); | }); | ||
Revision as of 21:22, 14 May 2024
document.addEventListener('DOMContentLoaded', function() {
// Check if we are on the page where we want to insert the XP calculation box
if (mw.config.get('wgCanonicalNamespace') === 'User_blog' && mw.config.get('wgAction') === 'view') {
// Create the XP calculation box
var xpCalculationBox = document.createElement('div');
xpCalculationBox.innerHTML = '<h2>XP Calculation</h2>' +
'<div>' +
' <label for="rValue">Enter the rarity (R):</label>' +
' <input type="number" id="rValue" min="0" step="1">' +
' <button id="calculateBtn">Calculate XP</button>' +
'</div>' +
'<div>' +
' <p id="xpResult"></p>' +
'</div>';
// Insert the XP calculation box into the page
document.querySelector('.mw-parser-output').prepend(xpCalculationBox);
// Function to calculate XP when the button is clicked
document.getElementById('calculateBtn').addEventListener('click', function() {
// Get the value of R from the input field
var r = parseInt(document.getElementById('rValue').value);
// Calculate E using the formula E = 1 + floor(R / 5)
var e = 1 + Math.floor(r / 5);
// Display the result
document.getElementById('xpResult').textContent = "XP Earned: " + e;
});
}
});