MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
// | // COMMON.JS MINIMAL SAFE VERSION | ||
document.addEventListener("DOMContentLoaded", function() { | |||
console.log("✅ Common.js Loaded"); | |||
console.log("✅ | |||
// --- Tier Assignment --- | |||
document.querySelectorAll('.tier-selector').forEach(function(sel) { | |||
sel.addEventListener('change', function() { | |||
const item = document.getElementById(this.id); | |||
const targetTier = document.getElementById(this.value); | |||
if (item && targetTier) targetTier.appendChild(item); | |||
}); | }); | ||
}); | }); | ||
// --- Bingo | // --- Bingo --- | ||
document.querySelectorAll(".bingo-table td .lighttable-cell").forEach(function(tile) { | |||
const 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 { | |||
if ( | localStorage.removeItem(id); | ||
} | } | ||
}); | }); | ||
}); | }); | ||
// --- Skill XP Calculator --- | // --- Skill XP Calculator --- | ||
document.querySelectorAll(".skill-info-calc").forEach(function(table){ | |||
const xpPerAction = parseInt(table.querySelector("span.total-xp").textContent); | |||
const numActionsElem = table.querySelector(".num-actions"); | |||
const totalXPElem = table.querySelector(".total-xp"); | |||
table.querySelector(".increase").addEventListener("click", function() { | table.querySelector(".increase").addEventListener("click", function() { | ||
let actions = parseInt(numActionsElem.textContent) + 1; | |||
numActionsElem.textContent = actions; | numActionsElem.textContent = actions; | ||
totalXPElem.textContent = actions * xpPerAction; | totalXPElem.textContent = actions * xpPerAction; | ||
| Line 64: | Line 41: | ||
table.querySelector(".decrease").addEventListener("click", function() { | table.querySelector(".decrease").addEventListener("click", function() { | ||
let actions = parseInt(numActionsElem.textContent) - 1; | |||
if (actions < 0) actions = 0; | if (actions < 0) actions = 0; | ||
numActionsElem.textContent = actions; | numActionsElem.textContent = actions; | ||
| Line 70: | Line 47: | ||
}); | }); | ||
}); | }); | ||
// --- Simple Calculator --- | // --- Simple Calculator --- | ||
const container = document.getElementById("calcContainer"); | const container = document.getElementById("calcContainer"); | ||
if ( | if (container) { | ||
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> | |||
`; | |||
document.getElementById("calcButton").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; | |||
}); | |||
} | |||
}); | }); | ||
Revision as of 02:33, 5 March 2026
// COMMON.JS MINIMAL SAFE VERSION
document.addEventListener("DOMContentLoaded", function() {
console.log("✅ Common.js Loaded");
// --- Tier Assignment ---
document.querySelectorAll('.tier-selector').forEach(function(sel) {
sel.addEventListener('change', function() {
const item = document.getElementById(this.id);
const targetTier = document.getElementById(this.value);
if (item && targetTier) targetTier.appendChild(item);
});
});
// --- Bingo ---
document.querySelectorAll(".bingo-table td .lighttable-cell").forEach(function(tile) {
const 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.querySelectorAll(".skill-info-calc").forEach(function(table){
const xpPerAction = parseInt(table.querySelector("span.total-xp").textContent);
const numActionsElem = table.querySelector(".num-actions");
const totalXPElem = table.querySelector(".total-xp");
table.querySelector(".increase").addEventListener("click", function() {
let actions = parseInt(numActionsElem.textContent) + 1;
numActionsElem.textContent = actions;
totalXPElem.textContent = actions * xpPerAction;
});
table.querySelector(".decrease").addEventListener("click", function() {
let actions = parseInt(numActionsElem.textContent) - 1;
if (actions < 0) actions = 0;
numActionsElem.textContent = actions;
totalXPElem.textContent = actions * xpPerAction;
});
});
// --- Simple Calculator ---
const container = document.getElementById("calcContainer");
if (container) {
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>
`;
document.getElementById("calcButton").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;
});
}
});