No edit summary |
No edit summary Tag: Reverted |
||
| Line 1: | Line 1: | ||
/* | /* ============================================================ | ||
FlatMMO Wiki — Common JavaScript | |||
Paste into: MediaWiki:Common.js | |||
============================================================ */ | |||
/* ===== STEALING PAGE: Chest Tracker Checkboxes ===== */ | |||
/* | |||
* Finds cells in Map Chest tables whose text matches known chest IDs | |||
* and replaces them with checkboxes that save to localStorage. | |||
*/ | |||
(function() { | |||
'use strict'; | |||
// Only run on the Stealing page | |||
if (mw.config.get('wgPageName') !== 'Stealing') return; | |||
// Known chest IDs (from the "Found" column) | |||
var chestIds = [ | |||
'bronzeEverbrook', 'bronzeCat', 'bronzeThieves', 'bronzeGeneralStore', | |||
'bronzeJungle', 'bronzeBackroom', 'bronzeHell', 'bronzeVines', | |||
'ironTavern', 'ironMapleTwoBears', 'ironHiddenBamboo', 'ironGreatThieves', | |||
'ironHell', 'ironThiefBank', 'ironThieves', 'ironBullyThieves', | |||
'silverChef', 'silverDigOrb', 'desertTemple5', 'desertTemple4', | |||
'silverCryptOver', 'silverCryptFour', 'desertTemple1', 'ombokoDungeon', | |||
'silverCryptUnder', 'desertTemple2', 'silverHell', 'silverMines', | |||
'frostvaleIceflare', 'desertTemple3', 'frostvaleIceOgre', 'deepvVolcano', | |||
'goldHell', 'goldPriest', | |||
'diamondMV', 'diamondCrypt4' | |||
]; | |||
// Load saved state from localStorage | |||
var storageKey = 'flatmmo-chest-tracker'; | |||
var saved = {}; | |||
try { | |||
saved = JSON.parse(localStorage.getItem(storageKey)) || {}; | |||
} catch(e) { | |||
saved = {}; | |||
} | |||
function saveState() { | |||
localStorage.setItem(storageKey, JSON.stringify(saved)); | |||
} | } | ||
// Find all table cells and replace matching chest IDs with checkboxes | |||
var allCells = document.querySelectorAll('.mw-parser-output td'); | |||
allCells.forEach(function(cell) { | |||
var text = cell.textContent.trim(); | |||
if (chestIds.indexOf(text) !== -1) { | |||
var id = text; | |||
cell.textContent = ''; | |||
cell.style.textAlign = 'center'; | |||
var checkbox = document.createElement('input'); | |||
checkbox.type = 'checkbox'; | |||
checkbox.className = 'chest-tracker-checkbox'; | |||
checkbox.checked = !!saved[id]; | |||
checkbox.title = 'Mark as found'; | |||
// Highlight the row if checked | |||
if (checkbox.checked) { | |||
cell.parentElement.classList.add('mapChestFound'); | |||
} | |||
checkbox.addEventListener('change', function() { | |||
saved[id] = this.checked; | |||
saveState(); | |||
if (this.checked) { | |||
cell.parentElement.classList.add('mapChestFound'); | |||
} else { | |||
cell.parentElement.classList.remove('mapChestFound'); | |||
} | |||
}); | |||
cell.appendChild(checkbox); | |||
} | } | ||
}); | |||
// Add a reset button above the Map Chests section | |||
var mapChestsHeading = document.getElementById('Map_Chests'); | |||
if (mapChestsHeading) { | |||
var headline = mapChestsHeading.closest('h2') || mapChestsHeading.parentElement; | |||
var resetBtn = document.createElement('button'); | |||
resetBtn.textContent = 'Reset All Checkboxes'; | |||
resetBtn.style.cssText = 'margin: 8px 0; padding: 6px 14px; background: #3a3428; color: #d4c8b0; border: 1px solid #504838; border-radius: 4px; cursor: pointer; font-size: 0.85em;'; | |||
resetBtn.addEventListener('mouseenter', function() { | |||
this.style.background = '#504838'; | |||
}); | |||
resetBtn.addEventListener('mouseleave', function() { | |||
this.style.background = '#3a3428'; | |||
}); | |||
resetBtn.addEventListener('click', function() { | |||
if (confirm('Reset all chest checkboxes? This cannot be undone.')) { | |||
saved = {}; | |||
saveState(); | |||
document.querySelectorAll('.chest-tracker-checkbox').forEach(function(cb) { | |||
cb.checked = false; | |||
cb.parentElement.parentElement.classList.remove('mapChestFound'); | |||
}); | |||
} | |||
}); | |||
// Insert after the heading | |||
if (headline.nextSibling) { | |||
headline.parentNode.insertBefore(resetBtn, headline.nextSibling); | |||
} | } | ||
} | |||
})(); | |||
Revision as of 01:26, 10 February 2026
1 /* ============================================================
2 FlatMMO Wiki — Common JavaScript
3 Paste into: MediaWiki:Common.js
4 ============================================================ */
5
6 /* ===== STEALING PAGE: Chest Tracker Checkboxes ===== */
7 /*
8 * Finds cells in Map Chest tables whose text matches known chest IDs
9 * and replaces them with checkboxes that save to localStorage.
10 */
11 (function() {
12 'use strict';
13
14 // Only run on the Stealing page
15 if (mw.config.get('wgPageName') !== 'Stealing') return;
16
17 // Known chest IDs (from the "Found" column)
18 var chestIds = [
19 'bronzeEverbrook', 'bronzeCat', 'bronzeThieves', 'bronzeGeneralStore',
20 'bronzeJungle', 'bronzeBackroom', 'bronzeHell', 'bronzeVines',
21 'ironTavern', 'ironMapleTwoBears', 'ironHiddenBamboo', 'ironGreatThieves',
22 'ironHell', 'ironThiefBank', 'ironThieves', 'ironBullyThieves',
23 'silverChef', 'silverDigOrb', 'desertTemple5', 'desertTemple4',
24 'silverCryptOver', 'silverCryptFour', 'desertTemple1', 'ombokoDungeon',
25 'silverCryptUnder', 'desertTemple2', 'silverHell', 'silverMines',
26 'frostvaleIceflare', 'desertTemple3', 'frostvaleIceOgre', 'deepvVolcano',
27 'goldHell', 'goldPriest',
28 'diamondMV', 'diamondCrypt4'
29 ];
30
31 // Load saved state from localStorage
32 var storageKey = 'flatmmo-chest-tracker';
33 var saved = {};
34 try {
35 saved = JSON.parse(localStorage.getItem(storageKey)) || {};
36 } catch(e) {
37 saved = {};
38 }
39
40 function saveState() {
41 localStorage.setItem(storageKey, JSON.stringify(saved));
42 }
43
44 // Find all table cells and replace matching chest IDs with checkboxes
45 var allCells = document.querySelectorAll('.mw-parser-output td');
46 allCells.forEach(function(cell) {
47 var text = cell.textContent.trim();
48 if (chestIds.indexOf(text) !== -1) {
49 var id = text;
50 cell.textContent = '';
51 cell.style.textAlign = 'center';
52
53 var checkbox = document.createElement('input');
54 checkbox.type = 'checkbox';
55 checkbox.className = 'chest-tracker-checkbox';
56 checkbox.checked = !!saved[id];
57 checkbox.title = 'Mark as found';
58
59 // Highlight the row if checked
60 if (checkbox.checked) {
61 cell.parentElement.classList.add('mapChestFound');
62 }
63
64 checkbox.addEventListener('change', function() {
65 saved[id] = this.checked;
66 saveState();
67 if (this.checked) {
68 cell.parentElement.classList.add('mapChestFound');
69 } else {
70 cell.parentElement.classList.remove('mapChestFound');
71 }
72 });
73
74 cell.appendChild(checkbox);
75 }
76 });
77
78 // Add a reset button above the Map Chests section
79 var mapChestsHeading = document.getElementById('Map_Chests');
80 if (mapChestsHeading) {
81 var headline = mapChestsHeading.closest('h2') || mapChestsHeading.parentElement;
82 var resetBtn = document.createElement('button');
83 resetBtn.textContent = 'Reset All Checkboxes';
84 resetBtn.style.cssText = 'margin: 8px 0; padding: 6px 14px; background: #3a3428; color: #d4c8b0; border: 1px solid #504838; border-radius: 4px; cursor: pointer; font-size: 0.85em;';
85 resetBtn.addEventListener('mouseenter', function() {
86 this.style.background = '#504838';
87 });
88 resetBtn.addEventListener('mouseleave', function() {
89 this.style.background = '#3a3428';
90 });
91 resetBtn.addEventListener('click', function() {
92 if (confirm('Reset all chest checkboxes? This cannot be undone.')) {
93 saved = {};
94 saveState();
95 document.querySelectorAll('.chest-tracker-checkbox').forEach(function(cb) {
96 cb.checked = false;
97 cb.parentElement.parentElement.classList.remove('mapChestFound');
98 });
99 }
100 });
101
102 // Insert after the heading
103 if (headline.nextSibling) {
104 headline.parentNode.insertBefore(resetBtn, headline.nextSibling);
105 }
106 }
107 })();
