Anonymous
×
Create a new article
Write your page title here:
We currently have 922 articles on WIKI - Flat MMO. Type your article name above or click on one of the titles below and start writing!



WIKI - Flat MMO
922Articles

MediaWiki:Common.js: Difference between revisions

No edit summary
Coolrock (talk | contribs)
No edit summary
Tag: Reverted
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* ============================================================
$(document).ready(function () {
  FlatMMO Wiki — Common JavaScript
console.log("loaded")
  Paste into: MediaWiki:Common.js
$.getScript(mw.util.getUrl("MediaWiki:ProfileTags.js") + "?action=raw&ctype=text/javascript");
  ============================================================ */
if (document.getElementById("interactiveMap")) {
 
console.log("map loaded")
/* ===== STEALING PAGE: Chest Tracker Checkboxes ===== */
$.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
/*
            $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
* Finds cells in Map Chest tables whose text matches known chest IDs
                $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
* and replaces them with checkboxes that save to localStorage.
                    $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap.js") + "?action=raw&ctype=text/javascript", function() {
*/
                    });
(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'
    ];


if (document.getElementById("wardrobe")) {
    // Load saved state from localStorage
$.getScript(mw.util.getUrl("MediaWiki:Wardrobe.js") + "?action=raw&ctype=text/javascript");
    var storageKey = 'flatmmo-chest-tracker';
console.log("wardrobe loaded")
    var saved = {};
}
    try {
        saved = JSON.parse(localStorage.getItem(storageKey)) || {};
    } catch(e) {
        saved = {};
    }


     if (document.getElementById("mapEditor")) {
     function saveState() {
         $.getScript("https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js", function() {
         localStorage.setItem(storageKey, JSON.stringify(saved));
            $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
                $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
                    $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
                        $.getScript(mw.util.getUrl("MediaWiki:MapEditor.js") + "?action=raw&ctype=text/javascript", function() {
                        });
                    });
                });
            });
        });
     }
     }
if (document.querySelector(".code")) {
$.getScript("../custom/highlight.min.js", ()=>{
document.querySelectorAll(".code").forEach(el=>hljs.highlightElement(el))
console.log('Code highlighted');
});
}


if (document.querySelector('[class*="Tracker"]')) {
    // Find all table cells and replace matching chest IDs with checkboxes
$.getScript(mw.util.getUrl("MediaWiki:Trackers.js") + "?action=raw&ctype=text/javascript");
    var allCells = document.querySelectorAll('.mw-parser-output td');
    console.log("Tracker loaded");
    allCells.forEach(function(cell) {
}
        var text = cell.textContent.trim();
        if (chestIds.indexOf(text) !== -1) {
            var id = text;
            cell.textContent = '';
            cell.style.textAlign = 'center';


if (document.getElementById("enemiesDB")) {
            var checkbox = document.createElement('input');
$.getScript(mw.util.getUrl("MediaWiki:Update_DB.js") + "?action=raw&ctype=text/javascript");
            checkbox.type = 'checkbox';
console.log("DB Updater Loaded")
            checkbox.className = 'chest-tracker-checkbox';
}
            checkbox.checked = !!saved[id];
function hitChance(accuracy, defence) {
            checkbox.title = 'Mark as found';
    accuracy = parseInt(accuracy);
    defence = parseInt(defence);
    let hitChance = 0;
    if(accuracy >= defence) {
        hitChance = 1;
    } else {
        hitChance = 1 / (1 + defence - accuracy)
    }
    return (hitChance * 100).toFixed(2);
}
if (document.querySelector('.hitChance')) {
    document.querySelectorAll(".hitChance").forEach(el => {
        let [acc, def] = el.innerText.split(",")
        el.innerText = "";
        const accSpan = document.createElement("span");
        const defSpan = document.createElement("span");
        const hitSpan = document.createElement("span");
        const accInput = document.createElement("input");
        const defInput = document.createElement("input");
        const hitValueSpan = document.createElement("span");


        accSpan.innerText = "Accuracy:";
            // Highlight the row if checked
        defSpan.innerText = "Defence:";
            if (checkbox.checked) {
        hitSpan.innerText = "Hit Chance:";
                cell.parentElement.classList.add('mapChestFound');
            }


        accInput.type = "number";
            checkbox.addEventListener('change', function() {
        defInput.type = "number";
                saved[id] = this.checked;
        accInput.min = 0;
                saveState();
        defInput.min = 0;
                if (this.checked) {
        if(acc !== "0") {
                    cell.parentElement.classList.add('mapChestFound');
             accInput.disabled = true;
                } else {
                    cell.parentElement.classList.remove('mapChestFound');
                }
            });
 
             cell.appendChild(checkbox);
         }
         }
         if(def !== "0") {
    });
             defInput.disabled = true
 
    // 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);
         }
         }
        def = def < 0 ? 0 : def;
    }
        acc = acc < 0 ? 0 : acc;
})();
        accInput.defaultValue = acc;
        defInput.defaultValue = def;
        accInput.onchange = function(){
            hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
        }
        defInput.onchange = function(){
            hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
        }
        el.append(accSpan, accInput, defSpan, defInput, hitSpan, hitValueSpan);
        hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
    })
}
 
});

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 })();