No edit summary |
No edit summary |
||
| Line 9: | Line 9: | ||
var saved = localStorage.getItem('flatmmo-theme') || 'dark'; | var saved = localStorage.getItem('flatmmo-theme') || 'dark'; | ||
document.documentElement.className += ' ' + saved + '-theme'; | document.documentElement.className += ' ' + saved + '-theme'; | ||
// Apply search bar mode BEFORE page renders (avoid flash) | |||
var searchMode = localStorage.getItem('flatmmo-search') || 'top'; | |||
document.documentElement.className += ' search-' + searchMode; | |||
document.addEventListener('DOMContentLoaded', function() { | document.addEventListener('DOMContentLoaded', function() { | ||
document.body.classList.add(saved + '-theme'); | document.body.classList.add(saved + '-theme'); | ||
document.body.classList.add('search-' + searchMode); | |||
}); | }); | ||
})(); | })(); | ||
| Line 58: | Line 64: | ||
} | } | ||
// --- | })(); | ||
// --- Search bar toggle + compact header search bar --- | |||
(function() { | |||
var searchMode = localStorage.getItem('flatmmo-search') || 'top'; | |||
// Ensure body has the right class | |||
document.body.classList.remove('search-top', 'search-header'); | |||
document.body.classList.add('search-' + searchMode); | |||
// Create toggle button | |||
var searchToggle = document.createElement('button'); | |||
searchToggle.className = 'search-toggle-btn'; | |||
searchToggle.title = 'Toggle search bar position'; | |||
searchToggle.textContent = searchMode === 'top' ? '🔍' : '🔎'; | |||
searchToggle.addEventListener('click', function() { | |||
var isTop = document.body.classList.contains('search-top'); | |||
var newMode = isTop ? 'header' : 'top'; | |||
document.body.classList.remove('search-top', 'search-header'); | |||
document.body.classList.add('search-' + newMode); | |||
document.documentElement.classList.remove('search-top', 'search-header'); | |||
document.documentElement.classList.add('search-' + newMode); | |||
localStorage.setItem('flatmmo-search', newMode); | |||
searchToggle.textContent = newMode === 'top' ? '🔍' : '🔎'; | |||
}); | |||
// Create compact header search bar | |||
var searchWrap = document.createElement('div'); | var searchWrap = document.createElement('div'); | ||
searchWrap.className = 'header-search-wrap'; | searchWrap.className = 'header-search-wrap'; | ||
| Line 88: | Line 123: | ||
searchWrap.appendChild(searchBtn); | searchWrap.appendChild(searchBtn); | ||
// Insert toggle button inline with other header buttons | |||
var target = document.querySelector('.cosmos-header__wiki-buttons') | |||
|| document.querySelector('.cosmos-actions') | |||
|| document.querySelector('.wds-button-group') | |||
|| document.querySelector('#content'); | |||
if (target && target.id !== 'content') { | if (target && target.id !== 'content') { | ||
target.appendChild(searchWrap); | target.appendChild(searchToggle); | ||
// Insert search bar BELOW the button row (as a sibling) | |||
target.parentNode.insertBefore(searchWrap, target.nextSibling); | |||
} | } | ||
})(); | })(); | ||
Revision as of 20:13, 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
12 // Apply search bar mode BEFORE page renders (avoid flash)
13 var searchMode = localStorage.getItem('flatmmo-search') || 'top';
14 document.documentElement.className += ' search-' + searchMode;
15
16 document.addEventListener('DOMContentLoaded', function() {
17 document.body.classList.add(saved + '-theme');
18 document.body.classList.add('search-' + searchMode);
19 });
20 })();
21
22 $(document).ready(function () {
23 console.log("loaded");
24
25 // --- Theme toggle button ---
26 (function() {
27 var currentTheme = localStorage.getItem('flatmmo-theme') || 'dark';
28
29 // Ensure body has the right class
30 document.body.classList.remove('dark-theme', 'light-theme');
31 document.body.classList.add(currentTheme + '-theme');
32
33 // Create toggle button
34 var btn = document.createElement('button');
35 btn.className = 'theme-toggle-btn';
36 btn.title = 'Toggle light/dark mode';
37 btn.textContent = currentTheme === 'dark' ? '☀️' : '🌙';
38
39 btn.addEventListener('click', function() {
40 var isDark = document.body.classList.contains('dark-theme');
41 var newTheme = isDark ? 'light' : 'dark';
42
43 document.body.classList.remove('dark-theme', 'light-theme');
44 document.body.classList.add(newTheme + '-theme');
45 document.documentElement.classList.remove('dark-theme', 'light-theme');
46 document.documentElement.classList.add(newTheme + '-theme');
47
48 localStorage.setItem('flatmmo-theme', newTheme);
49 btn.textContent = newTheme === 'dark' ? '☀️' : '🌙';
50 });
51
52 // Insert into Cosmos header (next to wiki buttons) or fallback to content area
53 var target = document.querySelector('.cosmos-header__wiki-buttons')
54 || document.querySelector('.cosmos-actions')
55 || document.querySelector('.wds-button-group')
56 || document.querySelector('#content');
57 if (target) {
58 if (target.id === 'content') {
59 // Fallback: put it at the top of content
60 target.insertBefore(btn, target.firstChild);
61 } else {
62 target.appendChild(btn);
63 }
64 }
65
66 })();
67
68 // --- Search bar toggle + compact header search bar ---
69 (function() {
70 var searchMode = localStorage.getItem('flatmmo-search') || 'top';
71
72 // Ensure body has the right class
73 document.body.classList.remove('search-top', 'search-header');
74 document.body.classList.add('search-' + searchMode);
75
76 // Create toggle button
77 var searchToggle = document.createElement('button');
78 searchToggle.className = 'search-toggle-btn';
79 searchToggle.title = 'Toggle search bar position';
80 searchToggle.textContent = searchMode === 'top' ? '🔍' : '🔎';
81
82 searchToggle.addEventListener('click', function() {
83 var isTop = document.body.classList.contains('search-top');
84 var newMode = isTop ? 'header' : 'top';
85
86 document.body.classList.remove('search-top', 'search-header');
87 document.body.classList.add('search-' + newMode);
88 document.documentElement.classList.remove('search-top', 'search-header');
89 document.documentElement.classList.add('search-' + newMode);
90
91 localStorage.setItem('flatmmo-search', newMode);
92 searchToggle.textContent = newMode === 'top' ? '🔍' : '🔎';
93 });
94
95 // Create compact header search bar
96 var searchWrap = document.createElement('div');
97 searchWrap.className = 'header-search-wrap';
98
99 var searchInput = document.createElement('input');
100 searchInput.type = 'text';
101 searchInput.className = 'header-search-input';
102 searchInput.placeholder = 'Search wiki...';
103 searchInput.setAttribute('autocomplete', 'off');
104
105 var searchBtn = document.createElement('button');
106 searchBtn.className = 'header-search-btn';
107 searchBtn.innerHTML = '🔍';
108 searchBtn.title = 'Search';
109
110 function doSearch() {
111 var q = searchInput.value.trim();
112 if (q) {
113 window.location.href = mw.util.getUrl('Special:Search') + '?search=' + encodeURIComponent(q);
114 }
115 }
116
117 searchBtn.addEventListener('click', doSearch);
118 searchInput.addEventListener('keydown', function(e) {
119 if (e.key === 'Enter') doSearch();
120 });
121
122 searchWrap.appendChild(searchInput);
123 searchWrap.appendChild(searchBtn);
124
125 // Insert toggle button inline with other header buttons
126 var target = document.querySelector('.cosmos-header__wiki-buttons')
127 || document.querySelector('.cosmos-actions')
128 || document.querySelector('.wds-button-group')
129 || document.querySelector('#content');
130 if (target && target.id !== 'content') {
131 target.appendChild(searchToggle);
132 // Insert search bar BELOW the button row (as a sibling)
133 target.parentNode.insertBefore(searchWrap, target.nextSibling);
134 }
135 })();
136
137 $.getScript(mw.util.getUrl("MediaWiki:ProfileTags.js") + "?action=raw&ctype=text/javascript");
138 if (document.getElementById("interactiveMap")) {
139 console.log("map loaded")
140 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
141 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
142 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
143 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap.js") + "?action=raw&ctype=text/javascript", function() {
144 });
145 });
146 });
147 });
148 }
149
150 if (document.getElementById("wardrobe")) {
151 $.getScript(mw.util.getUrl("MediaWiki:Wardrobe.js") + "?action=raw&ctype=text/javascript");
152 console.log("wardrobe loaded")
153 }
154
155 if (document.getElementById("mapEditor")) {
156 $.getScript("https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js", function() {
157 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Objects.js") + "?action=raw&ctype=text/javascript", function() {
158 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/NPCs.js") + "?action=raw&ctype=text/javascript", function() {
159 $.getScript(mw.util.getUrl("MediaWiki:InteractiveMap/Maps.js") + "?action=raw&ctype=text/javascript", function() {
160 $.getScript(mw.util.getUrl("MediaWiki:MapEditor.js") + "?action=raw&ctype=text/javascript", function() {
161 });
162 });
163 });
164 });
165 });
166 }
167 if (document.querySelector(".code")) {
168 $.getScript("../custom/highlight.min.js", ()=>{
169 document.querySelectorAll(".code").forEach(el=>hljs.highlightElement(el))
170 console.log('Code highlighted');
171 });
172 }
173
174 if (document.querySelector('[class*="Tracker"]') && !document.querySelector('[class*="page-MediaWiki"]')) {
175 $.getScript(mw.util.getUrl("MediaWiki:Trackers.js") + "?action=raw&ctype=text/javascript");
176 console.log("Tracker loaded");
177 }
178
179 if (document.getElementById("enemiesDB")) {
180 $.getScript(mw.util.getUrl("MediaWiki:Update_DB.js") + "?action=raw&ctype=text/javascript");
181 console.log("DB Updater Loaded")
182 }
183 function hitChance(accuracy, defence) {
184 accuracy = parseInt(accuracy);
185 defence = parseInt(defence);
186 let hitChance = 0;
187 if(accuracy >= defence) {
188 hitChance = 1;
189 } else {
190 hitChance = 1 / (1 + defence - accuracy)
191 }
192 return (hitChance * 100).toFixed(2);
193 }
194 if (document.querySelector('.hitChance')) {
195 document.querySelectorAll(".hitChance").forEach(el => {
196 let [acc, def] = el.innerText.split(",")
197 el.innerText = "";
198 const accSpan = document.createElement("span");
199 const defSpan = document.createElement("span");
200 const hitSpan = document.createElement("span");
201 const accInput = document.createElement("input");
202 const defInput = document.createElement("input");
203 const hitValueSpan = document.createElement("span");
204
205 accSpan.innerText = "Accuracy:";
206 defSpan.innerText = "Defence:";
207 hitSpan.innerText = "Hit Chance:";
208
209 accInput.type = "number";
210 defInput.type = "number";
211 accInput.min = 0;
212 defInput.min = 0;
213 if(acc !== "0") {
214 accInput.disabled = true;
215 }
216 if(def !== "0") {
217 defInput.disabled = true
218 }
219 def = def < 0 ? 0 : def;
220 acc = acc < 0 ? 0 : acc;
221 accInput.defaultValue = acc;
222 defInput.defaultValue = def;
223 accInput.onchange = function(){
224 hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
225 }
226 defInput.onchange = function(){
227 hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
228 }
229 el.append(accSpan, accInput, defSpan, defInput, hitSpan, hitValueSpan);
230 hitValueSpan.innerText = hitChance(accInput.value, defInput.value) + "%";
231 })
232 }
233
234 });
