MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
// --- COMMON.JS CLEANED AND UPDATED --- | |||
// --- Dropdown-based Tier Assignment --- | |||
// --- | |||
mw.loader.using('jquery').then(function () { | mw.loader.using('jquery').then(function () { | ||
console.log("✅ Dropdown-based Tier Assignment is running"); | console.log("✅ Dropdown-based Tier Assignment is running"); | ||
| Line 23: | Line 15: | ||
var selectors = document.querySelectorAll('.tier-selector'); | var selectors = document.querySelectorAll('.tier-selector'); | ||
selectors.forEach(function(sel) { | |||
sel.addEventListener('change', function () { | |||
moveItemToTier(this.id, this.value); | |||
}); | }); | ||
} | }); | ||
}); | }); | ||
}); | }); | ||
// Bingo JS | // --- Bingo JS --- | ||
mw.loader.using('mediawiki.util', function () { | mw.loader.using('mediawiki.util', function () { | ||
document.addEventListener("DOMContentLoaded", function () { | document.addEventListener("DOMContentLoaded", function () { | ||
| Line 39: | Line 29: | ||
var tiles = document.querySelectorAll(".bingo-table td .lighttable-cell"); | var tiles = document.querySelectorAll(".bingo-table td .lighttable-cell"); | ||
tiles.forEach(function(tile) { | |||
var id = tile.dataset.key || tile.id; | |||
if (!id) return; | |||
if (localStorage.getItem(id) === "selected") { | |||
tile.classList.add("bingo-selected"); | |||
} | |||
tile.addEventListener("click", function () { | |||
tile.classList.toggle("bingo-selected"); | |||
if (tile.classList.contains("bingo-selected")) { | |||
localStorage.setItem(id, "selected"); | |||
} else { | |||
localStorage.removeItem(id); | |||
} | } | ||
}); | |||
}); | |||
}); | }); | ||
}); | }); | ||
// Skill XP | // --- Skill XP Calculator --- | ||
document.addEventListener("DOMContentLoaded", function() { | document.addEventListener("DOMContentLoaded", function() { | ||
var tables = document.querySelectorAll(".skill-info-calc"); | var tables = document.querySelectorAll(".skill-info-calc"); | ||
tables.forEach(function(table){ | |||
var xpPerAction = parseInt(table.querySelector("span.total-xp").textContent); | |||
var numActionsElem = table.querySelector(".num-actions"); | |||
var totalXPElem = table.querySelector(".total-xp"); | |||
table.querySelector(".increase").addEventListener("click", function() { | |||
var actions = parseInt(numActionsElem.textContent) + 1; | |||
numActionsElem.textContent = actions; | |||
totalXPElem.textContent = actions * xpPerAction; | |||
}); | |||
} | |||
table.querySelector(".decrease").addEventListener("click", function() { | |||
var actions = parseInt(numActionsElem.textContent) - 1; | |||
if (actions < 0) actions = 0; | |||
numActionsElem.textContent = actions; | |||
totalXPElem.textContent = actions * xpPerAction; | |||
}); | |||
}); | }); | ||
}); | }); | ||
// --- Simple Calculator --- | |||
document.addEventListener("DOMContentLoaded", function() { | document.addEventListener("DOMContentLoaded", function() { | ||
const container = document.getElementById("calcContainer"); | const container = document.getElementById("calcContainer"); | ||
Revision as of 02:32, 5 March 2026
// --- COMMON.JS CLEANED AND UPDATED ---
// --- Dropdown-based Tier Assignment ---
mw.loader.using('jquery').then(function () {
console.log("✅ Dropdown-based Tier Assignment is running");
document.addEventListener('DOMContentLoaded', function () {
function moveItemToTier(itemId, tierId) {
var item = document.getElementById(itemId);
var targetTier = document.getElementById(tierId);
if (item && targetTier) {
targetTier.appendChild(item);
}
}
var selectors = document.querySelectorAll('.tier-selector');
selectors.forEach(function(sel) {
sel.addEventListener('change', function () {
moveItemToTier(this.id, this.value);
});
});
});
});
// --- Bingo JS ---
mw.loader.using('mediawiki.util', function () {
document.addEventListener("DOMContentLoaded", function () {
console.log("✅ Bingo JS Loaded");
var tiles = document.querySelectorAll(".bingo-table td .lighttable-cell");
tiles.forEach(function(tile) {
var id = tile.dataset.key || tile.id;
if (!id) return;
if (localStorage.getItem(id) === "selected") {
tile.classList.add("bingo-selected");
}
tile.addEventListener("click", function () {
tile.classList.toggle("bingo-selected");
if (tile.classList.contains("bingo-selected")) {
localStorage.setItem(id, "selected");
} else {
localStorage.removeItem(id);
}
});
});
});
});
// --- Skill XP Calculator ---
document.addEventListener("DOMContentLoaded", function() {
var tables = document.querySelectorAll(".skill-info-calc");
tables.forEach(function(table){
var xpPerAction = parseInt(table.querySelector("span.total-xp").textContent);
var numActionsElem = table.querySelector(".num-actions");
var totalXPElem = table.querySelector(".total-xp");
table.querySelector(".increase").addEventListener("click", function() {
var actions = parseInt(numActionsElem.textContent) + 1;
numActionsElem.textContent = actions;
totalXPElem.textContent = actions * xpPerAction;
});
table.querySelector(".decrease").addEventListener("click", function() {
var actions = parseInt(numActionsElem.textContent) - 1;
if (actions < 0) actions = 0;
numActionsElem.textContent = actions;
totalXPElem.textContent = actions * xpPerAction;
});
});
});
// --- Simple Calculator ---
document.addEventListener("DOMContentLoaded", function() {
const container = document.getElementById("calcContainer");
if (!container) return;
// Build calculator HTML dynamically
container.innerHTML = `
<div style="margin:10px 0;">
<label>Num1: <input type="number" id="num1" value="0" style="width:60px;"></label>
<label>Num2: <input type="number" id="num2" value="0" style="width:60px;"></label>
<label>Operation:
<select id="op">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</label>
<button id="calcButton">Calculate</button>
</div>
<div>Result: <span id="result">0</span></div>
`;
// Add calculator functionality
const btn = document.getElementById("calcButton");
btn.addEventListener("click", function() {
const a = parseFloat(document.getElementById("num1").value);
const b = parseFloat(document.getElementById("num2").value);
const op = document.getElementById("op").value;
let result;
if (isNaN(a) || isNaN(b)) {
result = "Enter valid numbers";
} else {
switch(op) {
case "+": result = a + b; break;
case "-": result = a - b; break;
case "*": result = a * b; break;
case "/": result = b !== 0 ? a / b : "∞"; break;
default: result = "Error";
}
}
document.getElementById("result").textContent = result;
});
});