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
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
/* ============================================================
  THEME TOGGLE — Dark/Light mode switcher
  Defaults to dark. Saves preference to localStorage.
  ============================================================ */
(function() {
    // Apply theme from localStorage BEFORE page renders (avoid flash)
    var saved = localStorage.getItem('flatmmo-theme') || 'dark';
    document.documentElement.className += ' ' + saved + '-theme';
    document.addEventListener('DOMContentLoaded', function() {
        document.body.classList.add(saved + '-theme');
    });
})();
$(document).ready(function () {
$(document).ready(function () {
console.log("loaded")
console.log("loaded")
// --- Theme toggle button ---
(function() {
    var currentTheme = localStorage.getItem('flatmmo-theme') || 'dark';
    // Ensure body has the right class
    document.body.classList.remove('dark-theme', 'light-theme');
    document.body.classList.add(currentTheme + '-theme');
    // Create toggle button
    var btn = document.createElement('button');
    btn.className = 'theme-toggle-btn';
    btn.title = 'Toggle light/dark mode';
    btn.textContent = currentTheme === 'dark' ? '☀️' : '🌙';
    btn.addEventListener('click', function() {
        var isDark = document.body.classList.contains('dark-theme');
        var newTheme = isDark ? 'light' : 'dark';
        document.body.classList.remove('dark-theme', 'light-theme');
        document.body.classList.add(newTheme + '-theme');
        document.documentElement.classList.remove('dark-theme', 'light-theme');
        document.documentElement.classList.add(newTheme + '-theme');
        localStorage.setItem('flatmmo-theme', newTheme);
        btn.textContent = newTheme === 'dark' ? '☀️' : '🌙';
    });
    // Insert into Cosmos header (next to wiki buttons) or fallback to content area
    var target = document.querySelector('.cosmos-header__wiki-buttons')
              || document.querySelector('.cosmos-actions')
              || document.querySelector('.wds-button-group')
              || document.querySelector('#content');
    if (target) {
        if (target.id === 'content') {
            // Fallback: put it at the top of content
            target.insertBefore(btn, target.firstChild);
        } else {
            target.appendChild(btn);
        }
    }
})();
$.getScript(mw.util.getUrl("MediaWiki:ProfileTags.js") + "?action=raw&ctype=text/javascript");
$.getScript(mw.util.getUrl("MediaWiki:ProfileTags.js") + "?action=raw&ctype=text/javascript");
if (document.getElementById("interactiveMap")) {
if (document.getElementById("interactiveMap")) {

Revision as of 22:58, 14 February 2026

  1 /* Any JavaScript here will be loaded for all users on every page load. */
  2 
  3 /* ============================================================
  4    THEME TOGGLE — Dark/Light mode switcher
  5    Defaults to dark. Saves preference to localStorage.
  6    ============================================================ */
  7 (function() {
  8     // Apply theme from localStorage BEFORE page renders (avoid flash)
  9     var saved = localStorage.getItem('flatmmo-theme') || 'dark';
 10     document.documentElement.className += ' ' + saved + '-theme';
 11     document.addEventListener('DOMContentLoaded', function() {
 12         document.body.classList.add(saved + '-theme');
 13     });
 14 })();
 15 
 16 $(document).ready(function () {
 17 console.log("loaded")
 18 
 19 // --- Theme toggle button ---
 20 (function() {
 21     var currentTheme = localStorage.getItem('flatmmo-theme') || 'dark';
 22 
 23     // Ensure body has the right class
 24     document.body.classList.remove('dark-theme', 'light-theme');
 25     document.body.classList.add(currentTheme + '-theme');
 26 
 27     // Create toggle button
 28     var btn = document.createElement('button');
 29     btn.className = 'theme-toggle-btn';
 30     btn.title = 'Toggle light/dark mode';
 31     btn.textContent = currentTheme === 'dark' ? '☀️' : '🌙';
 32 
 33     btn.addEventListener('click', function() {
 34         var isDark = document.body.classList.contains('dark-theme');
 35         var newTheme = isDark ? 'light' : 'dark';
 36 
 37         document.body.classList.remove('dark-theme', 'light-theme');
 38         document.body.classList.add(newTheme + '-theme');
 39         document.documentElement.classList.remove('dark-theme', 'light-theme');
 40         document.documentElement.classList.add(newTheme + '-theme');
 41 
 42         localStorage.setItem('flatmmo-theme', newTheme);
 43         btn.textContent = newTheme === 'dark' ? '☀️' : '🌙';
 44     });
 45 
 46     // Insert into Cosmos header (next to wiki buttons) or fallback to content area
 47     var target = document.querySelector('.cosmos-header__wiki-buttons')
 48               || document.querySelector('.cosmos-actions')
 49               || document.querySelector('.wds-button-group')
 50               || document.querySelector('#content');
 51     if (target) {
 52         if (target.id === 'content') {
 53             // Fallback: put it at the top of content
 54             target.insertBefore(btn, target.firstChild);
 55         } else {
 56             target.appendChild(btn);
 57         }
 58     }
 59 })();
 60 
 61 $.getScript(mw.util.getUrl("MediaWiki:ProfileTags.js") + "?action=raw&ctype=text/javascript");
 62 	if (document.getElementById("interactiveMap")) {
 63 console.log("map loaded")
 64 		$.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
 65             $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
 66                 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
 67                     $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap.js") + "?action=raw&ctype=text/javascript", function() {
 68                     });
 69                 });
 70             });
 71         });
 72 	}
 73 
 74 	if (document.getElementById("wardrobe")) {
 75 		$.getScript(mw.util.getUrl("MediaWiki:Wardrobe.js") + "?action=raw&ctype=text/javascript");
 76 		console.log("wardrobe loaded")
 77 	}
 78 
 79     if (document.getElementById("mapEditor")) {
 80         $.getScript("https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js", function() {
 81             $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
 82                 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
 83                     $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
 84                         $.getScript(mw.util.getUrl("MediaWiki:MapEditor.js") + "?action=raw&ctype=text/javascript", function() {
 85                         });
 86                     });
 87                 });
 88             });
 89         });
 90     }
 91 if (document.querySelector(".code")) {
 92 	$.getScript("../custom/highlight.min.js", ()=>{
 93 		document.querySelectorAll(".code").forEach(el=>hljs.highlightElement(el))
 94 		console.log('Code highlighted');
 95 	});
 96 }
 97 
 98 if (document.querySelector('[class*="Tracker"]') && !document.querySelector('[class*="page-MediaWiki"]')) {
 99 	$.getScript(mw.util.getUrl("MediaWiki:Trackers.js") + "?action=raw&ctype=text/javascript");
100     console.log("Tracker loaded");
101 }
102 
103 if (document.getElementById("enemiesDB")) {
104 	$.getScript(mw.util.getUrl("MediaWiki:Update_DB.js") + "?action=raw&ctype=text/javascript");
105 	console.log("DB Updater Loaded")
106 }
107 function hitChance(accuracy, defence) {
108     accuracy = parseInt(accuracy);
109     defence = parseInt(defence);
110     let hitChance = 0;
111     if(accuracy >= defence) {
112         hitChance = 1;
113     } else {
114         hitChance = 1 / (1 + defence - accuracy)
115     }
116     return (hitChance * 100).toFixed(2);
117 }
118 if (document.querySelector('.hitChance')) {
119     document.querySelectorAll(".hitChance").forEach(el => {
120         let [acc, def] = el.innerText.split(",")
121         el.innerText = "";
122         const accSpan = document.createElement("span");
123         const defSpan = document.createElement("span");
124         const hitSpan = document.createElement("span");
125         const accInput = document.createElement("input");
126         const defInput = document.createElement("input");
127         const hitValueSpan = document.createElement("span");
128 
129         accSpan.innerText = "Accuracy:";
130         defSpan.innerText = "Defence:";
131         hitSpan.innerText = "Hit Chance:";
132 
133         accInput.type = "number";
134         defInput.type = "number";
135         accInput.min = 0;
136         defInput.min = 0;
137         if(acc !== "0") {
138             accInput.disabled = true;
139         }
140         if(def !== "0") {
141             defInput.disabled = true
142         }
143         def = def < 0 ? 0 : def;
144         acc = acc < 0 ? 0 : acc;
145         accInput.defaultValue = acc;
146         defInput.defaultValue = def;
147         accInput.onchange = function(){
148             hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
149         }
150         defInput.onchange = function(){
151             hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
152         }
153         el.append(accSpan, accInput, defSpan, defInput, hitSpan, hitValueSpan);
154         hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
155     })
156 }
157 
158 });