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

Coolrock (talk | contribs)
No edit summary
Tag: Reverted
m Reverted edit by Coolrock (talk) to last revision by Liam
Tag: Rollback
Line 1: Line 1:
/* ============================================================
/* Any JavaScript here will be loaded for all users on every page load. */
  FlatMMO Wiki — Common JavaScript
$(document).ready(function () {
  Paste into: MediaWiki:Common.js
console.log("loaded")
  ============================================================ */
$.getScript(mw.util.getUrl("MediaWiki:ProfileTags.js") + "?action=raw&ctype=text/javascript");
if (document.getElementById("interactiveMap")) {
console.log("map loaded")
$.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:InteractiveMap.js") + "?action=raw&ctype=text/javascript", function() {
                    });
                });
            });
        });
}


/* ===== STEALING PAGE: Chest Tracker Checkboxes ===== */
if (document.getElementById("wardrobe")) {
/*
$.getScript(mw.util.getUrl("MediaWiki:Wardrobe.js") + "?action=raw&ctype=text/javascript");
* Finds cells in Map Chest tables whose text matches known chest IDs
console.log("wardrobe loaded")
* and replaces them with checkboxes that save to localStorage.
}
*/
(function() {
    'use strict';


     // Only run on the Stealing page
     if (document.getElementById("mapEditor")) {
     if (mw.config.get('wgPageName') !== 'Stealing') return;
        $.getScript("https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js", function() {
            $.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');
});
}


    // Known chest IDs (from the "Found" column)
if (document.querySelector('[class*="Tracker"]')) {
    var chestIds = [
$.getScript(mw.util.getUrl("MediaWiki:Trackers.js") + "?action=raw&ctype=text/javascript");
        'bronzeEverbrook', 'bronzeCat', 'bronzeThieves', 'bronzeGeneralStore',
     console.log("Tracker loaded");
        '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
if (document.getElementById("enemiesDB")) {
     var storageKey = 'flatmmo-chest-tracker';
$.getScript(mw.util.getUrl("MediaWiki:Update_DB.js") + "?action=raw&ctype=text/javascript");
     var saved = {};
console.log("DB Updater Loaded")
     try {
}
         saved = JSON.parse(localStorage.getItem(storageKey)) || {};
function hitChance(accuracy, defence) {
     } catch(e) {
     accuracy = parseInt(accuracy);
         saved = {};
     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");


    function saveState() {
        accSpan.innerText = "Accuracy:";
         localStorage.setItem(storageKey, JSON.stringify(saved));
         defSpan.innerText = "Defence:";
    }
        hitSpan.innerText = "Hit Chance:";


    // Find all table cells and replace matching chest IDs with checkboxes
        accInput.type = "number";
    var allCells = document.querySelectorAll('.mw-parser-output td');
        defInput.type = "number";
    allCells.forEach(function(cell) {
        accInput.min = 0;
         var text = cell.textContent.trim();
         defInput.min = 0;
         if (chestIds.indexOf(text) !== -1) {
         if(acc !== "0") {
             var id = text;
             accInput.disabled = true;
            cell.textContent = '';
        }
             cell.style.textAlign = 'center';
        if(def !== "0") {
 
             defInput.disabled = true
            var checkbox = document.createElement('input');
        }
            checkbox.type = 'checkbox';
        def = def < 0 ? 0 : def;
            checkbox.className = 'chest-tracker-checkbox';
        acc = acc < 0 ? 0 : acc;
            checkbox.checked = !!saved[id];
        accInput.defaultValue = acc;
            checkbox.title = 'Mark as found';
        defInput.defaultValue = def;
 
        accInput.onchange = function(){
            // Highlight the row if checked
            hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
            if (checkbox.checked) {
        }
                cell.parentElement.classList.add('mapChestFound');
        defInput.onchange = function(){
            }
            hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
 
            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);
         }
         }
     });
        el.append(accSpan, accInput, defSpan, defInput, hitSpan, hitValueSpan);
        hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
     })
}


    // 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:42, 10 February 2026

  1 /* Any JavaScript here will be loaded for all users on every page load. */
  2 $(document).ready(function () {
  3 console.log("loaded")
  4 $.getScript(mw.util.getUrl("MediaWiki:ProfileTags.js") + "?action=raw&ctype=text/javascript");
  5 	if (document.getElementById("interactiveMap")) {
  6 console.log("map loaded")
  7 		$.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
  8             $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
  9                 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
 10                     $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap.js") + "?action=raw&ctype=text/javascript", function() {
 11                     });
 12                 });
 13             });
 14         });
 15 	}
 16 
 17 	if (document.getElementById("wardrobe")) {
 18 		$.getScript(mw.util.getUrl("MediaWiki:Wardrobe.js") + "?action=raw&ctype=text/javascript");
 19 		console.log("wardrobe loaded")
 20 	}
 21 
 22     if (document.getElementById("mapEditor")) {
 23         $.getScript("https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js", function() {
 24             $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
 25                 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
 26                     $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
 27                         $.getScript(mw.util.getUrl("MediaWiki:MapEditor.js") + "?action=raw&ctype=text/javascript", function() {
 28                         });
 29                     });
 30                 });
 31             });
 32         });
 33     }
 34 if (document.querySelector(".code")) {
 35 	$.getScript("../custom/highlight.min.js", ()=>{
 36 		document.querySelectorAll(".code").forEach(el=>hljs.highlightElement(el))
 37 		console.log('Code highlighted');
 38 	});
 39 }
 40 
 41 if (document.querySelector('[class*="Tracker"]')) {
 42 	$.getScript(mw.util.getUrl("MediaWiki:Trackers.js") + "?action=raw&ctype=text/javascript");
 43     console.log("Tracker loaded");
 44 }
 45 
 46 if (document.getElementById("enemiesDB")) {
 47 	$.getScript(mw.util.getUrl("MediaWiki:Update_DB.js") + "?action=raw&ctype=text/javascript");
 48 	console.log("DB Updater Loaded")
 49 }
 50 function hitChance(accuracy, defence) {
 51     accuracy = parseInt(accuracy);
 52     defence = parseInt(defence);
 53     let hitChance = 0;
 54     if(accuracy >= defence) {
 55         hitChance = 1;
 56     } else {
 57         hitChance = 1 / (1 + defence - accuracy)
 58     }
 59     return (hitChance * 100).toFixed(2);
 60 }
 61 if (document.querySelector('.hitChance')) {
 62     document.querySelectorAll(".hitChance").forEach(el => {
 63         let [acc, def] = el.innerText.split(",")
 64         el.innerText = "";
 65         const accSpan = document.createElement("span");
 66         const defSpan = document.createElement("span");
 67         const hitSpan = document.createElement("span");
 68         const accInput = document.createElement("input");
 69         const defInput = document.createElement("input");
 70         const hitValueSpan = document.createElement("span");
 71 
 72         accSpan.innerText = "Accuracy:";
 73         defSpan.innerText = "Defence:";
 74         hitSpan.innerText = "Hit Chance:";
 75 
 76         accInput.type = "number";
 77         defInput.type = "number";
 78         accInput.min = 0;
 79         defInput.min = 0;
 80         if(acc !== "0") {
 81             accInput.disabled = true;
 82         }
 83         if(def !== "0") {
 84             defInput.disabled = true
 85         }
 86         def = def < 0 ? 0 : def;
 87         acc = acc < 0 ? 0 : acc;
 88         accInput.defaultValue = acc;
 89         defInput.defaultValue = def;
 90         accInput.onchange = function(){
 91             hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
 92         }
 93         defInput.onchange = function(){
 94             hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
 95         }
 96         el.append(accSpan, accInput, defSpan, defInput, hitSpan, hitValueSpan);
 97         hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
 98     })
 99 }
100 
101 });