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
Coolrock (talk | contribs)
No edit summary
Line 56: Line 56:
             target.appendChild(btn);
             target.appendChild(btn);
         }
         }
    }
    // --- Compact header search bar ---
    var searchWrap = document.createElement('div');
    searchWrap.className = 'header-search-wrap';
    var searchInput = document.createElement('input');
    searchInput.type = 'text';
    searchInput.className = 'header-search-input';
    searchInput.placeholder = 'Search wiki...';
    searchInput.setAttribute('autocomplete', 'off');
    var searchBtn = document.createElement('button');
    searchBtn.className = 'header-search-btn';
    searchBtn.innerHTML = '🔍';
    searchBtn.title = 'Search';
    function doSearch() {
        var q = searchInput.value.trim();
        if (q) {
            window.location.href = mw.util.getUrl('Special:Search') + '?search=' + encodeURIComponent(q);
        }
    }
    searchBtn.addEventListener('click', doSearch);
    searchInput.addEventListener('keydown', function(e) {
        if (e.key === 'Enter') doSearch();
    });
    searchWrap.appendChild(searchInput);
    searchWrap.appendChild(searchBtn);
    if (target && target.id !== 'content') {
        target.appendChild(searchWrap);
     }
     }
})();
})();

Revision as of 01:35, 15 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     // --- Compact header search bar ---
 61     var searchWrap = document.createElement('div');
 62     searchWrap.className = 'header-search-wrap';
 63 
 64     var searchInput = document.createElement('input');
 65     searchInput.type = 'text';
 66     searchInput.className = 'header-search-input';
 67     searchInput.placeholder = 'Search wiki...';
 68     searchInput.setAttribute('autocomplete', 'off');
 69 
 70     var searchBtn = document.createElement('button');
 71     searchBtn.className = 'header-search-btn';
 72     searchBtn.innerHTML = '🔍';
 73     searchBtn.title = 'Search';
 74 
 75     function doSearch() {
 76         var q = searchInput.value.trim();
 77         if (q) {
 78             window.location.href = mw.util.getUrl('Special:Search') + '?search=' + encodeURIComponent(q);
 79         }
 80     }
 81 
 82     searchBtn.addEventListener('click', doSearch);
 83     searchInput.addEventListener('keydown', function(e) {
 84         if (e.key === 'Enter') doSearch();
 85     });
 86 
 87     searchWrap.appendChild(searchInput);
 88     searchWrap.appendChild(searchBtn);
 89 
 90     if (target && target.id !== 'content') {
 91         target.appendChild(searchWrap);
 92     }
 93 })();
 94 
 95 $.getScript(mw.util.getUrl("MediaWiki:ProfileTags.js") + "?action=raw&ctype=text/javascript");
 96 	if (document.getElementById("interactiveMap")) {
 97 console.log("map loaded")
 98 		$.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
 99             $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
100                 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
101                     $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap.js") + "?action=raw&ctype=text/javascript", function() {
102                     });
103                 });
104             });
105         });
106 	}
107 
108 	if (document.getElementById("wardrobe")) {
109 		$.getScript(mw.util.getUrl("MediaWiki:Wardrobe.js") + "?action=raw&ctype=text/javascript");
110 		console.log("wardrobe loaded")
111 	}
112 
113     if (document.getElementById("mapEditor")) {
114         $.getScript("https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js", function() {
115             $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
116                 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
117                     $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
118                         $.getScript(mw.util.getUrl("MediaWiki:MapEditor.js") + "?action=raw&ctype=text/javascript", function() {
119                         });
120                     });
121                 });
122             });
123         });
124     }
125 if (document.querySelector(".code")) {
126 	$.getScript("../custom/highlight.min.js", ()=>{
127 		document.querySelectorAll(".code").forEach(el=>hljs.highlightElement(el))
128 		console.log('Code highlighted');
129 	});
130 }
131 
132 if (document.querySelector('[class*="Tracker"]') && !document.querySelector('[class*="page-MediaWiki"]')) {
133 	$.getScript(mw.util.getUrl("MediaWiki:Trackers.js") + "?action=raw&ctype=text/javascript");
134     console.log("Tracker loaded");
135 }
136 
137 if (document.getElementById("enemiesDB")) {
138 	$.getScript(mw.util.getUrl("MediaWiki:Update_DB.js") + "?action=raw&ctype=text/javascript");
139 	console.log("DB Updater Loaded")
140 }
141 function hitChance(accuracy, defence) {
142     accuracy = parseInt(accuracy);
143     defence = parseInt(defence);
144     let hitChance = 0;
145     if(accuracy >= defence) {
146         hitChance = 1;
147     } else {
148         hitChance = 1 / (1 + defence - accuracy)
149     }
150     return (hitChance * 100).toFixed(2);
151 }
152 if (document.querySelector('.hitChance')) {
153     document.querySelectorAll(".hitChance").forEach(el => {
154         let [acc, def] = el.innerText.split(",")
155         el.innerText = "";
156         const accSpan = document.createElement("span");
157         const defSpan = document.createElement("span");
158         const hitSpan = document.createElement("span");
159         const accInput = document.createElement("input");
160         const defInput = document.createElement("input");
161         const hitValueSpan = document.createElement("span");
162 
163         accSpan.innerText = "Accuracy:";
164         defSpan.innerText = "Defence:";
165         hitSpan.innerText = "Hit Chance:";
166 
167         accInput.type = "number";
168         defInput.type = "number";
169         accInput.min = 0;
170         defInput.min = 0;
171         if(acc !== "0") {
172             accInput.disabled = true;
173         }
174         if(def !== "0") {
175             defInput.disabled = true
176         }
177         def = def < 0 ? 0 : def;
178         acc = acc < 0 ? 0 : acc;
179         accInput.defaultValue = acc;
180         defInput.defaultValue = def;
181         accInput.onchange = function(){
182             hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
183         }
184         defInput.onchange = function(){
185             hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
186         }
187         el.append(accSpan, accInput, defSpan, defInput, hitSpan, hitValueSpan);
188         hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
189     })
190 }
191 
192 });